This repository is a modernized version of the popular Algorithmic Trading Course by freeCodeCamp.org.
What's new?
- Replaced deprecated IEX Cloud API with yfinance
- Optimized data fetching using multithreading
- Added portfolio optimization and backtesting for momentum- and value-based strategies
This project covers and enhances the three original strategy modules:
Equal-weight S&P 500 index fund
- Replicates an S&P 500 ETF by equally weighting all constituents
- Automatically rebalances the portfolio using live price data
Quantitative momentum strategy (Extended)
- Ranks S&P 500 stocks based on their 12-month price performance
- Selects top performers to construct a momentum-based portfolio
- Includes a full backtest comparing performance vs. SPY
Quantitative value strategy (Extended)
- Identifies undervalued stocks using multiple valuation metrics:
- Price-to-Earnings (P/E)
- Price-to-Book (P/B)
- Price-to-Sales (P/S)
- EV/EBITDA
- EV/Gross Profit
- Computes a composite score using percentiles of valuation metrics
- Applies mean-variance optimization to construct a long-only portfolio
- Includes a full backtest comparing performance vs. SPY
Each project generates an Excel file containing the recommended trades based on the strategy logic.
This project uses uv
, a superfast Python package manager to setup the environment.
Install uv
Download and install:
curl -Ls https://astral.sh/uv/install.sh | sh
Initialize the environment
Inside the directory run:
uv init .
and you're ready to go.
Start Jupyter Lab
Run
uv run --with jupyter jupyter lab
to start the server at http://localhost:8888/lab.
Alternatively, to use in VS Code, create a Jupyter kernel:
uv add --dev ipykernel
Inside the VS Code hit Ctrl+Shift+P
→ Python: Select Interpreter
→ choose .venv
(created by uv).
Main libraries used:
yfinance
for financial datapandas
,numpy
,scipy
for data analysiscvxpy
for portfolio optimizationmatplotlib
,seaborn
for visualizationconcurrent.futures
for multithreading
- Original tutorial by freeCodeCamp.org
- Edited by Ante Kapetanović