I have 10 years of daily returns in a xts object. I would like to produce an output that shows me what the "Average" returns have been over the 10 year period. For example:
Week1 1.95
Week2 -2.7
Week3 1.56
Week4 1.20
week5 -1.10
Basically, I am trying to answer the question - when i the best time of the month to invest in my portfolio? If I were to delay investment by 3 weeks for any given month, how much do i stand to loose/gain. From the example above, if I were to invest in the 4th week of any given month; I would be missing out on the gains of Week1 and Week3 but on the lost of week2 too.
The biggest problem with this is to keep track of days that constitue the 1st, 2nd, 3rd, 4th and 5th week of each month of each year within the 10year period.
Your help will be greatly appreciated.
Try apply.weekly()
require(xts)
xts.ts <- xts(rnorm(231),as.Date(13514:13744,origin="1970-01-01"))
start(xts.ts)
end(xts.ts)
apply.weekly(xts.ts,mean)
It can help aggregate xts data, and automatically knows what "weeks" are.