使用 QuantMod/tseries 每月回报与股息 [英] Using QuantMod/tseries monthlyReturn with dividend

查看:37
本文介绍了使用 QuantMod/tseries 每月回报与股息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用每月回报函数将股息计入每月回报?

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

我有一个带有价格和股息列的 xts 对象.

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

推荐答案

您可以直接使用 TTR::adjRatios 来计算创建总回报"价格系列所需的调整比率.然后您可以使用调整后的系列计算每月回报.请注意,您可能还需要针对拆分进行调整.

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

这篇关于使用 QuantMod/tseries 每月回报与股息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