Quant notes · 05 research plan

Development, backtesting and out-of-sample evaluation of two long/short models on gold and bitcoin

A daily trend model and an intraday model on XAU/USD and BTC/USD are specified from the literature, backtested net of transaction costs, validated by walk-forward analysis, frozen, and run on a simulated account.

1 · Structure

Four phases:

Selecting a week on the timeline shows its summary; section 2 gives the full scope.

Timeline

select a week
completein progressa model begins simulated trading

2 · Weekly scope

Each week specifies the work (what is built or tested), the reading (the sources consulted before the work, so that methods are taken from the literature rather than improvised) and the deliverable (the file that records the week's result). Where a note on this site covers the week's method, it is linked. Reading items are labelled by subject. The mathematics lane (Shreve, Stochastic Calculus for Finance) runs in parallel and does not block the model work; it is first required in week 11, where an Ornstein–Uhlenbeck process is fitted.

Subject:financestatisticsmathematicsprogramming

In this project

Where each phase is implemented in the xau-btc-models repository.

src/data.pyWeek 1. Downloads and cleans the daily table: one row per calendar day, columns btc, xau, xau_tradable.
src/backtest.pyWeek 2. The backtester with the lag, the cost model, the tradable mask, stats, yearly and walk_forward. Read line by line in note 04.
src/signals.pyWeeks 3–4. The trend rules: tsmom, tsmom_multi, ma_cross, donchian; EWMAC joins in week 3.
scripts/NN_*.pyWeeks 2–7. One research question per numbered script; 02_cost_sensitivity.py is week 2's.
notes/research_log.mdEvery week. One table row per test, written before the test runs. Failures stay.
live/live_alpaca.pyWeeks 8 and 14. The daily script that turns a frozen rule into orders on the simulated account and appends to results/live_log.csv.
notes/<model>_spec.mdWeeks 7 and 13. The frozen rule, written out exactly, before any live order.
tests/Every change to src/. Buy-and-hold reproduces the asset, the position is yesterday's signal, costs reduce returns, the mask freezes gold.

Sources

The reading in section 2 names each paper by the week it is read. Listed here once, in reading order.

López de PradoM. López de Prado, "The 10 Reasons Most Machine Learning Funds Fail", Journal of Portfolio Management 44 (2018). Week 2.
RiskMetricsJ.P. Morgan / Reuters, RiskMetrics Technical Document, 4th ed., 1996, ch. 5. Week 2.
Bailey et al. 2014D. Bailey, J. Borwein, M. López de Prado, Q. J. Zhu, "Pseudo-Mathematics and Financial Charlatanism", Notices of the AMS 61 (2014). Week 2.
SharpeW. F. Sharpe, "The Sharpe Ratio", Journal of Portfolio Management 21 (1994). Week 2.
Moskowitz et al.T. Moskowitz, Y. H. Ooi, L. H. Pedersen, "Time Series Momentum", Journal of Financial Economics 104 (2012). Week 3.
Hurst et al.B. Hurst, Y. H. Ooi, L. H. Pedersen, "A Century of Evidence on Trend-Following Investing", Journal of Portfolio Management 44 (2017). Week 3.
Liu & TsyvinskiY. Liu, A. Tsyvinski, "Risks and Returns of Cryptocurrency", Review of Financial Studies 34 (2021). Week 3.
TsayR. Tsay, Analysis of Financial Time Series, 2nd ed., Wiley, 2005. Ch. 1 and 3 in week 4; ch. 2 in week 9; ch. 8 in week 10.
WassermanL. Wasserman, All of Statistics, Springer, 2004, ch. 2–3. Week 4, optional.
MarkowitzH. Markowitz, "Portfolio Selection", Journal of Finance 7 (1952). Week 5.
Bailey et al. 2015D. Bailey, J. Borwein, M. López de Prado, Q. J. Zhu, "The Probability of Backtest Overfitting", working paper 2015, published in Journal of Computational Finance 20 (2017). Week 5.
Bailey & López de PradoD. Bailey, M. López de Prado, "The Deflated Sharpe Ratio", Journal of Portfolio Management 40 (2014). Week 6.
Harvey & LiuC. Harvey, Y. Liu, "Backtesting", Journal of Portfolio Management 42 (2015). Week 6.
LoA. W. Lo, "The Statistics of Sharpe Ratios", Financial Analysts Journal 58 (2002). Week 6.
Efron & TibshiraniB. Efron, R. Tibshirani, An Introduction to the Bootstrap, Chapman & Hall, 1993, ch. 1–6. Week 7.
Politis & RomanoD. Politis, J. Romano, "The Stationary Bootstrap", Journal of the American Statistical Association 89 (1994). Week 7.
Lo & MacKinlayA. Lo, A. C. MacKinlay, "Stock Market Prices Do Not Follow Random Walks", Review of Financial Studies 1 (1988). Week 9.
Halls-MooreM. Halls-Moore, Successful Algorithmic Trading, QuantStart, 2015, the cointegration chapter. Week 10.
ShreveS. Shreve, Stochastic Calculus for Finance I: The Binomial Asset Pricing Model, Springer, 2004. Weeks 1–3 of the mathematics lane.
Avellaneda & LeeM. Avellaneda, J.-H. Lee, "Statistical Arbitrage in the US Equities Market", Quantitative Finance 10 (2010), section 2 and appendix. Week 11.

Carver's Systematic Trading (2015), its companion spreadsheets, Chan's Algorithmic Trading (2013), Shreve's Stochastic Calculus for Finance II (2004) and the pysystemtrade documentation are quoted from the reading list, not from the text. Part of quant-notes. See also 01 · Time-series momentum, 02 · Volatility estimation by EWMA, 03 · Backtest errors and controls, Backtester implementation and 06 · Sharpe ratio estimation.