Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Survivorship bias in Markowitz classic mean-variance optimization

Hi every one,

I'm new here, and I wanted to share with you the results of some quick experiments I've been doing with the classical Markowitz optimization technique. I based my code on these notebooks:

https://blog.quantopian.com/markowitz-portfolio-optimization-2/
https://www.quantopian.com/posts/the-efficient-frontier-markowitz-portfolio-optimization-in-python-using-cvxopt

I just made a small modification to make sure the algorithm maximizes the sharpe ratio (the original code somehow maximized the return).

It turns out, the original Markowitz is incredible prone to survivorship bias. I ran the simulation from mid 2006 to 2016. When I use the current top 25 stocks of the SP500 (discarding those that did not exist back then, like FB or so), the algorithm performs, let's say -acceptable- it doesn't beat the benchmark or anything, but it follows it closely, even with though I rebalance daily and with the default transactions costs.

(See attached backtest)

But as soon as I include the next 20 stocks of the SP500, the algorithm plunges. The performance is so terrible at first I thought it could be some code bug, so double checked everything, but so far I think everything checks.

Still, I'd like a second opinion on this. If it is indeed a case of survivorship bias, it's pretty amazing how a small change in the universe of stocks can dramatically change the results of Markowitz technique. I mean, it's not like I'm comparing the top10 vs the bottom10 or something, it's just adding a few more good stocks =S

7 responses

Here are the results for the same algorithm, now including the current top forty something stocks of the SP500. Let yourselves be the judges.

Have you tried using this with the pipeline to dynamically select the top stocks, rather than choosing from a basket?

Markowitz is not a good path to go down.
If it works out for you in any of your testing it is due to luck.
Since the mean-variance optimization is based on historical returns and variances it will not be a good predictor of FUTURE returns and variances, which are both unstable and highly volatile.
It is great as a teaching tool and a Nobel winning breakthrough in financial theory, but in practice it will not outperform the market. It has been widely analyzed over the past decades and unless you can create a superior forecast of FUTURE returns and variances to optimize against it is not going to outperform.

@ Cory,
That was bold statement, I" Morkow is a great teaching tool". Is there a proof or backing up evidences for that statement. Come on man!. i know few of my professors in my past university.who are all about MVP type, are beating market and they are the one that run the Business School deparment funds.. Im a big fan of MVP myself. i spent all my time doing research about it so really you statement was kinda what ??? uhm Are you sure ? kinda statement. If you are a CFA charter member the nyou should not making these statements which will not hold in my opinions. You are telling me that just only MVP is using historical returns. Is there any algo in this forum does not use historical return ? " what will be a good predictors for returns and variance in your opinions ? In fact , i dont think there any prediction at all with MVP type problem. i dont see any Maximum Likelihood Estimator (MLE) , The Rao-BlackWell and Mimimum Variance unbiased estimation or other estimator when im calculating the weights by hand for MVP. MVP is first order differential minimizing problem with constraints or without ,no predicting here .
For MVP, there are many components to look at not just mu, signma , correlation, ..etc. If you go in depth like a master in Financial Engineering, there is a tons of research you can do with Mean-Variance type of problems.
@ Lino, if you randomly select stocks with high correlation, MVP wont help you. you need to run through a correlation and select stocks with minimum correlation. If i do it i would take 5 small caps, mid caps, large caps and risk free instrument.
If you select all stocks from sp 500, too much correlation in your portfolio. i wish i have time to play with your algo but unfortunate actuarial exams are kicking my butts right now. So maybe later.

I just cloned this algo from Thomas post just now. So there is no checking leverage or anything, just plug in stocks and etfs
This algo, i was looking at it yesterday, It is beating the benchmark but im not sure it using leverage or not. in fact it you in Porfollio type problem, im i recommending these books: it cheaps 5 bucks a piece " Modern Portfolio Theory and Investment Analysis" and the application book using excel " Running Money Professional Portfolio Management". First one is heavy in math those, it is a grad book, but second one is easier and a lot of fun.

Markowitz's lasting achievement was that he showed mathematically what was well known anecdotally, that there are benefits to diversifying your portfolio and he showed the importance of correlations in relation to diversification. His work points more toward investing in a diversified market portfolio, low cost index, than trying to beat the market.

Two points to make a quick case against using historical data to build an optimized portfolio:
1. When you optimize you are finding the best portfolio to have owned on the date of the START of the optimization , not the portfolio to own at the end.
If you use historical data from 01/01/2016 to 09/30/2016 as your data set, you are finding the portfolio you should have owned on 01/01/2016, not the portfolio you should own on 09/30/2016. Future performance is not likely to resemble the historical performance due to instability of the variables.
2. Markowitz has been around for a long, long time. If it was the magical answer to beating the market, we wouldn't still be looking for a way to beat the market.

Valid ways to try to implement Markowitz:
1. People use it at a macro level across asset classes. Allocating across equities, bonds, commodities, real estate, alt-investments, etc... The variables by assets class are more stable than at the individual asset level, but it can only give you a general idea of the best way to allocate.
2. Using on forecast data. If you can develop a way to model future returns, variances (and that is a very big if), then it might be good to optimize based on the forecast data. Even the macro level optimization should be done on your forecast of returns. You can try to use analyst estimates of forward earnings/returns, but analysts are not that great of forecasters. If you want to use optimization, focus your learning on how to make a good forecast, doing the optimization part is easy.

In short, feel free to run optimizations, change variables, sample periods, etc.. and you may manage to mine the data that gives you fantastic historical returns, but it is very unlikely to produce future out performance. Must at a minimum optimize based on a forecast.

Best

An excellent and I suspect correct summation. Asset allocation can work says Markowitz's research. I'm beginning to think that is all most research can say. If you have been around long enough you realise back testing is mostly wishful thinking.
I
Asset allocation and diversification are about all you can do in the long term. And success in other areas is probably luck and survivorship bias.