Online Portfolio Selection (OLPS) algorithms and benchmarks, implemented following Online Portfolio Selection: Principles and Algorithms (Li & Hoi).
data.py— downloads adjusted close prices (viayfinance) and converts them into price relativesx[t,i] = price[t,i] / price[t-1,i].strategies/base.py—Strategy, the abstract base class all algorithms implement (Algorithm A.1). Strategies are stateless:update(history)is a pure function of the price-relative history up tot-1and returns the portfoliob_t.strategies/bah.py— Buy-and-Hold (Chapter 3.1): invests once att=1and never rebalances, so its weights drift with relative asset performance.
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txtfrom data import get_price_relatives
from strategies.bah import BAH
price_relatives = get_price_relatives(
tickers=["AAPL", "MSFT"], start="2023-01-01", end="2024-01-01"
)
strategy = BAH(n_assets=price_relatives.shape[1])
b_t = strategy.get_portfolio(price_relatives.values[:10])Early stage — data pipeline and BAH strategy in place. More OLPS algorithms (CRP, UP, EG, ONS, ...) to follow.