Shiny App for asset allocation backtesting
Project Motivation
Retail investors often lack not only a general understanding of asset management principles but also the necessary tools to make an educated decision about their investment portfolio. Wealth advisers create portfolios that seemingly reflect the clientβs risk/return objectives. However, the client is not equipped to objectively assess if the manager is doing a good job.
Thatβs why I decided that for my project for the NYC Data Science Academy, I βd attempt to create a prototype of the portfolio allocation backtesting that can potentially be used by asset managers to illustrate the performance of a clientβs portfolio and to explain the key principles of the modern portfolio theory.
The beta version of the Shiny App can be found on ShinyApps.io , and the full code is presented on the GitHub.
A Little Bit of Theory
In 1952 Harry Markowitz suggested that assets should be evaluated based on the ratio of their expected risk and return. The ratio varies among different asset classes. We will use six asset classes:
- US Equities (represented by S&P500)
- European Stocks (MSCI European Stocks Index)
- Emerging Market Stocks (MSCI Emerging Market Index)
- US Treasury Bonds (Barclays US Treasury Total Return Index)
- US Corporate Bonds (Barclays US Corp Bond Total Return Index)
- Real Estate (Dow Jones US Real Estate Index).
We can look at the historical risk/return ratios of these asset classes for the period 1Q2000 β 3Q2018.
Quite expectedly, fixed income instruments offered the least risk. However, one snapshot does not give enough information for an optimal portfolio selection. Asset returns are non-stationary, which means that the distribution of returns may change with time.
Another takeaway from the Markowitzβ approach later elaborated by William Sharpe (1966) is that returns of asset classes are not perfectly correlated. Therefore, an investor can enjoy the benefits of diversification by including more assets in her portfolio.
The graph below shows the results of simulated portfolios (gray). For the simulation, we generated 10,000 possible combinations of asset weights that add up to 100%, i.e. a fully-invested portfolio. The weights were drawn from a uniform distribution (0,1), which means that the portfolios we simulate are long-only. The blue line shows the combination of optimal portfolios, i.e. portfolios that offer the highest expected return for a given amount of risk. In Markowitzβ framework, such a line would be called the Efficient Frontier. However, technically speaking, the Efficient Frontier includes short positions on some of the assets. We assume that ordinary investors typically do not engage in short-selling. Therefore, we restrict our analysis to long-only portfolios. To maintain keep the integrity of definitions. we will refer to this line as the βOptimal Lineβ and portfolios on the Optimal Line as βOptimal Portfolios.β
The Application
The prototype of the backtesting application is aimed at providing investors with the tool to evaluate the historical performance of different combinations of asset classes and to compare it to the optimal portfolio.
Below is the layout of the Backtesting page of the application.
A user can choose asset weights in the portfolio. The weights of other assets are adjusted automatically so that the portfolio stays fully invested. The pie chart in the right upper corner visualizes the allocation. Next, the user chooses the rebalancing schedule and the period for which the backtesting is performed. After pressing the Backtest button, he can see the historical performance of the portfolio and compare it to benchmarks such as S&P500 and a portfolio consisting of 60% S&P500, 10% Treasury Bonds, and 30% corporate Bonds. The graph shows the compound return of the portfolios and the table in the right low corner provides key performance metrics.
On the Allocation Comparison page, the user can compare his portfolio to two Optimal portfolios: one with a similar return but lower risk and another with a similar risk but higher return. Under the hood, the code performs a penalizing optimization using DEOptim package in R.
Limitations
I can see two major limitations for this product.
First and foremost, we use historical data to find an optimal portfolio. Therefore, the results have an inherited hindsight bias. Consquently, if such a product is used by asset management clients, the clients should be aware that a) previous performance of assets does not guarantee the future performance, and that b) it is virtually impossible to create a portfolio that will be on the Optimal Line, unless you have a crystal ball and know the future returns. That means that the product can be used to evaluate the portfolio performance and see how close or far its performance was to the Optimal Line. But slight deviations from the optimal portfolio should not be viewed as a bad performance by an asset manager.
Second, in designing an application like this, we have to strike the balance between providing a wide variety of asset classes within a manageable interface, and not presenting an overwhelming number of portfolio selections. In my example, I kept six asset classes that probably represent the most popular ones among retail investors. If the application is used by asset managers in real life, the number of asset classes may be increased to reflect most of the viable options that the firmβs clients have. However, it is practically impossible to include all the investable asset classes without making portfolio selection too complicated for an average investor.