HADIGHOREISHI/tsx-sector-rotation
0
TSX Sector Rotation & Risk Dashboard
Live TSX sector analytics: risk/return, drawdowns, rolling volatility, correlations, momentum, and a simple rotation strategy (6/12-month momentum + drawdown filter).
Stack: Python · Streamlit · Plotly · pandas · yfinance · (optional) Tableau. Deploy: Hugging Face Spaces (Streamlit) with datasets hosted on the Hugging Face Hub (Parquet).
Features
- Daily prices for TSX sector ETFs (default):
XIU.TO, XIC.TO, XFN.TO, XMA.TO, XEG.TO, XIT.TO, XRE.TO - Metrics: returns, rolling volatility (21/63/252d), rolling Sharpe, max drawdown, 12- and 6-month momentum
- Correlation heatmap, equity curve, drawdown curve
- Rotation backtest: monthly rebalance, long top-2 momentum sectors if recent drawdown above threshold isn’t breached; otherwise defensive (XIU) or cash
- Switch between local yfinance fetch or Hub dataset (Parquet) for fast loads in production
Quickstart (local)
python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
streamlit run app/streamlit_app.pyDeploy to Hugging Face Spaces
- Create a Space (type Streamlit) named
your-username/tsx-sector-rotation. - Push this repo to that Space (connect via Git + Git LFS).
- (Optional, recommended) Create a Datasets repo
your-username/tsx-sector-rotation-dataand uploaddata/processed/*.parquet. Inapp/streamlit_app.py, set Data Source → Hugging Face Hub and fill in your dataset path. - Add your Space URL + repo link to LinkedIn Featured.
Data sources
- Prices via yfinance (Yahoo! Finance). Data may be delayed; for production, consider a paid real-time data provider.
- Processed snapshots can be stored as Parquet in an HF Datasets repo for versioning/reproducibility.
Project structure
tsx-sector-rotation/
├─ app/
│ └─ streamlit_app.py
├─ src/
│ ├─ data.py
│ ├─ features.py
│ ├─ backtest.py
│ └─ viz.py
├─ data/
│ ├─ raw/
│ └─ processed/
├─ notebooks/
│ └─ 01_exploration.ipynb (placeholder)
├─ requirements.txt
├─ README.md
└─ LICENSEI built a TSX Sector Rotation & Risk Dashboard: momentum, drawdowns, rolling risk, and a simple rotation backtest across Canadian sector ETFs (XIU, XFN, XMA, XEG, XIT, XRE).
#python #streamlit #canada #tsx #dataanalytics #finance #tableau
License
MIT — educational purposes only; not investment advice.
