--- 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 ```bash pip install -r requirements.txt export HF_TOKEN=your_token streamlit run app.py ``` --- ## Output UI 1. **Data freshness warning** โ€” alerts if prior NYSE trading day data is missing 2. **Next Trading Day Signal** โ€” date + ETF from the winning approach 3. **Signal Conviction** โ€” Z-score gauge + per-ETF probability bars 4. **Performance Metrics** โ€” Annualised Return, Sharpe, Hit Ratio, Max DD 5. **Approach Comparison Table** โ€” all three approaches side by side 6. **Equity Curves** โ€” all three approaches + SPY + AGG benchmarks 7. **Audit Trail** โ€” last 20 trading days for the winning approach