Yousafza1/financial-price-forecasting
Multi-market price forecasting with PatchTST
Forecasts next-step (configurable horizon) log returns for crypto, forex, stocks and indices from free public data (yfinance + Binance/ccxt). Model: channel-independent PatchTST with RevIN, ~150–300K params — the top-tier architecture in a 918-experiment controlled benchmark on crypto/forex/index data (arXiv 2603.16886), and cheap enough for a T4.
Why these choices
- Target is log return, not price. Price targets break under cross-asset scale differences (BTC ~$100k vs EURUSD ~1.08) and the random walk. RevIN instance normalization inside the model handles the rest of the shift.
- Direction is measured, not promised. MSE-trained models score ~50% directional accuracy at short horizons in controlled studies; treat directional accuracy and the naive-strategy Sharpe as the honest metrics, with a binomial z-test against 50%.
- Leakage is guarded three ways: trailing-window feature statistics only, chronological 70/15/15 splits with
pred_lenpurge rows at boundaries, and windows built strictly inside each split.
Pipeline
python download_data.py --out-dir data/raw --start 2017-01-01
python build_dataset.py --raw-dir data/raw --out-dir data/features --pred-len 1
python train_patchtst.py --data-dir data/features \
--hub-model-id Yousafza1/patchtst-financial-dailyDefaults: seq_len=96, pred_len=1, d_model=128, e_layers=3, n_heads=4, d_ff=256, patch_len=16, stride=8, Adam lr=1e-4, batch 128. These follow the reference configs in yuqinie98/PatchTST (pinned commit 204c21e, cloned automatically at train time).
Known biases and limits (read before trusting results)
- Survivorship bias: stock/index ticker lists are today's constituents; delisted names are absent.
- Crypto history starts at listing date (SOL/DOGE have no 2017 data).
- Forex has no volume —
volume_zis 0 there; range and returns carry it. - yfinance is unofficial and rate-limits; the downloader throttles and retries, but re-runs should expect occasional failures per ticker.
- Realistic expectation: near-zero-to-small edge. A ~52–55% directional accuracy with positive test Sharpe would already be a strong result.
Costed run plan (to execute when compute budget is granted)
From Jobs pricing:
Each submission reserves its worst case (price × timeout) and settles to minutes actually used. A $5 budget covers the full pipeline with headroom; a $15 budget allows 3 seeds + a pred_len=5 variant.
