Using QuantMod/tseries monthlyReturn with dividend

放肆的年华 提交于 2019-12-24 10:49:24

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/26103147/using-quantmod-tseries-monthlyreturn-with-dividend

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!