GitHub Actions
Sync from GitHub: f5aa990994d06264b868e62464282c3f6d0c2337
d8f24bd
---
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