data.synthetic¶
Deterministic seeded bars, for tests and for examples that must run without shipping a data file.
synthetic
¶
Deterministic synthetic OHLCV bars for examples and tests.
A seeded random.Random walk in INTEGER TICKS — prices are reconstructed
via from_ticks so every value is exactly on the instrument's grid and no
float ever touches a price. Bars are stamped in ET (one per
unit x unit_number step), weekends are skipped, and the same seed always
reproduces the identical bar tuple.
hours selects the span stamped for each trading day:
"rth"(default) — regular trading hours, starting 09:30 ET on the trading day itself. Covers the NY session only."globex"— the full 23-hour electronic session, starting 18:00 ET on the PREVIOUS calendar day (Sunday 18:00 for a Monday) and running to 17:00 ET. This is the mode that produces Asia and London bars, and therefore the only one against which session-scoped behaviour means anything.
Exchange holidays are NOT skipped — this package ships no holiday calendar
(see core/time.py). A synthetic tape spanning a market holiday will emit
a session that would not exist in real data.
days counts WEEKDAYS emitted: the generator scans forward from
start_day and skips Sat/Sun until days sessions exist. The weekday
test is applied to the TRADING day, so a Monday tape correctly opens on the
preceding Sunday evening under "globex".
bars_per_day is capped so the last one-minute bar closes at 17:00 ET —
450 from the 09:30 RTH open, 1380 from the 18:00 Globex open — and no
synthetic bar can ever sit inside the 17:00-18:00 ET maintenance halt.
synthetic_bars
¶
synthetic_bars(*, contract_id: str, spec: InstrumentSpec, start_day: date, days: int, seed: int, start_price: Decimal, bars_per_day: int | None = None, unit: AggregateBarUnit = MINUTE, unit_number: int = 1, drift_ticks_per_day: int = 0, vol_ticks: int = 8, hours: Hours = 'rth') -> tuple[Bar, ...]
Generate days trading sessions of consistent, on-grid OHLCV bars.
start_price must lie on spec.tick_size (raises OffGridError
otherwise) and be comfortably above zero for the chosen vol_ticks.
drift_ticks_per_day is distributed across the day's bars in exact
integer ticks; vol_ticks bounds the per-bar random move.
hours="rth" (default) stamps from 09:30 ET on the trading day and caps
bars_per_day at 450; hours="globex" stamps the full electronic
session from 18:00 ET on the PREVIOUS calendar day and caps it at 1380.
Either way the cap is the point at which a one-minute bar would close past
17:00 ET and land inside the maintenance halt. bars_per_day defaults to
a full session for the chosen mode (390 RTH, 1380 Globex).
Only "globex" emits Asia and London bars — an "rth" tape is NY-only
and cannot exercise anything session-scoped.
Source code in src/topstep_backtest/data/synthetic.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |