This project delivers a comprehensive implementation of the Markowitz mean-variance portfolio optimization model focused specifically on Indian equities. It aims to assist investors in crafting an optimal portfolio by balancing return and risk using historical stock price data.
The core idea behind the implementation is to calculate the efficient frontier, which represents the set of portfolios that offer the highest expected return for a given level of risk. The project additionally optimizes for the maximum Sharpe Ratio portfolio to maximize risk-adjusted returns.
Key components of the project include:
- Data Acquisition: Historical adjusted closing prices for a selected basket of Indian stocks are fetched via Yahoo Finance API. The dataset undergoes cleansing to handle missing values and ensure data integrity.
- Return and Risk Calculation: Daily returns are computed from price data, then annualized to get expected returns and the covariance matrix representing risks and correlations among stocks.
- Covariance Matrix Regularization: Since real stock data can lead to near-singular or unstable covariance matrices (causing optimization issues), a small regularization term is added to the diagonal for numerical stability.
- Quadratic Programming for Mean-Variance Optimization: Using libraries like
cvxopt, the project solves the quadratic program to minimize portfolio variance for given target returns, thereby generating the efficient frontier. - Maximum Sharpe Ratio Optimization: Using constrained optimization (
scipy.optimize), the portfolio weights are found that maximize the Sharpe Ratio considering a risk-free rate, thus identifying the best risk-adjusted portfolio. - Visualization: The efficient frontier curve is plotted to show trade-offs between risk (volatility) and expected return, aiding decision-making.
- Output and Interpretation: Project outputs include optimal weights per stock for different target returns, expected portfolio returns, risk (standard deviation), and the Sharpe ratio for maximum risk-adjusted return.
This project serves as an educational and practical resource for portfolio managers, financial analysts, and individual investors aiming to apply quantitative finance techniques specifically to the Indian equity market. It also addresses practical data challenges like missing data and covariance instability.
- Fetches, cleans, and preprocesses Indian stocks' historical price data.
- Calculates daily and annualized returns and covariance matrix.
- Regularizes covariance to ensure matrix invertibility.
- Solves mean-variance optimization with return constraints.
- Finds portfolio maximizing Sharpe Ratio under realistic constraints.
- Visualizes the efficient frontier for intuitive interpretation.
- Outputs clear portfolio weights, portfolio statistics, and visual aids.
- Python 3.10+
- pandas, numpy for data manipulation and calculations
- matplotlib for plotting and visualizations
- yfinance for fetching market data