[R-SIG-Finance] Monthly returns from Daily prices
Gabor Grothendieck
ggrothendieck at gmail.com
Mon Mar 24 13:04:51 CET 2008
Your file is not a csv file so I would not name it *.csv.
Try this.
library(zoo)
Lines <- "RIC Trade.Date Close.Price Currency.Code
ABCd.xx 2008/02/29 15.3 CNY
ABCd.xx 2008/02/28 15.1 CNY
ABCd.xx 2008/02/27 15.28 CNY
ABCd.xx 2008/02/26 15.26 CNY
ABCd.xx 2008/02/25 14.88 CNY
ABCd.xx 2008/02/22 15.64 CNY
"
zd <- read.zoo(textConnection(Lines), # change to "myfile.txt"
colClasses = c("NULL", "character", "numeric", "NULL"),
header = TRUE, format = "%Y/%m/%d")
z <- aggregate(z, as.yearmon, tail, 1)
On Mon, Mar 24, 2008 at 7:26 AM, Ravi S. Shankar <ravis at ambaresearch.com> wrote:
> Hi,
>
> I have the daily data in the following format
>
> RIC Trade.Date Close.Price Currency.Code
> ABCd.xx 2008/02/29 15.3 CNY
> ABCd.xx 2008/02/28 15.1 CNY
> ABCd.xx 2008/02/27 15.28 CNY
> ABCd.xx 2008/02/26 15.26 CNY
> ABCd.xx 2008/02/25 14.88 CNY
> ABCd.xx 2008/02/22 15.64 CNY
>
>
> I have about 1000 rics and one year daily price history for each of the
> rics. I need to compute the monthly returns for this data.
>
> I tried the following code to get the monthly data from the daily prices
> library(zoo)
> ss=read.csv("C:\\Documents and
> Settings\\ravis\\Desktop\\ravi.csv",header=T)
> ss$Trade.Date=as.Date(ss$Trade.Date,"%Y/%m/%d")
> ss$ym=as.yearmon(ss$Trade.Date)
> ss.mon=aggregate(ss$Close.Price,list(RIC=ss$RIC,Month_Year=ss$ym),functi
> on(x) tail(x,1))
>
> I am interested in an alternate way of doing this.
> Any help would be appreciated.
>
> Thank you,
> Regards,
>
> Ravi Shankar S
>
>
> This e-mail may contain confidential and/or privileged i...{{dropped:10}}
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>
More information about the R-SIG-Finance
mailing list