The project computes optimal portfolio weight distributions based on the maximum Sharpe ratio, using historical stock price data.
It allows users to to input a set of stock tickers and compares two different optimization approaches for portfolio construction.
The Sharpe ratio is used to measure return per unit of risk relative to a risk-free investment.
You can learn more about Sharpe ratio here.
- Long and short selling is allowed.
- Risk-free rate is not accounted for (= 0).
- Long-only portfolio (weights constrained to [0, 1]).
- Risk-free rate is inputted by the user (currently not possible).
- Optimized using Sequencial Least Squares Programming (SLSQP).
- The user inputs stock tickers to include in the optimised portfolio.
- Monthly returns are calculated using downloaded historical price data (2020-01-01 to 2025-12-31).
- Both optimization approaches are computed and generate portfolio weights.
If you want to try out the source code yourself, create a virtual environment and download the required libraries listed in requirements.txt:
python -m venv .venv
pip install -r requirements.txt
And run the code:
python3 PortfolioGen.py
-
The Sharpe ratio is calculated only using historical returns data and does not predict future market performance.
-
This tool does not attempt to predict price movements, but rather evaluate how well past returns compensated for risk.
This project is for educational and analytical purposes only. It is not financial advice and should not be used as the sole basis for investment decisions.
- Add Treynor ratio for comparison between Sharpe.