r - Does this actually return the total return of a portfolio? -


i've ran bit of trouble of late trying calculate returns of investment portfolio. here's 1 way has been recommended on rstudio blog.

this way uses return.portfolio function performanceanalytics , shows 'dollar growth' of portfolio. if has experience i'd keen hear thoughts on whether or not 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 port.closing <- merge.xts(goog[,4], amzn[,4], ba[,4], fb[,4], aapl[,4]) #change closings returns port.return <- na.omit(return.calculate(port.closing)) #portfolio returns wealth.index = true apply $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 current date , dividing investment date portfolioreturn <- as.numeric(tail(port.norebal,1)) / as.numeric(head(port.norebal, 1)) portfolioreturn 

so, i've got growth of $1 of portfolio calculated return.portfolio function , calculate percentage increase between current date , investment date. accurately show capital growth of portfolio?

not quite: when return.portfolio starting on 2017-01-03, gives index value @ 2017-01-03 assumed 1. doesn't include 1 @ 2017-01-03 in series.

the portfolio return as.numeric(tail(port.norebal,1)). when divide as.numeric(head(port.norebal, 1)), you're getting return since second day of portfolio (not since first day). i.e. you're dropping returns 2017-01-04 calculation.

also, don't forget subtract 1 in return calculation. portfolio return 40%, not 140%.

to wrap head around problem, computed equal-weighted version of portfolio replacing stock.weights line with

stock.weights <- rep(0.2, 5) 

then calculated returns first principles:

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

this gives me 0.382475, equal as.numeric(tail(port.norebal,1)) - 1.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -