nr.dev
← work
// project

Stock Portfolio Optimizer

Random Forest + CVXPY pipeline, 34% backtested CAGR with 1.38 Sharpe

2025 · live
[ STACK ]
Python scikit-learn CVXPY Docker AWS
[ LINKS ]

A quantitative trading pipeline that pairs machine learning return prediction with convex portfolio optimization. Random Forest regressors trained per ticker on engineered technical features (momentum, rolling volatility, market correlation, volume signals) predict next-day returns, and a CVXPY mean-variance optimizer turns those predictions into portfolio weights. Risk is managed through a quadratic penalty on variance, full-capital long-only constraints, and a 40 percent cap on any single position to prevent concentration.

Backtested with a custom walk-forward engine over 150+ trading days, the strategy hit 34 percent CAGR with a 1.38 Sharpe ratio and 1.45 percent daily volatility, beating the S&P 500 baseline across multiple test window configurations. The full system is productionized: the FastAPI backend lives on AWS EC2 in a Docker container, models are joblib-serialized, the static frontend is served through S3 and CloudFront, and there’s a REST endpoint that accepts a ticker list and budget and returns optimized weights along with expected return and variance.

← back to work