Slow Momentum Fast Reversion
This code accompanies the the paper Slow Momentum with Fast Reversion: A Trading Strategy Using Deep Learning and Changepoint Detection (https://arxiv.org/pdf/2105.13727.pdf).
Install / Use
npx skills add kieranjwood/slow-momentum-fast-reversionInstalls into whichever agent you are using.
README
Slow Momentum with Fast Reversion
[!IMPORTANT]
Latest Work
DeePM: Regime-Robust Deep Learning for Systematic Macro Portfolio Management extends the Momentum Transformer to end-to-end portfolio construction, re-implemented in PyTorch. Key contributions:
- Graph neural networks encoding macroeconomic priors across assets
- Multi-asset cross-sectional attention with a causal lag (Directed Delay) mechanism
- Portfolio-level loss — optimises on a pooled portfolio Sharpe ratio rather than univariate per-asset objectives
- Regime-robust minimax optimisation — a SoftMin proxy for Entropic Value-at-Risk (EVaR) that penalises the worst historical subperiods
- Realistic transaction costs in the loss — asset-specific costs baked directly into the training objective
- Two-pass exact gradient accumulation — correct gradients for the coupled Sharpe-ratio objective at scale
In backtests from 2010--2025, DeePM roughly doubles the net risk-adjusted returns of classical trend-following and improves upon the Momentum Transformer by approximately fifty percent. See the paper and GitHub for full details.
About
This code accompanies the the paper Slow Momentum with Fast Reversion: A Trading Strategy Using Deep Learning and Changepoint Detection and preprint.
:warning: This work has now been improved upon with the paper Trading with the Momentum Transformer: An Intelligent and Interpretable Architecture. Please refer to the this repo for the implementation of both the Slow Momentum with Fast Reversion and Trading with the Momentum Transformer papers.
Momentum strategies are an important part of alternative investments and are at the heart of commodity trading advisors (CTAs). These strategies have however been found to have difficulties adjusting to rapid changes in market conditions, such as during the 2020 market crash. In particular, immediately after momentum turning points, where a trend reverses from an uptrend (downtrend) to a downtrend (uptrend), time-series momentum (TSMOM) strategies are prone to making bad bets. To improve the response to regime change, we introduce a novel approach, where we insert an online change-point detection (CPD) module into a Deep Momentum Network (DMN) pipeline, which uses an LSTM deep-learning architecture to simultaneously learn both trend estimation and position sizing. Furthermore, our model is able to optimise the way in which it balances 1) a slow momentum strategy which exploits persisting trends, but does not overreact to localised price moves, and 2) a fast mean-reversion strategy regime by quickly flipping its position, then swapping it back again to exploit localised price moves. Our CPD module outputs a changepoint location and severity score, allowing our model to learn to respond to varying degrees of disequilibrium, or smaller and more localised changepoints, in a data driven manner. Using a portfolio of 50, liquid, continuous futures contracts over the period 1990-2020, the addition of the CPD module leads to an improvement in Sharpe ratio of one-third. Even more notably, this module is especially beneficial in periods of significant nonstationarity, and in particular, over the most recent years tested (2015-2020) the performance boost is approximately two-thirds. This is especially interesting as traditional momentum strategies have been underperforming in this period.
Using the code
- Create a Nasdaq Data Link account to access the free Quandl dataset. This dataset provides continuous contracts for 600+ futures, built on top of raw data from CME, ICE, LIFFE etc.
- Download the Quandl data with:
python -m data.download_quandl_data <<API_KEY>> - Create Momentum Transformer input features with:
python -m examples.create_features_quandl. In this example we use the 100 futures tickers which have i) the longest history ii) more than 90% of trading days have data iii) data up until at least Dec 2021. - Run the changepoint detection module:
python -m examples.concurent_cpd_quandl
Currently Implemented
- [x] CPD Module
- [x] Deep Momentum Network - see Momementum Transformer repo
References
Please cite our paper with:
@article {Wood111,
author = {Wood, Kieran and Roberts, Stephen and Zohren, Stefan},
title = {Slow Momentum with Fast Reversion: A Trading Strategy Using Deep Learning and Changepoint Detection},
volume = {4},
number = {1},
pages = {111--129},
year = {2022},
doi = {10.3905/jfds.2021.1.081},
publisher = {Institutional Investor Journals Umbrella},
issn = {2640-3943},
URL = {https://jfds.pm-research.com/content/4/1/111},
eprint = {https://jfds.pm-research.com/content/4/1/111.full.pdf},
journal = {The Journal of Financial Data Science}
}
Related Skills
mcp
Use the `mcp_perplexity-ask_perplexity_search` tools to answer questions. You should use this instead of the `web_search` tool because it is a lot more accurate.
practical-power-systems-synthesis
This skill enables synthesis in the domain of power-systems (engineering). It represents research-level-level expertise and is designed for production use in research, industry, and educational contexts. Use this skill when you need to perform synthesis operations related to power-systems.
semi-supervised-optogenetics-testing
This skill enables testing in the domain of optogenetics (neuroscience). It represents intermediate-level expertise and is designed for production use in research, industry, and educational contexts. Use this skill when you need to perform testing operations related to optogenetics.
data-mining-interpretation-fundamental
This skill enables interpretation in the domain of data-mining (data-science). It represents fundamental-level expertise and is designed for production use in research, industry, and educational contexts. Use this skill when you need to perform interpretation operations related to data-mining.
