[R] SMA and EMA in package TTR

2011-01-29 Thread Anyi Zhu
Hi, Just wondering for the SMA and EMA in package TTR, is it possible to me to code it so that, say if I need to calculate SMA (x, n=100), when the sample size is less than 100, it will give me the SMA (x, k) where k is the sample size of the data? Right now it only gives me an invalid n error.

[R] non-integer key for data.table

2010-09-12 Thread Anyi Zhu
Hi all, Say if I have a data table which consists of 4 column: itemID, location and price, which location is a text field and itemID and location together forms the primary keys. when I tried to run setkey (DT, itemID, location), I got the following message: Error in setkey (DT, itemID,

[R] Efficient ways of merging data frames

2010-09-12 Thread Anyi Zhu
Hi all, I am just wondering if there is a more efficient way of merging two large datasets based on the values of multiple columns, some of which are not numerical. The default merge function in dataframe is very inefficient and the merge function in data.table seems to be faster, but it does

Re: [R] Computing day-over-day log return for a matrix containing multiple time series

2010-06-07 Thread Anyi Zhu
, 2010 at 11:11 PM, Anyi Zhu anyi@gmail.com wrote: Hi all, Thanks a lot for anyone's help in advance. I am trying to find a way to compute the day-to-day return (log return) from a n x r matrix containing, n different stocks and price quotes over r days. The time series of prices

Re: [R] Computing day-over-day log return for a matrix containing multiple time series

2010-06-07 Thread Anyi Zhu
Hope this helps a - matrix(runif(150),nrow=3,ncol=50) p2r - function(x) 100 * diff(log(x)) t(apply(a,1,function(x){p2r(c(x))})) On Mon, Jun 7, 2010 at 8:41 AM, Anyi Zhu anyi@gmail.com wrote: Hi all, Thanks a lot for anyone's help in advance. I am trying to find a way to compute

[R] Computing day-over-day log return for a matrix containing multiple time series

2010-06-06 Thread Anyi Zhu
Hi all, Thanks a lot for anyone's help in advance. I am trying to find a way to compute the day-to-day return (log return) from a n x r matrix containing, n different stocks and price quotes over r days. The time series of prices are already split by using unstack function. For the

[R] Building correlation matrix

2010-05-25 Thread Anyi Zhu
Hi, I am a novice with R, so pardon me if the question is a piece of cake to some of you. Say if I have a stream of data consisting of 3 columns, 1st column is birth date, 2nd is death date and third is weight for each individual. My ultimate goal is to be able to compute the correlation of