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.
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.
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)))