I've ran into a bit of trouble of late trying to calculate the returns of my investment portfolio. Here's one way which has been recommended on the Rstudio blog.
This way uses the Return.portfolio
function from PerformanceAnalytics
and which shows the 'dollar growth' of a portfolio. If anyone has experience with this I'd be keen to hear your thoughts on whether or not this is an accurate method.
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
So, I've got the growth of $1 of my portfolio as calculated by the Return.portfolio
function and I calculate the percentage increase between the current date and the investment date. Does this accurately show the capital growth of the portfolio?
Not quite: when you do
Return.portfolio
starting on 2017-01-03, it gives you an index where the value at 2017-01-03 is assumed to be a 1. But it doesn't actually include the 1 at 2017-01-03 in the series.The portfolio return is
as.numeric(tail(port.norebal,1))
. When you divide byas.numeric(head(port.norebal, 1))
, you're getting the return since the second day of the portfolio (not since the first day). i.e. you're dropping the returns from 2017-01-04 from your calculation.Also, don't forget to subtract 1 in your return calculation. Your portfolio return 40%, not 140%.
To help wrap my head around the problem, I computed an equal-weighted version of your portfolio by replacing your
stock.weights
line withThen I calculated the returns from first principles:
This gives me 0.382475, which is equal to
as.numeric(tail(port.norebal,1)) - 1
.