Sergey Malchevskiy

Data Scientist at Conjecture corp.

Could a random portfolio management be applicable to investing?

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

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.

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.

Run this function for ETFs and stocks.

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).

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


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.

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

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.

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

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.

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


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.

More by Sergey Malchevskiy

More Related Stories