How johnbrick123/sp500-data works
This repository builds a point-in-time S&P 500 and ETF historical dataset, then provides a backtesting library that consumes it. The data workflow covers universe and membership construction, price collection and recovery, adjustment, verification, and local or hosted database loading. In the backtesting workflow, a user runs a strategy through the engine, which uses aligned market data and indicators to produce results and reports. The README documents the dataset stages; sampled source shows the backtester’s internal links. Other recovery and collection links are omitted where their callers were not shown.
Main entry points: engine.py Backtest engine · fetch_perma.py Tiingo recovery · momentum_with_stops.py Trading strategy · data.py Market panels
Components 20
Universe and membership
- Build universe
build_universe.py - Bridge membership
bridge_membership.py - Membership history
build_universe.py
Price collection
- Fetch prices
fetch_prices.py - CRSP data
fetch_crsp.py - WIKI recovery
fetch_wiki.py - Tiingo recovery
fetch_perma.py - Name-based recovery
fetch_perma_names.py - Split salvage
salvage_split.py
Adjustment and release
- Compute adjustments
compute_adjusted.py - Verify dataset
verify.py - Historical dataset
- DuckDB loading
build_db.py - MotherDuck loading
load_motherduck.py
Backtesting
- Trading strategy
strategies/momentum_with_stops.py - Backtest engine
qbt/engine.py - Market panels
qbt/data.py - Indicators
qbt/indicators.py - Results and reports
qbt/report.py
Other components
- Backtest user
Connections 18
- Build universe → Membership history: builds
- Bridge membership → Membership history: extends history
- Fetch prices → Historical dataset: collects prices
- CRSP data → Historical dataset: provides history
- WIKI recovery → Historical dataset: recovers prices
fetch_wiki.py - Tiingo recovery → Historical dataset: recovers members
- Name-based recovery → Tiingo recovery: reuses helpers
fetch_perma_names.py - Split salvage → Historical dataset: repairs splits
- Compute adjustments → Historical dataset: derives adjusted prices
- Verify dataset → Historical dataset: checks quality
- Historical dataset → DuckDB loading: loads locally
- Historical dataset → MotherDuck loading: loads remotely
- Backtest user → Trading strategy: chooses
- Trading strategy → Backtest engine: implements callbacks
strategies/momentum_with_stops.py - Backtest engine → Market panels: loads market data
qbt/engine.py - Market panels → Historical dataset: reads release files
qbt/data.py - Backtest engine → Indicators: uses indicators
qbt/engine.py - Backtest engine → Results and reports: computes results
qbt/engine.py