Could a random portfolio management be applicable to investing?

Written by hackernoon-archives | Published 2018/06/18
Tech Story Tags: investing | trading | statistics | data-science | stock-market

TLDRvia the TL;DR App

The global stock market has a wide range of various Exchange Traded Funds (ETFs). Today we are going to compare a random portfolio management of stocks and ETF investing. Hundreds of random investors will be simulated. We will try to understand is there a difference between these approaches.

All operations will be carried out in R.

What is ETF?

An ETF, or exchange-traded fund, is a marketable security that tracks an index, a commodity, bonds, or a basket of assets like an index fund. Unlike mutual funds, an ETF trades like a common stock on a stock exchange. ETFs experience price changes throughout the day as they are bought and sold.

Loading data and preprocessing

Used libraries are

<a href="https://medium.com/media/70a6505a27be7978662cdb2c00a3446f/href">https://medium.com/media/70a6505a27be7978662cdb2c00a3446f/href</a>

First of all, we should load the data. Here you can find the current list of stocks that contained in S&P500 Index, and here the list of active US listed ETFs. Let’s grab these lists.

<a href="https://medium.com/media/39500b52e399fadc133353ef9aa89445/href">https://medium.com/media/39500b52e399fadc133353ef9aa89445/href</a>

When we parse the S&P500 list we should filter by date. It needs to get more fair research, because we should be confident that this stock was presented at the beginning of investing. The second note is selection of date range, it’s some trade-off between available data and length of research.

We have 397 stocks and 243 ETFs. Now we are ready to define a function that loads the daily data and cleans it. I modified this approach by Chris for my research. We will work with logarithmic returns of assets.

<a href="https://medium.com/media/897422f8a44e36e7404de053907cab36/href">https://medium.com/media/897422f8a44e36e7404de053907cab36/href</a>

Run this function for ETFs and stocks.

<a href="https://medium.com/media/7474c1d51e1348984f0dddc1f8849210/href">https://medium.com/media/7474c1d51e1348984f0dddc1f8849210/href</a>

Getting back to trade-off we see that these values are missing (light blue), and we should remove the data. If date range would be wider it had more missing values.

Downloaded data

After this operation, the stock list contains 376 items, and the ETF list contains 79.

Investing quality measure

To compare the investing approaches we should define a quality measure. The Sotrino ratio is good measure for that.

The Sortino ratio is used as a way to compare the risk-adjusted performance of programs with differing risk and return profiles. In general, risk-adjusted returns seek to normalize the risk across programs and then see which has the higher return unit per risk. The Sortino ratio is used to score a portfolio’s risk-adjusted returns relative to an investment target using downside risk. This is analogous to the Sharpe ratio, which scores risk-adjusted returns relative to the risk-free rate using standard deviation.

Volatility distribution

Sortino ratio formula

We can calculate the Sortino ratio of the market (SPY ticker).

<a href="https://medium.com/media/b94d1a4e83e7da1ecc678e978e88e9fc/href">https://medium.com/media/b94d1a4e83e7da1ecc678e978e88e9fc/href</a>

The value is 8.34, and this is pretty good. Indeed, the graph shows growth almost all the time.

SPY

Sortino ratio estimation of ETFs

This code calculates a Sortino ratio of each ETF, gets a summary statistics, and visualizes a distribution of ETF set.

<a href="https://medium.com/media/9b4e3cc415df700ad32df42960d3ffe5/href">https://medium.com/media/9b4e3cc415df700ad32df42960d3ffe5/href</a>

And we get this summary of the Sortino ratio for ETFs:

<a href="https://medium.com/media/0a465a26dc93f5f5e635fcc39c52ce4c/href">https://medium.com/media/0a465a26dc93f5f5e635fcc39c52ce4c/href</a>

Random portfolio simulation and Sortino ratio estimation

The number of simulated portfolios is equal to number of random investors (nPortfolios variable). We will test a different number of stocks in each random portfolio (nStocks variable). Also, we will do this nTrials times and get median of attempts, it needs to get a stable result. All stocks in a random portfolio have an equal proportion.

Comparison of ETFs and random portfolios we will carry out using Wilcoxon signed-rank test for ETF Sortino ratios and median values of Sortino ratio of random portfolios. This is a non-parametric statistical hypothesis test when the population cannot be assumed to be normally distributed.

<a href="https://medium.com/media/2f66e0831aa093a29a798c2910185a94/href">https://medium.com/media/2f66e0831aa093a29a798c2910185a94/href</a>

Comparison of approaches

This graph shows a distribution of medians of the Sortino ratio for random portfolios with different number of stocks.

Sortino ratio distribution of random portfolios

Also, let’s look at a distribution of medians of the p-values (Wilcoxon signed-rank test).

p-value distribution of Wilcoxon signed-tank test

This table contains an aggregate result (result variable).

Result of simulation

As you see, we don’t have a significant difference between the Sortino ratios of ETF and random portfolios. Median of p-value of our experiment is quite high.

Full output looks like this

<a href="https://medium.com/media/1bab101df473070bbd4e439f7744d3c9/href">https://medium.com/media/1bab101df473070bbd4e439f7744d3c9/href</a>

Backtesting of random portfolio on Quantopian

Quantopian is a Boston-based company that aims to create a crowd-sourced hedge fund by letting freelance quantitative analysts develop, test, and use trading algorithms to buy and sell securities.

We can carry out an experiment on Quantopian to see how a random portfolio works, and compare the result to the benchmark (SPY ticker). Let’s buy 10 stocks at the beginning of time period. A few of the possible variants below.

Quantopian experiments

More often this approach works worse than buy & hold the S&P500 Index. What alpha and beta mean I considered in the article How to develop a stock market analytical tool using Shiny and R.

Code of this experiment is next. You can start coding here.

<a href="https://medium.com/media/45bcee9d8c66d3e1cb108094abac0d96/href">https://medium.com/media/45bcee9d8c66d3e1cb108094abac0d96/href</a>

Really good algorithms usually get performance better. One of our developed strategies in Quantroom has this backtesting result for 2004–2018 years (long only positions).

Long only algorithm performance

Conclusions

The following statements are valid for a given time interval:

  1. Medium values of the Sortino ratios don’t differ significantly between ETF investing and random portfolio management.
  2. Buy & hold the market is better than random choices of assets. Probably buy the market at the right time is a good approach for passive investing.
  3. Some of the assets have better performance, but you should have a deeper analysis to investing in. This variant will differ little from the development of its own trading strategy, and it’s another way to invest.

These conclusions may be different for another market phase and situation.


Published by HackerNoon on 2018/06/18