← 开源
kieranjwood

trading-momentum-transformer

This code accompanies the the paper Trading with the Momentum Transformer: An Intelligent and Interpretable Architecture (https://arxiv.org/pdf/2112.08534.pdf).

ApplicationsSpecialistsPython
在 GitHub 打开
增长势头
+124 小时新增 Star+0.2%
641
Star
255
Fork
+2
本周
1
贡献者
创建于 2021-12-27 · 更新于 2026-10-16 · 今日第 6539 名
主要开发者
kieranjwood

kieranjwood/trading-momentum-transformer 排名第 6,539,有 641 个星标。

同类别比较

kieranjwood/trading-momentum-transformer 排名第 6,539,此处有 8 个同类条目;DeadWaveWave/demo2apk 排名第 6,536。

同类别比较
名称排名指标
tldraw/tldraw-offline6,522
星标数:
649
分叉数:
24
简介:
A desktop app for using tldraw with local files.
chongdashu/cc-statusline6,529
语言:
TypeScript
星标数:
645
分叉数:
63
简介:
Transform your Claude Code experience with a beautiful, informative statusline
iBlinkQ/llm-wiki-obsidian-blink6,532
星标数:
644
分叉数:
109
简介:
一个基于 Andrej Karpathy 的 LLM Wiki 模式 实现的 Obsidian 知识库,利用 LLM 维护可复利的个人知识层。
DeadWaveWave/demo2apk6,536
语言:
TypeScript
星标数:
642
分叉数:
69
简介:
Turn your Vibe Coding ideas into runnable Android Apps instantly
SeanHeelan/anamnesis-release6,547
语言:
JavaScript
星标数:
635
分叉数:
87
简介:
Automatic Exploit Generation with LLMs
liruifengv/we-drawing6,553
语言:
TypeScript
星标数:
634
分叉数:
79
简介:
AI画图。每天一句中国古诗词,生成 AI 图片。
gersteinlab/LocAgent6,555
语言:
Python
星标数:
633
分叉数:
97
简介:
[ACL 2025] Graph-guided agentic framework for code localization https://arxiv.org/abs/2503.09089
minghe36/haoone-app6,565
语言:
JavaScript
星标数:
628
分叉数:
5
简介:
新一代 AI 专业字幕软件,剪映字幕、elevenlabs 语音转文本的最佳本地版平替之一,也是加强版。中英转录识别准确率超过 97%,词语音频对齐率 98%,说话人分割与识别准确率 96%,带有最先进的 ASR 开源模型,100+字幕动画(支持导出透明背景的字幕动画)。说话人识别、专业字幕编辑器、命令行工具、Skill,达芬奇字幕插件(含字幕动画插件),PR 字幕插件,本地转录、远程转录、文稿匹配、智能拆行、AI校正、AI 智能热词、翻译、双语字幕、专业字幕编辑器、字幕合成、自定义大模型 API
关键参数与规格
关键参数与规格
参数值
语言Python
类别Applications
子类别Specialists
关键词Finance, Trading
星标数641
分叉数255
贡献者1
创建日期2021-12-27
更新日期2026-10-16
1 天星标数1
7 天星标数2
排名6,539
上次排名15,487
排名变化8,948
7 天星标排名8,697
上次 7 天星标排名11,140
7 天星标排名变化2,443
总星标排名15,933
上次总星标排名15,958
总星标排名变化25
国家UK
README 摘录

Trading with the Momentum Transformer [! 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. **Graph neural networks** encoding macroeconomic priors across assets 2. **Multi-asset cross-sectional attention** with a causal lag (Directed Delay) mechanism 3. See the paper and GitHub for full details. About This code accompanies the paper Trading with the Momentum Transformer: An Intelligent and Interpretable Architecture and additionally

provides an implementation for the paper Slow Momentum with Fast Reversion: A Trading Strategy Using Deep Learning and Changepoint Detection. 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. Create Momentum Transformer input features with: . 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. Optionally, run the changepoint detection module: , for example and 5. Create Momentum Transformer input features, including CPD module features with: after the changepoint detection module has completed. To create a features file with multiple changepoint detection lookback windows: after the 126 day LBW changepoint detection module has completed and a features file for the 21 day LBW exists. Run one of the Momentum Transformer or Slow Momentum with Fast Reversion experiments

with Trading with the Momentum Transformer: An Intelligent and Interpretable Architecture Deep learning architectures, specifically Deep Momentum Networks (DMNs) , have been found to be an effective approach to momentum and mean-reversion trading. However, some of the key challenges in recent years involve learning long-term dependencies, degradation of performance when considering returns net of transaction costs and adapting to new market regimes, notably during the SARS-CoV-2 crisis. Attention mechanisms, or Transformer-based architectures, are a solution to

such challenges because they allow the network to focus on significant time steps in the past and longer-term patterns. We introduce the Momentum Transformer, an attention-based architecture which outperforms the benchmarks, and is inherently interpretable, providing us with greater insights into our deep learning trading strategy. Our model is an extension to the LSTM-based DMN, which directly outputs position sizing by optimising the network on a risk-adjusted performance metric, such as Sharpe ratio. We find an

attention-LSTM hybrid Decoder-Only Temporal Fusion Transformer (TFT) style architecture is the best performing model. In terms of interpretability, we observe remarkable structure in the attention patterns, with significant peaks of importance at momentum turning points. The time series is thus segmented into regimes and the model tends to focus on previous time-steps in alike regimes. We find changepoint detection (CPD) , another technique for responding to regime change, can complement multi-headed attention, especially when we run CPD

at multiple timescales. Through the addition of an interpretable variable selection network, we observe how CPD helps our model to

常见问题

记录了多少星标和分叉?

kieranjwood/trading-momentum-transformer 有 641 个星标和 255 个分叉。

仓库排名是多少?

kieranjwood/trading-momentum-transformer 排名第 6,539。

记录的语言和类别是什么?

kieranjwood/trading-momentum-transformer 有 641 个星标,语言为 Python,类别为 Applications。

哪个仓库排名最接近?

kieranjwood/trading-momentum-transformer 与 DeadWaveWave/demo2apk 比较,后者排名第 6,536,有 642 个星标。

README

Trading with the Momentum Transformer

[!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:

  1. Graph neural networks encoding macroeconomic priors across assets
  2. Multi-asset cross-sectional attention with a causal lag (Directed Delay) mechanism
  3. Portfolio-level loss — optimises on a pooled portfolio Sharpe ratio rather than univariate per-asset objectives
  4. Regime-robust minimax optimisation — a SoftMin proxy for Entropic Value-at-Risk (EVaR) that penalises the worst historical subperiods
  5. Realistic transaction costs in the loss — asset-specific costs baked directly into the training objective
  6. 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 paper Trading with the Momentum Transformer: An Intelligent and Interpretable Architecture and additionally provides an implementation for the paper Slow Momentum with Fast Reversion: A Trading Strategy Using Deep Learning and Changepoint Detection.

Using the code

  1. 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.
  2. Download the Quandl data with: python -m data.download_quandl_data <>
  3. 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.
  4. Optionally, run the changepoint detection module: python -m examples.concurent_cpd_quandl <>, for example python -m examples.concurent_cpd_quandl 21 and python -m examples.concurent_cpd_quandl 126
  5. Create Momentum Transformer input features, including CPD module features with: python -m examples.create_features_quandl 21 after the changepoint detection module has completed.
  6. To create a features file with multiple changepoint detection lookback windows: python -m examples.create_features_quandl 126 21 after the 126 day LBW changepoint detection module has completed and a features file for the 21 day LBW exists.
  7. Run one of the Momentum Transformer or Slow Momentum with Fast Reversion experiments with python -m examples.run_dmn_experiment <>

Trading with the Momentum Transformer: An Intelligent and Interpretable Architecture

Deep learning architectures, specifically Deep Momentum Networks (DMNs) , have been found to be an effective approach to momentum and mean-reversion trading. However, some of the key challenges in recent years involve learning long-term dependencies, degradation of performance when considering returns net of transaction costs and adapting to new market regimes, notably during the SARS-CoV-2 crisis. Attention mechanisms, or Transformer-based architectures, are a solution to such challenges because they allow the network to focus on significant time steps in the past and longer-term patterns. We introduce the Momentum Transformer, an attention-based architecture which outperforms the benchmarks, and is inherently interpretable, providing us with greater insights into our deep learning trading strategy. Our model is an extension to the LSTM-based DMN, which directly outputs position sizing by optimising the network on a risk-adjusted performance metric, such as Sharpe ratio. We find an attention-LSTM hybrid Decoder-Only Temporal Fusion Transformer (TFT) style architecture is the best performing model. In terms of interpretability, we observe remarkable structure in the attention patterns, with significant peaks of importance at momentum turning points. The time series is thus segmented into regimes and the model tends to focus on previous time-steps in alike regimes. We find changepoint detection (CPD) , another technique for responding to regime change, can complement multi-headed attention, especially when we run CPD at multiple timescales. Through the addition of an interpretable variable selection network, we observe how CPD helps our model to move away from trading predominantly on daily returns data. We note that the model can intelligently switch between, and blend, classical strategies - basing its decision on patterns in the data.

Slow Momentum with Fast Reversion: A Trading Strategy Using Deep Learning and Changepoint Detection

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 changepoint 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. Back-testing our model over the period 1995-2020, the addition of the CPD module leads to an improvement in Sharpe ratio of one-third. The 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 interesting as traditional momentum strategies have been underperforming in this period.

References

Please cite our papers with:

@article{wood2021trading,
  title={Trading with the Momentum Transformer: An Intelligent and Interpretable Architecture},
  author={Wood, Kieran and Giegerich, Sven and Roberts, Stephen and Zohren, Stefan},
  journal={arXiv preprint arXiv:2112.08534},
  year={2021}
}

@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}
}

The Momentum Transformer uses a number of components from the Temporal Fusion Transformer (TFT). The code for the TFT can be found here.

Sample results

Will be made available soon.

Subsequent work

We also have a follow-up paper: Few-Shot Learning Patterns in Financial Time-Series for Trend-Following Strategies

排名相邻
同类项目