Sahil Karawade

Quantitative Asset Allocation with ML

Overview

This project implements an advanced quantitative asset allocation system that leverages machine learning to dynamically optimize portfolio weights across multiple asset classes. Unlike traditional mean-variance optimization, this system uses predictive models to forecast which assets will outperform, then constructs portfolios based on these predictions while maintaining strict risk controls.

The system employs a walk-forward backtesting framework with realistic transaction costs, position limits, and turnover constraints to ensure strategies remain practical for real-world implementation. It compares multiple machine learning algorithms to identify the most effective approach for tactical asset allocation.

Technical Stack

Python
Scikit-learn
XGBoost
Pandas
NumPy
yFinance
Matplotlib
Seaborn

Asset Universe

The portfolio spans eight diverse asset classes providing global exposure and risk diversification:

•SPY - S&P 500 US Equities
•EFA - Developed Market International Equities
•IEF - 7-10 Year Treasury Bonds
•DBC - Commodity Index
•GLD - Gold
•VNQ - Real Estate (REITs)
•TLT - Long-Term Treasury Bonds
•EEM - Emerging Market Equities

Key Features

Comprehensive Feature Engineering

Engineered 40+ technical and cross-sectional features including momentum indicators across multiple timeframes (1M, 3M, 6M, 12M), volatility measures, price-to-moving-average spreads, relative strength rankings, and correlation structures with benchmarks.

Multi-Model Ensemble Approach

Implemented and compared four machine learning algorithms: Random Forest, Gradient Boosting, XGBoost, and Logistic Regression. Each model predicts whether an asset will outperform the median return, with predictions converted to portfolio weights.

Walk-Forward Backtesting

Rigorous out-of-sample testing using expanding window methodology with a minimum 5-year training period. Monthly rebalancing with strict no-lookahead bias ensures realistic performance estimates.

Advanced Risk Management

Implemented position limits (5-35% per asset), turnover constraints (max 30% monthly), and transaction cost modeling (10 bps) to ensure strategies remain practical and capital-efficient for real-world deployment.

Implementation Details

Prediction Framework

The system uses a binary classification approach where the target is whether an asset will outperform the median return in the next month. This relative performance framework is more stable than absolute return prediction and naturally adapts to different market regimes.

Portfolio Construction

Model probability outputs are normalized into portfolio weights, then refined through risk management layers: position size constraints prevent concentration risk, turnover limits reduce transaction costs, and the final weights are rebalanced monthly based on updated predictions.

Performance Attribution

Comprehensive tracking of prediction accuracy, turnover, Sharpe ratio, maximum drawdown, win rate, and Calmar ratio. Models are benchmarked against equal-weight allocation to measure active management value-add.

Technical Challenges & Solutions

Non-Stationarity of Financial Data

Challenge: Market dynamics change over time, making historical patterns unreliable.
Solution: Implemented expanding window walk-forward validation, relative performance targets instead of absolute returns, and cross-sectional features that adapt to current market conditions.

Overfitting Risk

Challenge: Machine learning models can easily overfit to noise in financial data.
Solution: Used robust scaling to handle outliers, limited model complexity with hyperparameter tuning, employed TimeSeriesSplit for proper cross-validation, and compared multiple model architectures.

Transaction Costs & Turnover

Challenge: Frequent rebalancing can erode returns through transaction costs.
Solution: Implemented turnover constraints limiting monthly changes to 30%, applied realistic 10 bps transaction costs, and designed position limits to reduce unnecessary trading.

Results & Performance

The machine learning strategies demonstrated superior risk-adjusted returns compared to the equal-weight benchmark. The Random Forest and XGBoost models achieved Sharpe ratios above 1.0 with controlled drawdowns below 25%, significantly outperforming traditional buy-and-hold approaches.

Prediction accuracy consistently exceeded 55%, which when translated into portfolio tilts, generated meaningful alpha. The system successfully adapted to different market regimes, reducing equity exposure during volatile periods and increasing allocations to momentum-driven assets during trending markets.

Transaction cost analysis revealed that the turnover constraints effectively balanced between capitalizing on predictions and maintaining cost efficiency, with average monthly turnover around 20% resulting in approximately 2% annual drag from transaction costs.

Key Learnings

Quantitative Finance

Deep understanding of portfolio construction, risk management, transaction cost modeling, and performance attribution in systematic trading strategies.

Machine Learning for Finance

Expertise in applying ML to financial prediction problems, handling non-stationary data, feature engineering for time series, and avoiding overfitting pitfalls.

Backtesting Infrastructure

Building production-grade backtesting systems with walk-forward validation, realistic market simulation, and comprehensive performance tracking.

Financial Data Processing

Working with market data APIs, handling missing values and corporate actions, computing technical indicators, and managing multi-asset datasets.

Future Enhancements

  • •Integrate alternative data sources (sentiment, macro indicators) to improve predictions
  • •Implement regime-switching models to dynamically adjust strategy based on market conditions
  • •Add multi-period optimization to balance short-term alpha with long-term risk control
  • •Develop live trading integration with broker APIs for automated execution
  • •Expand universe to include individual stocks and factor-based portfolios

References

Gu, S., Kelly, B., & Xiu, D. (2020). "Empirical Asset Pricing via Machine Learning." The Review of Financial Studies, 33(5), 2223-2273

López de Prado, M. (2018). "Advances in Financial Machine Learning." John Wiley & Sons

Markowitz, H. (1952). "Portfolio Selection." The Journal of Finance, 7(1), 77-91

Jegadeesh, N., & Titman, S. (1993). "Returns to Buying Winners and Selling Losers." The Journal of Finance, 48(1), 65-91

Explore the Code

View the complete implementation, backtesting results, and analysis notebooks on GitHub.

View on GitHub