r-这实际上返回投资组合的总回报



我遇到了一些麻烦,试图计算我的投资组合的回报。这是在RSTUDIO博客上推荐的一种方法。

以这种方式使用PerformanceAnalyticsReturn.portfolio函数,并显示了投资组合的"美元增长"。如果有人有这个经验,我会渴望听到您对这是否是准确的方法的想法。

library(PerformanceAnalytics)
library(quantmod)
library(dygraphs)
symbols <- c("GOOG", "AMZN", "BA", "FB", "AAPL")
stock.weights <- c(.15, .20, .25, .225, .175)
getSymbols(symbols,  src = 'google', from="2017-01-01")
#merge closing together
port.closing <- merge.xts(GOOG[,4], AMZN[,4], BA[,4], FB[,4], AAPL[,4])
#change closings to returns
port.return <- na.omit(Return.calculate(port.closing))
#portfolio returns with wealth.index = TRUE to apply to $1 invested - no rebalance
port.norebal = Return.portfolio(port.return,
    weights = stock.weights, wealth.index = TRUE)
#visualise dollar growth
dygraph(port.norebal)
#calculating return on portfolio taking the current date and dividing it by investment date
PortfolioReturn <- as.numeric(tail(port.norebal,1)) / as.numeric(head(port.norebal, 1))
PortfolioReturn

因此,根据Return.portfolio功能计算的我的投资组合中的1美元增长了1美元,并且我计算了当前日期和投资日期之间的百分比增加。这是否准确地显示了投资组合的资本增长?

不是完全:当您从2017-01-03开始执行Return.portfolio时,它为您提供了一个索引,其中假定值为2017-01-03的值为1。't实际上在该系列中包括2017-01-03的1个。

投资组合返回是as.numeric(tail(port.norebal,1))。当您除以as.numeric(head(port.norebal, 1))时,自投资组合第二天以来就会获得回报(自第一天以来)。即,您正在从2017-01-04中删除收益。

另外,不要忘记在返回计算中减去1。您的投资组合返回40%,而不是140%。

为了帮助我解决问题,我通过用

替换您的stock.weights线来计算您的投资组合的同等加权版本
stock.weights <- rep(0.2, 5)

然后我从第一原则计算了回报:

end.price = port.closing["2017-09-13"] 
start.price = port.closing["2017-01-03"] 
mean(as.numeric(end.price) / as.numeric(start.price) - 1)

这给了我0.382475,等于as.numeric(tail(port.norebal,1)) - 1

最新更新