[R-SIG-Finance] Generating Monthly Return Info (Eric Thungstom)

Tobias Muhlhofer tmuhlhof at indiana.edu
Sat Mar 12 18:02:30 CET 2011


Eric:

Why not do it by hand, using aggregate()? Let's say dset is your
data.frame of daily returns, with the return variable called ret and
the date variable called date. Make sure the date variable has class
Date.

> dset$month <- format(dset$date, format="%m")  ## This generates a month variable
> dset$year <- format(dset$date, format="%Y") ## This generates a year variable
> dset.monthly <- aggregate(1+dset$ret, by=list(year=dset$year, month=dset$month), FUN=prod, na.rm=TRUE)
> dset.monthly$x <- dset.monthly$x - 1

Done!

I do digest only for this list, so may be slow responding to further questions.

Best,
   Toby



More information about the R-SIG-Finance mailing list