1

Is there are way using Monthly Return function to factor in dividends into the monthlyReturn?

I have my an xts object with price and dividend columns.

firstever
  • 49
  • 1
  • 6
  • 2
    Add the price and dividend columns together and run `monthlyReturn` on that. – GSee Sep 29 '14 at 15:38
  • @GSee, I have not thought about it that way. It might present an issue when calculating the return if the dividends happen in the middle of the month. – firstever Sep 29 '14 at 16:06
  • Oh. I think I see what you're saying. You should add the `cumsum` of dividends to the price – GSee Sep 29 '14 at 16:27

1 Answers1

2

You can use TTR::adjRatios directly to calculate the adjustment ratios necessary to create a "total-return" price series. Then you can calculate the monthly return using the adjusted series. Note that you might also need to adjust for splits.

library(quantmod)
# create sample data
SPY.Close <- Cl(getSymbols("SPY", auto.assign=FALSE))
SPY.Div <- getDividends("SPY", auto.assign=FALSE)
SPY <- merge(SPY.Close, SPY.Div)
# now adjust close for dividends
ratios <- adjRatios(dividends=SPY[,"SPY.Div"], close=SPY[,"SPY.Close"])
SPY$SPY.Adjusted <- (ratios$Split * ratios$Div) * SPY$SPY.Close
# only keep dates from the original object
SPY <- SPY[index(SPY.Close),]
# calculate returns on raw prices and adjusted prices
ret <- merge(monthlyReturn(Cl(SPY)), monthlyReturn(Ad(SPY)))
Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418