harbor run -t xiaoboai/task-00075-sector-momentum-rotation-backtest-with-data-quality-trapsharbor download xiaoboai/task-00075-sector-momentum-rotation-backtest-with-data-quality-trapsI've set up a workspace with weekly OHLCV data for six sector ETFs — XLK, XLF, XLE, XLV, XLI, and XLY — covering about 30 weeks from early January through late July 2024. The prices are in data/sector_prices.csv and there's a SPY benchmark in data/benchmark.csv. I also have a strategy configuration in config/strategy_params.yaml that defines the momentum parameters and portfolio construction rules, plus a transaction cost schedule in config/transaction_costs.json.
There's a reference/strategy_notes.md with some implementation details and override rules you should read before starting — it covers how to handle data quality issues and some risk controls that aren't in the main config. Also check data/sector_metadata.csv for any corporate action info that might affect the price data.
What I need: run a full momentum-based sector rotation backtest using this data. The strategy picks the top sectors by momentum score every few weeks, rebalances into them with equal weighting, and tracks performance over the period. The config has all the formula details — lookback window, rebalancing frequency, number of sectors to hold, etc.
Before computing anything, make sure the price data is clean. I know there might be some issues in there — missing data points, possible duplicates, maybe corporate actions that need adjustment. The strategy notes describe how to handle each case. Getting the data preprocessing right is critical because everything downstream depends on it.
Once the backtest is done, I need three things:
First, write up the full analysis in backtest_report.md — cover the data cleaning steps you took, the momentum scores and portfolio selections at each rebalancing point, period-by-period and cumulative returns, key performance metrics (total return, annualized return, Sharpe ratio, max drawdown), how the strategy compares to SPY, and what the transaction costs look like. Show your work on the calculations.
Second, dump the structured results into backtest_results.json — I need the period-by-period breakdown (which sectors were selected, what the returns were), the overall performance metrics, and the transaction cost summary. Keep the schema clean so I can pipe it into our analytics dashboard.
Third, write a self-contained Python script backtest.py that reproduces the entire backtest from the raw data files. It should handle the data cleaning, run the strategy, and print the key results. Use only standard library plus csv/json/math — no pandas or numpy dependency, since I want it portable.