An open API service indexing awesome lists of open source software.

https://github.com/kaift4/stock-portfolio-optimization-algo-using

A quantitative portfolio optimization script that leverages historical price data, log-normal returns, and covariance analysis to compute optimal asset allocation via Sharpe ratio maximization using the SLSQP method under bounded constraints.
https://github.com/kaift4/stock-portfolio-optimization-algo-using

data-science matplotlib portfolio-optimization python quant-finance scipy yfinance

Last synced: 17 days ago
JSON representation

A quantitative portfolio optimization script that leverages historical price data, log-normal returns, and covariance analysis to compute optimal asset allocation via Sharpe ratio maximization using the SLSQP method under bounded constraints.

Awesome Lists containing this project

README

        

#Optimal Portfolio Allocation using Modern Portfolio Theory
-This project implements a portfolio optimization algorithm based on Modern Portfolio Theory (MPT). It analyzes historical data to allocate weights across a selection of assets in a way that maximizes the Sharpe Ratio, balancing expected return against risk.

#Overview
-Assets considered: SPY, BND, GLD, QQQ, VTI
-Data source: Historical price data via yfinance

#Methodology:
-Computes log returns from adjusted closing prices
-Annualizes return and covariance to evaluate performance
-Uses Sharpe Ratio as the optimization objective
-Solves the constrained optimization using SLSQP

#Features
-Pulls 8 years of price data
-Calculates expected return, volatility, and risk
-Prevents short selling and overexposure via constraints
-Visualizes the optimal allocation using a bar chart

#Installation
-Make sure you have Python 3.x installed. Then install the required libraries:

#bash
pip install numpy pandas yfinance scipy matplotlib

#Running the Script
-bash
python app.py

---You’ll see the optimal weights printed in the console along with the expected return, volatility, and Sharpe ratio. A bar chart will also display the final portfolio allocation.

#Example Output
yaml
Optimal Weights:
SPY: 0.2010
BND: 0.2391
GLD: 0.1573
QQQ: 0.3026
VTI: 0.1000

Expected Annual Return: 0.1364
Expected Volatility: 0.1497
Sharpe Ratio: 0.7776

#Notes
-The weights are subject to constraints:
-Must sum to 1 (fully invested)
-No short positions (minimum weight = 0)
-Maximum 40% allocation to any single asset
-The risk-free rate is assumed to be 2% for Sharpe Ratio calculations
-You can modify the tickers list or adjust constraints to experiment with other asset mixes