Data Sources Overview
Historical bars for backtest: synthetic, dict, custom
The DataSource protocol is what the backtest loop iterates over. Horizon ships three built-ins and makes it trivial to add your own.
Built-in sources
SyntheticGBM Seeded geometric Brownian motion. Perfect for deterministic tests. SyntheticRegimes Programmable regime shifts (uptrend, chop, crash). DictSource In-memory bars from a plain Python dict. Custom sources CSV, parquet, Yahoo, polygon, your own.
Protocol
python
from typing import Iterator, Protocol
from horizon.data import Bar
class DataSource(Protocol):
def markets(self) -> list[str]: ...
def iter_bars(self) -> Iterator[Bar]: ...
Implementations yield Bar objects in chronological order across all markets. The backtest loop buffers bars at the same timestamp and flushes them as a single tick.
The Bar type
python
@dataclass(frozen=True)
class Bar:
market_id: str
timestamp: datetime
price: float
open: float | None = None
high: float | None = None
low: float | None = None
close: float | None = None
volume: float | None = None
bid: float | None = None
ask: float | None = None