The Austrian Quant: My Machine Learning Trading Algorithm Outperformed SP500 For 10 Years

Permanent Portfolio Fund on Quantopian : January 1, 2006 until June 2, 2017

 

Introduction

Dutch Golden Age. Origins of Tulip Mania, The first investment bubble. 17th Century.
Source: Jan Claesz Rietschoof [Public domain], via Wikimedia Commons

Broadly speaking, I generally spend most of my time thinking about two things, technology and investing. More specifically, I often ask myself what is something useful I can build with software (or occasionally hardware) and what is something useful which I should invest in. Algorithmic trading is a nice integration of these two schools and I have been spending some time understanding this field. This is an intriguing field and I learnt some interesting things which I decided to share.

Austrian Quant

The Austrian Quant is named after the Austrian School of Economics which serves as the inspiration for how I structured the portfolio. I designed a trading strategy composed of 3 different investment funds to gain a better understanding of investments, machine learning and programming and how they all combine together in the world of finance and technology.

The 3 different funds used in this strategy include: The Permanent Portfolio Fund, The Speculative Fund and The Fundamental Fund. 70% of the overall portfolio was invested in the Permanent Portfolio, with an equal 15% weighting allocated to the Speculative and Fundamental Fund each. The Fundamental Fund is still under construction so I may add a follow up to this essay with the fund performance later. However, the rest of this article is based on a portfolio weighting of 85% in the Permanent Portfolio Fund and 15% in the speculative fund.

I have also shared the code for this project on my Github.

The Permanent Portfolio Fund

The permanent portfolio is an idea by Harry Browne, based on the Austrian School of Economics, a solid economic framework and a very useful way for looking at life in general. The Permanent Portfolio is not for investors looking to beat the market, evident by the large cash and gold holdings; it’s for people with a long-term investment horizon, which describes my investment style well and thus its my largest allocation.

The fund was inspired by the permanent portfolio quantopian notebook on Quantopian and the Austrian School for Investors book by Rahim Reghezda et. al. which is another book I strongly recommend. The portfolio is also partly inspired by the All Weather principles from Ray Dalio’s Bridgewater, which served as a useful framework for managing my risk exposure while targeting strong returns. 

Within this fund, 30% of the portfolio went into stocks, bonds and Gold while 10% went into cash (or more specifically 1-3 year treasury bills). The Allocation in the Austrian School for Investor’s book suggested equal 25% weightings between each asset class but since I am young and have few responsibilities, I figured I can be a bit more aggressive and take some more risk. Thus I lowered my cash allocation and increased the other asset allocations.

Permanent Portfolio Allocations        
  Cash (1-3 yr T Bills) Gold Bond Stocks
Harry Browne   25% 25% 25%
My Portfolio 10% 30% 30% 30%

The portfolio is rebalanced using the Markowitz style optimization algorithm to find the most efficient frontier ratio between risk (standard deviation) and return.The Markowitz optimization is an interesting algorithm because it is predicated on normally distributed returns, however stock market returns are subject to the power law and fat tails. So one has to wonder how accurate algorithms such as Markowitz optimizations actually are; perhaps it is just meant to be used as a heuristic for simplifying very complex problems.

A fairly extensive backtest was run, tracking the performance of the fund from January 1, 2006 until June 2, 2017.

Update: This is backtest from before Quantopian started calculating risk-related data. 

The purpose of the permanent portfolio is not to beat the index, but to generate stable returns over the long term. With this in mind, I was very pleased with the results of the backtest. Though the fund underperformed the SPY benchmark by ~500 basis points, it was significantly less risky. More specifically, it enjoyed growth in the bull markets from 2006-2007 and 2010-2017, while avoiding losses, in the 2008/09 bear market.

One of the really insightful things I learnt while researching algorithmic trading is that good strategies tend to be very ephemeral. Investors tend to be very shrewd and thus if an asset class tends to perform well, the strategy very quickly gets arbitraged away as other investors flock to that trading strategy. I don’t anticipate the permanent portfolio drawing too many imitators due to the cautious approach it takes even in bull markets; investors seem to ignore the significant downside protection it offers. Surprisingly this fund has consistently outperformed the index, without the lead being arbitraged away.

I’m currently now testing this out in a live trading environment and it seems that a longer testing period must be used before any conclusive observations can be made. However, based on past data, the results seem very promising and this is a trading strategy that has me seriously considering putting some skin in the game and testing with real money.

The Speculation Fund

As mentioned earlier, I have a higher risk tolerance so I figured that I could devote a small part of my portfolio to pure speculations. Gambling strictly violates my investment principles however, the knowledge I gained and the amount of fun I had while constructing this portfolio is my justification for the hypocrisy. It reminds me of the time when Jack Bogle was explaining why he invested in his son’s active investment company, while preaching the gospel of index investing; “If it’s not consistent, well, life isn’t always consistent.”

The speculative fund is inspired by the Python programming quantopian tutorial, which I highly recommend for anyone learning python and Harrison Kinley is a very good teacher.

The speculative fund uses a relatively simple machine learning support vector classification algorithm. The algorithm is trained with historical stock price data, by looking at the price movement of a stock in the last 10 days, and learning if the stock price increased or decreased on the 11th day. Then the algorithm can predict whether or not a stock price will increase based on how the price has improved in the last 10 days.

