algo-trading-bot

A rules-based ETF rotation strategy, implemented as a tested Python package with a realistic backtester. Each day it reads two bond-market signals, picks one of three portfolios, and holds it until the signals change: 3× leveraged equity funds when bonds (AGG) beat cash (BIL) over 60 days, half UUP (US dollar) and half QID or TBF when long bonds (TLT) trail cash over 20 days, and an equal split of UGL, TMF, BTAL and XLP otherwise. This console shows every decision, run and backtest. Paper trading only; nothing here is investment advice.

Every weekday at 09:35 New York time a GitHub Actions job decides on the latest completed day and trades the difference on an Alpaca paper account. The backtest and the live runner call the same pure strategy function, which returns target weights plus the reasoning behind them, so live and backtest decisions on the same day match. Client order IDs are built from the day, fund and side, so a rerun cannot trade twice.

Backtested daily from January 2013 to October 2026 at 5 bps per dollar traded, with 2023 onward held out as an out-of-sample test fixed before any backtest ran. The Sharpe ratio falls from 1.15 in 2013–2022 to 0.39 in 2023–2026, well below holding SPY (1.12) over the holdout: the in-sample result does not hold up.

Stack: Python 3.12, uv, FastAPI and pydantic, Alpaca, Yahoo Finance with a Parquet cache, React, TypeScript and Vite, GitHub Actions and GitHub Pages.