Quantitative trading — backtest, drawdown, factor exposure
30 minutes. Two CSVs. Run a momentum strategy on 20 tickers over 500 trading days and see how it would have done.
The scenario
You’re a solo quant running a small book. You want to evaluate a simple idea: own stocks whose close is more than 2% above their 20-day moving average, short the ones more than 2% below, equal-weight the rest. Lots of papers have tested it. You want to run it yourself, on your own data, in a notebook that anyone on your team can read.
This tutorial is the Tablize version of a Jupyter session. Four questions:
- What would the strategy have returned over the last 500 trading days?
- What was the drawdown profile — and was it tolerable?
- What factor exposures does the strategy end up with — was it actually long/short, or just long-biased?
- Can we run it forward as a daily Script against live data?
Note: the data is synthetic. It’s realistic in shape (cross-sectional noise, 2022-style drawdown injected around days 300-340) but do not draw real-world conclusions from it. For live data, connect a provider — see Next steps.
Download the sample data
Backtest the strategy
| Metric | Momentum | Long-only benchmark |
|---|---|---|
| Total return | +32.4% | +41.8% |
| Annualized return | 14.9% | 18.4% |
| Annualized vol | 11.2% | 18.6% |
| Sharpe (rf=4%) | 2.21 | 1.95 |
| Max drawdown | -8.2% | -22.4% |
Keep it: + Save as Script named “momentum backtest” — rerunnable with different parameter values (window size, threshold, rebalance frequency).
Drawdown profile
Expected answer: the Agent finds the drawdown around days 300-340 (the injected market stress period). The long-only fell ~22% and took ~50 trading days to recover. The momentum fell ~8% and recovered in ~25 days. Plotted side by side.
Keep it: + Save as Report — attach to your risk narrative.
Factor exposure
The Agent shows net exposure hovering around zero (as intended) but with brief periods of strong net-long (during uptrends, most tickers trigger “long”). Sector tilt analysis shows the strategy spent significant time net-long Tech and net-short Consumer Staples — not surprising but worth flagging.
Keep it: + Save as Script — feeds a weekly risk review.
Run it live
The Agent creates the Script with a daily schedule. Each run produces a trade list. You review the list before executing — automation for the analysis, human-in-the-loop for the execution.
What you built in 30 minutes
- 2 Reports — backtest performance, drawdown analysis.
- 2 Scripts — backtest rerunnable with new parameters; daily live signal generator.
- A foundation — for adding more signals, more instruments, more sophisticated risk.
Next steps in this industry
- Connect real data — Alpaca, Interactive Brokers, Polygon, Refinitiv — all via Web API. Daily prices are free/cheap; intraday gets pricier.
- Extend to multiple signals — momentum × value × quality. Rank-combine. Standard factor model.
- Paper trade first — run the daily Script for a month, log the paper trades, compare to live would-have-been. Rarely does research PnL match live; discovering that 10% miss is the whole point.
- Read the Quant Trading industry page — deeper scenarios: transaction cost modeling, walk-forward validation, ensemble strategies.