A full-stack, end-to-end quantitative portfolio optimizer designed for the Indian stock market (NSE). This project computes optimal capital allocation using modern portfolio theory, allowing investors to maximize risk-adjusted returns or minimize volatility across a selected basket of Indian equities.
- Automated Data Pipeline: Fetches and cleans up to 2 years of daily OHLCV historical pricing data from Yahoo Finance. Users simply input standard NSE tickers (e.g., RELIANCE, TCS, INFY) and the backend automatically normalizes them (
.NS). - Optimization Routines:
- Max Sharpe Ratio: Discovers the portfolio weight allocation that maximizes return per unit of risk, benchmarked against the default Indian risk-free rate (6.5%).
- Global Minimum Variance: Identifies the portfolio structure with the lowest absolute volatility.
- Custom Target Return: Computes the lowest-risk portfolio that mathematically guarantees a precise target yield.
- Interactive Dashboard: Built with Vanilla HTML/JS and Plotly.js to render real-time Efficient Frontier scatter plots and customized asset allocation donut charts.
- Data Export: Instant CSV export of weights, performance metrics, and equal-weight comparison baselines, standardized in ₹ INR.
- Backend / API: FastAPI, Python 3.9
- Quantitative Engine:
scipy.optimize.minimize(SLSQP with multi-start architecture for edge case handling),pandas,numpy,yfinance - Frontend: Vanilla HTML5 / CSS Variables / Vanilla JS, Plotly.js (CDN)
- UI Design System: Custom-built, developer-focus aesthetic using Inter and JetBrains Mono.
- Python 3.9+
pip
-
Clone the repository:
git clone https://github.com/SakshamDev/portfolio-optimizer.git cd portfolio-optimizer -
Install the dependencies:
pip install -r requirements.txt
-
Start the backend server:
python backend/main.py
-
Launch the dashboard: Open your browser and navigate to
http://localhost:8000.
- Long-only Portfolios: Short selling is unsupported (Weights ≥ 0).
- Fully Invested: The model enforces that 100% of capital must be allocated.
- Asset Limits: An arbitrary concentration cap of 40% per individual asset is set to prevent extreme skewing. Max limit of 10 tickers simultaneously to ensure API reliability.
- Incorporate custom risk models (e.g., Shrinkage estimators for the Covariance matrix).
- Add support for fractional shares and precise capital sizing (e.g., allocating a specific ₹ amount instead of raw percentages).
- Integrate continuous deployment via Render or Railway.