2017-09-13 57 views
-1

我後來嘗試計算投資組合的回報時遇到了一些麻煩。這是Rstudio博客推薦的一種方法。這實際上是否會返回投資組合的總回報?

這種方式使用PerformanceAnalytics中的Return.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 

所以,我有我的投資組合的1 $增長由Return.portfolio函數計算,我計算出當前的日期和投資日之間增加的百分比。這是否準確地顯示了投資組合的資本增長?

回答

0

不完全:當你在2017-01-03開始做Return.portfolio時,它會給你一個指數,其中2017-01-03的值被假定爲1,但它實際上並不包括1在2017-01-03在系列中。

投資組合回報是as.numeric(tail(port.norebal,1))。當你除以as.numeric(head(port.norebal, 1))時,你會從投資組合的第二天(不是自第一天起)獲得回報。即您從計算中減去2017-01-04的回報。

此外,不要忘記在你的退貨計算中減去1。你的投資組合回報40%,而不是140%。

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

爲了幫助總結我的頭周圍的問題,我從第一原理同

stock.weights <- rep(0.2, 5) 

免去您stock.weights線然後我計算的回報率來計算你的投資組合的等權版

這給了我0.382475,這相當於as.numeric(tail(port.norebal,1)) - 1