Multi-Factor Timing with Deep Learning

How deep learning can assist in factor timing?

Hi! Here's Iván with this week's exciting newsletter, brimming with insights and discoveries on building robust trading strategies and risk models using Machine Learning.

In this edition, I am sharing two interesting trading ideas. The first one relates to how deep learning can assist in factor timing, and the second is a pure VIX future strategy that also applies deep learning in the process. Both are nice pieces of research!

  • 🕹️ 2 Academic Articles: Dive into groundbreaking research featuring actionable ideas that are reshaping our understanding of how to apply ML/DL in creating successful investment and trading strategies.

  • 💊 Video Insight : A user-friendly complete guide on how to start with the VectorBT python backtester.

  • 🥐 Best backtesting libraries in Python: My personal ranking!.

Academic Insights

“Multi-Factor Timing with Deep Learning”

In the paper they improve factor timing through neural networks (LSTMs is the paper best performing method) with economic restrictions.

The main paper contribution is to mix multi-task learning to capture the common structure across factors with the LSTMs to extract financial and macroeconomic states.

Basically, the LSTM layers serve to reduce dimensions, like a kind of principal component analysis (PCA), while also extracting dynamics to a state space model within a broader nonlinear framework.

 🔔 They find that:

  1. Tail risk, along with variations in leverage, profitability, and momentum, are key predictors, and

  2. They also demonstrate the importance of capturing the factors nonlinear interactions.

🔔 Results

Even with transaction costs of fourteen basis points their main methodology still achieves an alpha of 1.33% (t-stat of 3.42) and Sharpe ratio of 1.17, surpassing the multi-factor Buy Sharpe ratio of 0.98.

“Trading the VIX futures curve using Deep Learning” 

🔔 Simple Trade Intuition

If the VIX curve shows a hump, a zero-cost long-short VIX futures position or calendar spread can yield profit when the curve shifts back to contango, especially if this reversion occurs rapidly.

What they do in the paper?...In only two sentences: 👇

--> The authors optimize trading strategies in VIX futures for a day-ahead horizon by maximizing expected utility (using calendars), taking into account the current term structure shape and level.

-->They computationally model the relationship between the VIX futures curve, positions, and expected utility using a deep neural network with five hidden layers.

🔔The strategy step-by-step:

  1. They start by downloading VIX curve future data (6 maturities, from one-month to six-month maturity) from 2008 to 2020, using data from the VIX Central website.

  2. Using these data, they construct the time series of VIX CMFs (constant-maturity futures) using linear interpolation and VIX rolls (details provided in the paper)

  3. Using lags of both VIX CMFs and VIX rolls, they train a vector autoregressive model (AR) to predict the values for the next day.

  4. They apply k-fold cross-validation using 10 different folds, each comprising 316 or 317 days.

  5. Using the trained autoregressive (AR) model, they draw samples to train a deep neural network (see the image of this post). This process aims to develop an optimal trading decision 'function'.

  6. Those optimal trading decision, are constrained to long/short positions (calendars) between the one-month and the five-month futures.

🔔 Results

In all 10 folds, they find a Sharpe Ratio (SR) higher than one, with values reaching between 4 and 8 in some folds.

AI-Essentials: Step-by-Step Tutorial

🚀 A user-friendly, complete guide on how to start with VectorBT backtester. It's not the easiest library to begin with, but it is probably the most complete one available right now.

Quick: Learning

“Best Backtesting Python Libraries: My Personal Ranking” 

I often receive many questions about which is the best backtesting Python library. Here are my two cents:

The main current candidates are: 👇

  • 💡 Backtesting.py

  • 💡 Backtrader

  • 💡 Zipline

  • 💡 VectorBT (pro)

  • 💡 Custom inhouse solution

For single-asset backtesting, particularly for pure market timing and time series strategies, I would rank VectorBT as my top choice, followed by Backtesting.py (with more limitations and slower than VectorBT).

For portfolio strategies, which also include pair trading and statistical arbitrage, I generally prefer custom solutions, like the pandas backtesting framework developed from scratch. However, we a bit practice, VectorBT can also do the work.

Zipline and Backtrader are both decent solutions that were widely used in the past, and I have utilized them extensively as well. However, currently, they are barely maintained.

To sum up, if you are beginning with algorithmic trading, I recommend starting with VectorBT for higher-frequency single-asset strategies, and a pandas-based "simple" custom backtester for portfolio-based strategies.

By the way, the plot above shows a crossover strategy over the SPY using the 50-day and 200-day MAs (in VectorBT) - a classic strategy that, of course, isn't working 😅.

If you're enjoying our newsletter and want to support us, please recommend it to anyone you know who's interested in AI and Finance. Your referrals are the biggest compliment and help us grow! 🌟🤖💼