【发布时间】:2018-02-22 18:24:27
【问题描述】:
我最近在计算投资组合的回报时遇到了一些麻烦。这是 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 函数计算得出,我计算了当前日期和投资日期之间的百分比增长。这是否准确地显示了投资组合的资本增长?
【问题讨论】:
标签: r finance quantmod stock performanceanalytics