Implementation of a sector rotation trading strategy accross 7 ETF sectors that identifies and invests in the strongest performing market sectors using the MetaSync API.
XLF (Financial Select Sector SPDR Fund): Banks, insurance, financial services XLE (Energy Select Sector SPDR Fund): Oil, gas, and energy companies XLI (Industrial Select Sector SPDR Fund): Manufacturing, aerospace, construction USTEC (NASDAQ-100): Technology proxy for growth exposure
XLP (Consumer Staples Sector SPDR Fund): Essential goods, recession-resistant XLU (Utilities Sector SPDR Fund): Power, water, telecommunications XLV (Healthcare Sector SPDR Fund): Pharmaceuticals, medical devices
- Real-time Market Analysis: Monitors major sector ETFs in real-time
- Relative Strength Scoring: Identifies outperforming sectors
- Interactive Dashboard: Clean console-based dashboard with color-coded signals
- Configurable: Easy to modify sectors, timeframes, and parameters
- Risk Management: Built-in position sizing and risk controls
The strategy works by:
- Tracking major sector ETFs (XLF, XLE, XLI, etc.) and the NASDAQ-100 (USTEC)
- Calculating relative strength compared to the S&P 500 benchmark
- Generating trading signals based on price momentum
- Providing clear visual indicators for sector strength
- Python 3.8 or higher
- MetaSync API key (get it from RapidAPI)
- (Optional) MetaTrader 5 account for live trading
-
Clone the repository:
git clone https://github.com/yllvar/ETF-Sector-Rotation-Strategy.git cd ETF-Sector-Rotation-Strategy -
Set up a virtual environment (recommended):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Configure your environment:
- Copy
.env.exampleto.env - Update with your API credentials
cp .env.example .env
Edit
.env:# MetaSync API Configuration RAPIDAPI_KEY=your_api_key_here # MT5 Account Details (optional) MT5_LOGIN=your_mt5_login MT5_PASSWORD=your_mt5_password MT5_SERVER=your_mt5_server - Copy
-
Start the strategy:
python sector_rotation.py
-
View the interactive dashboard:
================================================================================ SECTOR ROTATION DASHBOARD - 2025-09-25 15:30:00 ================================================================================ Sector Symbol Price Daily % Signal -------------------------------------------------------------------------------- Technology USTEC 14500.50 +1.85% 🟢 STRONG Financials XLF.NYSE 38.75 +1.25% 🟡 NEUTRAL Healthcare XLV.NYSE 125.30 +0.75% 🟡 NEUTRAL ... ================================================================================
Understanding economic cycles is crucial for effective sector rotation. Each phase favors different types of businesses and investment themes. Sector Performance by Economic Phase
This is for educational purposes only. Always test strategies with a paper trading account before risking real capital. Past performance is not indicative of future results.