A Support Vector Machine (SVM) classifier was used instead of K-Nearest Neighbours as the computation intensive processes required in Quantopian made speed a high priority and that could best be achieved with the SVMs. A summary of the code is included below, lines have been removed to save space but the full code can be found in this file:

Complex algorithms notwithstanding, the results were very poor:

Speculation Fund

This was disappointing for me because the supposedly elaborate algorithm I used could not even beat a simple momentum strategy. In fact, when the speculation fund was combined with the momentum strategy it reduced the returns by over 5000 basis points (50%).

Momentum Fund

Speculation + Momentum Fund

I was also expecting volatility and max drawdown to be even higher in the pure speculation fund because I have been very fascinated by Nassim Taleb’s work and I was very worried about the “black swan” effect wiping out my portfolio. Mark Spitznagel has a very good paper on this topic that helped me understand the underrated impact of tail risk events in financial markets.  

In short, by speculating in short term price changes I was getting ~1 – 2% short term gains but exposing myself to situations where I could quickly lose >50%. (Charlie Munger calls this picking pennies in front of a steamroller.)However, the ability to short and hedge my positions proved very useful in March 2009. When the market was having its biggest losses, I had my biggest gains. Though my leverage ratio never exceeded ~4%, this is another strategy that would need to be properly tested in a live environment because of interest rate expenses and premiums on shorting that could have a material impact on the returns. So long story short, I learnt a lot and I really enjoyed getting to use machine learning in a practical trading example, but don’t try this at home.

The Fundamental Fund [Work in Progress]

The idea behind this fund was to look at  company fundamentals to see which financial metrics  are most predictive of a rise in the stock price. Train a machine learning algorithm to predict what company fundamental features would present a compelling buy arguement and invest in those securities. Interestingly, I got the algorithm to work in my Python environment on my command line but I’m still trying to get the program to work in Quantopian so I can do some more rigorous backtesting.

{Code Snippet and Command Line Results}

Fundamental Fund

Though the results in my preliminary tests were promising, I am not getting too excited yet as the lack of rigorous testing in a proper backtesting environment means it’s hard to gauge how well my portfolio would realistically perform as a live trading strategy. However, the theory and math behind the algorithm seems to be sound which is a good sign.

Putting it Together

After seeing how well the Permanent Portfolio and Momentum Funds had done in comparison to the abysmal performance of the Speculation Fund, it seems crazy to combine these funds. But again, the purpose was not to maximize returns but to learn more about investing and programming. It was interesting to look at how the portfolio performed in other metrics.

Portfolio Performance                
Jan 1. 2016 – June 2 2017 Cumulative Return Benchmark (SPY) Alpha Beta Sharpe Sortino Volatility Max Drawdown
Austrian Quant Fund 126.89% 145.10% 0.07 0.06 1.04 1.52 0.07 -9.70%
Permanent Portfolio Fund 139.59% 145.10% 0.07 0.12 0.98 1.45 0.08 -14.80%
Speculation + Momentum 146.50% 145.10% 0.01 0.9 0.53 0.75 0.18 -48.90%
Momentum Fund 69.90% 145.10% 0.08 -0.21 0.36 0.51 0.17 -32.20%
Speculation Fund -31.40% 145.10% -0.01 -0.18 -0.24 -0.32 0.11 -40.70%

I decided to focus on Sortino Ratio as opposed to the more conventional Sharpe ratio as the Sharpe ratio penalizes both upside and downside volatility while the Sortino ratio only penalizes downside volatility. The practical difference between the two however is not clear because both the Sharpe and Sortino Ratios had the exact same ordinality. 1)If two lists were created, one with Sharpe ratio in descending order and one with Sortino ratio in descending order (see table); both lists would have the same ordering.

Strictly speaking, the Speculation and Moment Fund had the largest cumulative return so it seems to be the best strategy. But, I identified my goals as a long term trading strategy, with relatively little risk and the Speculation + Momentum fund violated that principle with the a large maximum drawdown of -48.90% and a sortino ratio of 0.75.

Choosing between the Austrian Quant Fund and the Permanent Portfolio is an example of why people refer to investing as more of an art  than a science. While the Permanent Portfolio outperformed the Austrian Quant by about 13,000 basis points, the Austrian Quant offered much less volatility and better downside protection. I’m not entirely comfortable with the short-term short trades employed in the Austrian Quant Fund due to the asymmetric payoffs; while the Permanent Portfolio Fund offers a simplistic, buy, hold and sleep easy strategy. Thus, I am inclined to pick the Permanent Portfolio Fund.Though I think I should wait and see the data from the results of these two funds in the live trading environment before I draw any conclusions.

Conclusion

I learnt a lot while building this project and I had a lot of fun, which is ultimately the most important thing. Tangentially, another interesting thing I learnt while researching this project is the tendency for financial fields to become overly theoretical and equation-driven. This is fine in the natural sciences such as biology or physics, but finance is generally a social science, which has a greater exposure to black swan events and tail risks.

I remind everyone to apply caution and remember not to confuse precision with accuracy. Finally, I end with the wise Benjamin Franklin who reminds us that, “An investment in knowledge pays the best interest.

References   [ + ]

1. If two lists were created, one with Sharpe ratio in descending order and one with Sortino ratio in descending order (see table); both lists would have the same ordering.