我後來嘗試計算投資組合的回報時遇到了一些麻煩。這是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
函數計算,我計算出當前的日期和投資日之間增加的百分比。這是否準確地顯示了投資組合的資本增長?