The Austrian Quant

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

Introduction

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 interesting field and I did learn some interesting things which I’ll share with you today.

Dutch Golden Age. 17th Century. Origins of Tulip Mania. The first investment bubble.

Source:Jan Claesz Rietschoof [Public domain], via Wikimedia Commons

Austrian Quant

The Austrian Quant is named after the Austrian School of Economics which served 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 I used to make 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.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)GoldBondStocks
Harry Browne 25%25%25%
My Portfolio10%30%30%30%

The portfolio is rebalanced using Markowitz style optimization 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. So one has to wonder how accurate algorithms such as Markowitz optimizations actually are; perhaps it is just useful 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.

The purpose of the permanent portfolio is not to beat the index, its purpose is 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 quantitative algorithms is that good strategies are 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 tested 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 SVM algorithm was used instead of K-Nearest Neighbours as the computation intensive processes required in Quantopian made speed a high priority and the speed required 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:

Update: December 28, 2019: I am getting a weird bug when inserting code snippets so I will have to use pictures. But you can find the full code at the speculation_fund.py file in the Github repo

Update: June 10, 2020: I think the bug has been fixed. I finally updated to WordPress 5.

Update: December 3, 2020: The bug is back now. See this Github gist of the code snippet that used to be here.

Complex algorithms notwithstanding, the results were very poor:

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 50%.

Momentum Fund

Momentum

Speculation + Momentum Fund

Speculation + Momentum

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 had a very good paper on that as well.  

In short, by speculating in short term price changes I was getting 1 or 2% short term gains but exposing myself to situations where I could quickly lose >50%. 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}

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 2017Cumulative ReturnBenchmark (SPY)AlphaBetaSharpeSortinoVolatilityMax Drawdown
Austrian Quant Fund126.89%145.10%0.070.061.041.520.07-9.70%
Permanent Portfolio Fund139.59%145.10%0.070.120.981.450.08-14.80%
Speculation + Momentum146.50%145.10%0.010.90.530.750.18-48.90%
Momentum Fund69.90%145.10%0.08-0.210.360.510.17-32.20%
Speculation Fund-31.40%145.10%-0.01-0.18-0.24-0.320.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. 2

  • Sortino :  Rp-Rf Sharpe: Rp-Rfp
  • Rp = Return of portfolio investment
  • Rp = Return on Risk-free rate
  • p-= Standard deviation of negative portfolio returns
  • p = Standard deviation of portfolio returns

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 a social science, which has a greater exposure to black swan events and tail risks. So 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.

Notes:

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