[R-SIG-Finance] Monthly returns from Daily prices

Jeff Ryan jeff.a.ryan at gmail.com
Mon Mar 24 13:02:20 CET 2008


Hi Ravi,

I can't really reproduce your data, but once you get the date
converted the following should work.  I've used Starbucks daily data
as an example (and because I need more coffee...)

library(quantmod)
getSymbols("SBUX", src='yahoo')

Delt(Cl(to.monthly(SBUX)),type='arithmetic')
Delt(Cl(to.monthly(SBUX)),type='log')

# this will compute the discrete (arithmetic) return as well (though
it is slower):

monthlyReturn(Cl(SBUX))

Jeff

On Mon, Mar 24, 2008 at 6: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.
>



-- 
There's a way to do it better - find it.
Thomas A. Edison



More information about the R-SIG-Finance mailing list