Data Science & Fintech · /portfolio-optimizer
Stock Portfolio Optimizer
Quantitative Asset Allocation & Risk Analytics Platform using Modern Portfolio Theory
An interactive quantitative finance web application engineered to compute optimal asset allocations using Modern Portfolio Theory (MPT). The platform maximizes risk-adjusted returns (Sharpe Ratio) through non-linear constrained optimization (SciPy SLSQP), simulates a 10,000-iteration Monte Carlo Efficient Frontier, computes parametric risk metrics (VaR/CVaR), and stress-tests portfolio resilience against historical market crashes.
- Python
- Streamlit
- SciPy (SLSQP)
- Modern Portfolio Theory
- Plotly
- Pandas
- NumPy
- yfinance
- Monte Carlo
- Risk Analytics (VaR/CVaR)

Overview
An interactive quantitative finance web application engineered to compute optimal asset allocations using Modern Portfolio Theory (MPT). The platform maximizes risk-adjusted returns (Sharpe Ratio) through non-linear constrained optimization (SciPy SLSQP), simulates a 10,000-iteration Monte Carlo Efficient Frontier, computes parametric risk metrics (VaR/CVaR), and stress-tests portfolio resilience against historical market crashes.
Problem
Retail investors and analysts often rely on intuitive or equal-weight allocation strategies that ignore asset covariance and downside tail risk. The challenge was building an interactive, responsive analytical tool that translates complex financial mathematics into real-time interactive charts with defensive data caching and stress-testing capabilities.
Solution
Constrained Numerical Optimization: Uses SciPy's Sequential Least Squares Programming (SLSQP) to find the maximum Sharpe Ratio allocation under realistic constraints (no short-selling, custom asset weight caps). Monte Carlo Efficient Frontier: Generates 10,000 randomized portfolios plotted as an interactive Plotly scatter chart to visualize risk vs. expected return. Parametric Tail-Risk Modeling: Calculates Value at Risk (VaR) and Conditional VaR (CVaR / Expected Shortfall) at configurable confidence intervals. Backtesting & Stress Testing: Simulates cumulative portfolio growth against benchmarks (SPY) and models drawdown resilience during historical crises (2008 GFC, COVID-19 Crash, 2022 Tech Bear Market).
Architecture & Core Systems
Modular Quant Pipeline: Clean separation of concerns between data ingestion (yfinance + caching), metrics calculation, SciPy optimization, and visualization. Stateful Streamlit UI: Full reactive interface with sidebar configuration controls, multi-tab result views, and auto-themed Plotly charts. Dual Execution Engine: Supports both an interactive Streamlit Cloud web deployment and a standalone CLI runner (main.py).
Technical Implementation
Performance Caching: Integrated Streamlit @st.cache_data to memoize time-series downloads, avoiding redundant API calls and rate-limiting. Defensive Data Alignment: Automated forward/backward fill algorithms handling timezone discrepancies and non-trading days across multiple tickers. Vectorized Math: Fast vectorized matrix operations via NumPy and Pandas for sub-second 10k-point Monte Carlo simulations.
Challenges
Ensuring sub-second real-time responsiveness while computing large covariance matrices and non-linear multi-asset constraints. Accurately modeling tail-risk metrics (CVaR) to represent realistic downside risk during catastrophic market conditions.
Results
Successfully deployed and live on Streamlit Cloud. Open-source on GitHub with complete modular architecture and CLI support.
Lessons Learned
Translating financial theory into functional software requires robust data sanitization and defensive exception handling. Expected Shortfall (CVaR) provides significantly more actionable downside protection insights than standard volatility alone.
Screenshots & Gameplay
Visual assets and in-game captures from Stock Portfolio Optimizer. Click any image to open the full-resolution preview.