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
Actually the 'apply' is not necessary.
The original poster has stocks as rows
rather than the customary columns, so
the following should suffice:
retmat - diff(log(t(pricemat)))
Questions that are specifically financial
should be sent to r-sig-finance (you need
to subscribe before posting).
You can use diff.zoo like this:
library(zoo)
z - zoo(matrix(1:24, 6))
z
diff(log(z))
# also try
diff(z, arith = FALSE) - 1
See ?diff.zoo
and read the three zoo vignettes (pdf documents):
vignette(package = zoo) # lists them
vignette(zoo)
etc.
On Sun, Jun 6, 2010 at 11:11 PM, Anyi Zhu
I did not realise making a zoo object is that convenient. Thanks a lot
Gabor.
-Original Message-
From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com]
Sent: June-07-10 5:20 AM
To: anyi@gmail.com
Cc: r-help@r-project.org
Subject: Re: [R] Computing day-over-day log return
Thanks a lot Sayan, I'll give it a try and let you know how it goes.
From: sayan dasgupta [mailto:kitt...@gmail.com]
Sent: June-07-10 2:13 AM
To: anyi@gmail.com
Cc: r-help@r-project.org
Subject: Re: [R] Computing day-over-day log return for a matrix containing
multiple time series
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
6 matches
Mail list logo