1. PerformanceAnalytics
At this point, you know the ins and outs of computing a
2. The practitioner's challenge
portfolio return over a single period running from a start date to an end date.
In practice, we will need to compute the returns for many periods. In fact, the longer the history of returns,
the more information we have about the underlying portfolio performance.
Real-life analysis of portfolio returns thus requires a loop over the different dates. In this video, I will show you how to do this using the R package PerformanceAnalytics. This is
3. The creators
the go-to package for analyzing portfolio returns in R and has been written by two quants from the city of Chicago:
Peter Carl and Brian Peterson.
4. Calculating returns
So, how to compute the time series of portfolio returns in R. Well, this is made easy by using two functions in R, namely: the function Return.calculate and the function Return.portfolio.
The main argument for the function Return.calculate is the time series of end-of-period prices of the different investments. This should come as an object of the xts-time series class, meaning that the rows are ordered in time. The corresponding dates are preferably indicated as YEAR YEAR YEAR YEAR dash MONTH MONTH dash DAY DAY.
5. Calculating returns
By default, the function Return.calculate transforms the time series of prices into a time series of returns, where each observation is the percentage change in value over that period.
Note that the first row of the obtained return data consists of NA’s. This means that for the first date, the returns are not available. This is normal since, for the first date, there is no previous price available to compare with the current price. This first row can thus be removed, as shown on the slide.
As such, we have the time series of returns on the individual investments. To compute the time series of portfolio returns, we also need to define the time series of initial portfolio weights.
6. Dynamics of portfolio weights
There are several possibilities. The default choice is to set only the initial weights for the first date and then have the subsequent weights be automatically determined by the price dynamics.
The alternative is to pursue a dynamic
7. Dynamics of portfolio weights
approach to portfolio allocation, in which the action of buying and selling assets to actively change the portfolio weights is called rebalancing.
8. Portfolio returns
Given the returns and portfolio weights, we can then finally compute the time series of portfolio returns using the function Return.portfolio. This is a powerful function, with at least three arguments that need to be specified: the return data argument, the weights argument, and the rebalancing argument defining whether and how frequent the portfolio needs to be rebalanced. Without going in the details,
9. Let's practice!
let’s go to the exercises and learn by doing about these arguments.