A newer version of the Streamlit SDK is available:
1.55.0
metadata
title: P2-ETF-CNN-LSTM-ALTERNATIVE-APPROACHES
emoji: π§
colorFrom: green
colorTo: blue
sdk: streamlit
sdk_version: 1.32.0
python_version: '3.10'
app_file: app.py
pinned: false
P2-ETF-CNN-LSTM-ALTERNATIVE-APPROACHES
Macro-driven ETF rotation using three augmented CNN-LSTM variants.
Winner selected by highest raw annualised return on the out-of-sample test set.
Architecture Overview
| Approach | Core Idea | Key Addition |
|---|---|---|
| 1 β Wavelet | DWT decomposes each macro signal into frequency subbands before the CNN | Separates trend / cycle / noise |
| 2 β Regime-Conditioned | HMM detects macro regimes; one-hot regime label concatenated into the network | Removes non-stationarity |
| 3 β Multi-Scale Parallel | Three CNN towers (kernels 3, 7, 21 days) run in parallel before the LSTM | Captures momentum + cycle + trend simultaneously |
ETF Universe
| Ticker | Description |
|---|---|
| TLT | 20+ Year Treasury Bond |
| TBT | 20+ Year Treasury Short (2Γ) |
| VNQ | Real Estate (REIT) |
| SLV | Silver |
| GLD | Gold |
| CASH | 3m T-bill rate (from HF dataset) |
Benchmarks (chart only, not traded): SPY, AGG
Data
All data sourced exclusively from:P2SAMAPA/fi-etf-macro-signal-master-data (HuggingFace Dataset)
File: master_data.parquet
No external API calls (no yfinance, no FRED).
The app checks daily whether the prior NYSE trading day's data is present in the dataset.
Project Structure
βββ .github/
β βββ workflows/
β βββ sync.yml # Auto-sync GitHub β HF Space on push to main
β
βββ app.py # Streamlit orchestrator (UI wiring only)
β
βββ data/
β βββ loader.py # HF dataset load, freshness check, column validation
β
βββ models/
β βββ base.py # Shared: sequences, splits, scaling, callbacks
β βββ approach1_wavelet.py # Wavelet CNN-LSTM
β βββ approach2_regime.py # Regime-Conditioned CNN-LSTM
β βββ approach3_multiscale.py # Multi-Scale Parallel CNN-LSTM
β
βββ strategy/
β βββ backtest.py # execute_strategy, metrics, winner selection
β
βββ signals/
β βββ conviction.py # Z-score conviction scoring
β
βββ ui/
β βββ components.py # Banner, conviction panel, metrics, audit trail
β βββ charts.py # Plotly equity curve + comparison bar chart
β
βββ utils/
β βββ calendar.py # NYSE calendar, next trading day, EST time
β
βββ requirements.txt
βββ README.md
Secrets Required
| Secret | Where | Purpose |
|---|---|---|
HF_TOKEN |
GitHub + HF Space | Read HF dataset Β· Sync HF Space |
Set in:
- GitHub:
Settings β Secrets β Actions β New repository secret - HF Space:
Settings β Repository secrets
Deployment
Push to main β GitHub Actions (sync.yml) automatically syncs to HF Space.
Local development
pip install -r requirements.txt
export HF_TOKEN=your_token
streamlit run app.py
Output UI
- Data freshness warning β alerts if prior NYSE trading day data is missing
- Next Trading Day Signal β date + ETF from the winning approach
- Signal Conviction β Z-score gauge + per-ETF probability bars
- Performance Metrics β Annualised Return, Sharpe, Hit Ratio, Max DD
- Approach Comparison Table β all three approaches side by side
- Equity Curves β all three approaches + SPY + AGG benchmarks
- Audit Trail β last 20 trading days for the winning approach