# Task: Complete rotation ranking service ## Goal Implement the ranking logic for sector rotation in `services/rotation_service.py`. The service currently has skeleton methods for ranking but needs the actual implementation. ## Requirements ### Implement ranking methods in `services/rotation_service.py` 1. `rank_sectors(sector_data, timeframe="20d")` method: - Accept a list of sector data dicts (from the database) - Sort sectors by momentum score (descending) - Assign rank_now to each sector - Calculate rank_change compared to previous ranking - Return ranked sector list 2. `get_ranking_history(ticker, days=30)` method: - Query historical rankings from the database (TimescaleDB hypertable) - Return time-series of rank data for charting - Use `execute_query` with parameterized queries 3. `calculate_relative_strength(ticker, benchmark="SPY")` method: - Calculate price ratio between sector ETF and benchmark - Compute relative strength as a percentage change - Return strength metric ### Database interactions - Read from `sector_rankings` hypertable (TimescaleDB) - Use parameterized queries - Handle missing data gracefully (return empty lists) ## Acceptance Criteria 1. `rank_sectors()` returns properly ranked sector list 2. `get_ranking_history()` returns time-series data 3. `calculate_relative_strength()` returns strength metric 4. All methods are async 5. File stays under 200 lines ## Files to Modify - `src/backend/services/rotation_service.py` ## Files to Read First - `src/backend/services/rotation_service.py` — current state - `src/backend/database.py` — query patterns - `src/backend/tests/test_sector_rotation.py` — test expectations