US Rebalance Analysis Classifier FastAPI
Objective: compute multi-indicator technical analysis relative to the US_REBALANCE benchmark, train ML models
to classify positive forward returns, backtest a strategy based on consecutive positive signals, and generate a unified PDF report.
Expected output: downloadable PDF + CSV summary, inline charts (indicators, backtest),
and a simple metrics list per selected sector.
📊 Technical Methodology & Implementation Details
🔧 Technical Indicators Used:
- RSI (Relative Strength Index): 14-period momentum oscillator (30/50/70 thresholds)
- MACD: 12,26,9 exponential moving average crossover with signal line
- Coppock Curve: Long-term momentum indicator with turn-up/zero-cross signals
- Bollinger Bands: 20-period SMA with 2 standard deviation bands
- KST (Know Sure Thing): Multi-timeframe momentum oscillator
- Monthly MACD: Long-term trend analysis using monthly data
- PPO (Percentage Price Oscillator): MACD alternative using percentages
- Stochastic Oscillator: %K and %D momentum indicators
- Williams %R: Momentum oscillator measuring overbought/oversold levels
- MAS (Moving Average Slope): Trend direction indicator
- CLV (Close Location Value): Price position within daily range
- MA50/MA200: Short and long-term moving averages
🤖 Machine Learning Approach:
- Classification Model: Random Forest or XGBoost to predict positive 5-day forward returns
- Feature Engineering: Lagged indicators (RSI, MACD, Coppock) + binary signals (RSI thresholds, MACD crossover, Coppock signals)
- Train/Test Split: 80/20 chronological split to prevent look-ahead bias
- Target Variable: Binary classification (1 if 5-day forward return > 0, 0 otherwise)
- Feature Selection: Permutation importance analysis to identify most predictive indicators
📈 Regression Mode (Optional):
- Regression Target: Actual 5-day forward return values (continuous)
- Models: Random Forest Regressor or XGBoost Regressor
- Metrics: R², MAE (Mean Absolute Error), RMSE (Root Mean Square Error)
- Forecast: Point estimate of expected return for next period
âš¡ Backtesting Strategy:
- Entry Condition: ML model predicts positive return for 3 consecutive days
- Hold Period: 20 trading days (approximately 1 month)
- Exit Strategy: Fixed time-based exit (no stop-loss or take-profit)
- Position Sizing: Equal weight per trade (no leverage considerations)
- Transaction Costs: Not included in backtest (assumes frictionless trading)
- Benchmark: US_REBALANCE index for relative performance analysis
📊 Performance Metrics:
- ML Accuracy: Classification accuracy on test set
- Cumulative Return: Total return from all trades (geometric mean)
- Win Rate: Percentage of profitable trades
- Number of Trades: Total trading opportunities identified
- Forecast Probability: ML model's confidence in positive prediction
Run Analysis
Reports