Group members: Tianyi Wu, Qingrui (Rachel) Li, Shiyu (Andrea) Zhao, Rebekah Wong
Welcome to our repository! Our project is an investigation into how stocks can be optimized through machine-learning based methods, namely Nested Clustered Optimization (NCO) as opposed to traditional methods like Mean Variance Optimization (MVO).
Please ensure that all required libraries are listed in the requirements.txt file located in the NCO folder so that the scripts can run correctly.
Although we do not use the MVO methods as our website demo, you can still run them locally and view the results in the terminal. If you want to see those results, enter the following commands:
cd path/to/CMPT733-Portfolio-optimization
python3(python) -m algorithms.MVO.MVOPortfolioOptimizer
Note that we have included some example stocks in both MVO and NCO, which you can replace with others if you prefer.
Please follow the web frontend instruction below to optimize your portfolio using NCO!
Within the Testing folder, you will find several test scripts designed to compare MVO and NCO performance under different simulated scenarios:
- regular_market.py: Regular market conditions
- test1.py: High correlation
- test2.py: High volatility
- test3.py: Negative returns
- test4.py: Combined worst-case scenarios
- test5.py: Sector-specific breakdowns (e.g., technology)
Then, enter the following commands to redo the test:
cd algorithms
cd Testing
python3(python) -m algorithms.Testing.regular_market
python3(python) -m algorithms.Testing.test1
python3(python) -m algorithms.Testing.test2
python3(python) -m algorithms.Testing.test3
python3(python) -m algorithms.Testing.test4
python3(python) -m algorithms.Testing.test5
We have also built a website hosted locally that takes in tickers from a dropdown (S&P 500) or any other ticker that the yfinance library supports, with proper error checking to ensure that all inputs are valid.
To run the website, make sure that you have the following libraries installed:
- datetime
- dateutil
- matplotlib
- nicegui
- numpy
- pandas
- pickle
- yfinance
Then, enter the following commands:
cd website
python3 main.py
The local website can then be accessed through http://localhost:8080, or whichever link is shown in the terminal.