A quantitative research project that builds a volatility-scaled trend-following strategy on continuous futures and stress-tests it across parameters, timeframes, indicator families, walk-forward windows, and a multi-asset portfolio. The emphasis is on honest evaluation and overfitting risk rather than curve-fitted performance.
A continuous, volatility-normalized trend-following position:
position = EMA(log returns) / (signal_vol * asset_vol) * scale (capped at +/- pos_limit)
- EMA of log returns — the trend signal over a look-back
period; positive => long, negative => short. - signal_vol — volatility of the signal (EMA of absolute log returns).
- asset_vol — instrument volatility (double-smoothed EMA of absolute log returns).
- scale — scales the influence of volatility on the final target position.
Dividing by volatility gives dynamic position sizing: exposure shrinks in turbulent regimes and grows in calm trends.
- No look-ahead — all features are computed on shifted data, so a bar's position only uses information available before it.
- Costs — per-trade slippage applied on position changes.
- Calendar-day annualization — zero returns inserted on non-trading days (instead of the usual 252-day convention), so strategies across instruments, exchanges and timezones stay comparable.
- In-sample / out-of-sample split — parameters optimized on 2018 to mid-2022, then evaluated on the held-out test period.
- Tear sheets — full performance/risk reporting via
pyfolio.
The base notebook is extended with five self-contained studies:
| # | Study | Question | Key finding |
|---|---|---|---|
| 1 | Parameter robustness | How sensitive is the strategy near its optimum? | period sits on a plateau (best ~263): moving to neighbouring grid values costs only ~4–4.5% Sharpe => robust, low overfitting risk on this axis. |
| 2 | Multi-timeframe | Does edge survive from 5-min to daily? | Clear monotonic decay: Sharpe > 1.40 at 5-min, > 1.22 at 15-min, falling to ~0.38 daily. The optimal look-back (in bars) scales down with the timeframe. |
| 3 | Indicator families | Do EWMAC / MACD / Bollinger beat the base signal? | None beat the benchmark or the original signal; MACD was the most respectable of the alternatives. |
| 4 | Walk-forward optimization | Are the optimal parameters stable through time? | With 2-year train / 3-month test windows and purging, the best period jumps erratically (~200 to ~3400) with no stable optimum — a caution against trusting a single in-sample fit. |
| 5 | Multi-asset portfolio | Does diversification help? | Equal-weighted WFO portfolio over NQ, JY, BTC produces a visibly smoother equity curve, but near-zero total return — NQ's gains are offset by JY/BTC losses. |
The honest negative results (Studies 3–5) are the point: they demonstrate walk-forward discipline, purging against leakage, and skepticism toward in-sample Sharpe.
pip install -r requirements.txt jupyter notebook notebooks/01_trend_following_research.ipynb
The notebook works on intraday logarithmic returns of continuous
(back-adjusted) futures — one CSV per instrument named {ticker}.csv. Each
file is indexed by a date timestamp column (YYYY-MM-DD HH:MM:SS, ~5-minute
bars) holding the log-return series; coarser timeframes are produced by
resampling inside the notebook.
Instruments used in this study:
| Ticker | Instrument | Asset class |
|---|---|---|
NQ |
E-mini Nasdaq-100 index futures (CME) | Equity index |
JY |
Japanese Yen FX futures (CME) | Currency |
BTC |
Bitcoin | Crypto |
Data is not bundled (see .gitignore). To reproduce, supply your own
{ticker}.csv files next to the notebook. Continuous-futures return series like
these are typically obtained from:
- commercial historical-data vendors that publish ready-made back-adjusted continuous-futures series, or
- a broker / exchange market-data API (e.g. CME-listed contracts via a broker; crypto such as BTC directly from an exchange API), or
- built yourself by stitching and back-adjusting consecutive contract expiries into a single continuous series.
Any source works as long as the CSV matches the date + log-return format above.
trend-following-futures/
├── notebooks/
│ └── 01_trend_following_research.ipynb strategy + 5 research studies
├── requirements.txt
├── LICENSE
└── README.md
pandas · numpy · matplotlib · pyfolio (tear sheets) · tqdm ·
grid search · walk-forward optimization with purging
Educational / research project on historical data. Not investment advice. Backtested results do not guarantee future performance.