tearsheet¶
report.to_html() / report.show(): the interactive tearsheet — one self-contained HTML file with the tape, every fill marked, the equity curve against the MLL floor, and the text render's stats.
tearsheet
¶
Interactive HTML tearsheet: the text report, plus the charts it cannot print.
:func:render_html turns a finished :class:~topstep_backtest.harness.Report
into ONE self-contained HTML document — candlestick price panes with entry/exit
markers, the equity curve with the trailing MLL floor and the intrabar equity
envelope, a daily P&L histogram, an R-multiple distribution, and every stats
section the text render prints, label for label. The file needs no server, no
CDN and no network: the charting library (TradingView Lightweight Charts™,
Apache-2.0, vendored under _assets/ with its license) and all styling are
inlined, so the document opens offline and can be archived next to a run.
The render is a pure function of the frozen report data. No wall clock, no
unordered iteration: rendering the same Report twice yields byte-identical
HTML, the same contract str(report) keeps. The provenance line every text
report carries is stamped on the page footer for the same reason — a chart gets
screenshotted out of context even more readily than a verdict line.
This module is where Decimal leaves the money path. Everything shown in
a stats tile is formatted in Python by the exact helpers Report.__str__
uses, so gross/net basis labels cannot drift from the text render; only chart
series cross to the JavaScript side as raw decimal strings, converted to floats
by the chart layer at the last possible moment (floats are a display concern
here, never an accounting one).
Two tabs, one payload. Results is the finished run — the tape, equity
against the floor, daily P&L, the R histogram, the stat cards. Replay appears
only when the report carries a recording and holds the bar-by-bar cockpit: its
own charts (veiled after the cursor, so nothing past the strategy's knowledge is
drawn) beside the settled state and the running stats — regrouped into by-type
cards (_REPLAY_CARDS), shown one at a time behind filter chips — with the
event log across the full width beneath, laid out to be read in one viewport
instead of scrolled between. Its charts are separate from
the results tab's on purpose — a veiled chart is a run mid-flight, and the
results sheet is the run that finished.
Reached via :meth:Report.to_html(path) <topstep_backtest.harness.Report.to_html>
(writes the named file, the only disk write) or
:meth:Report.show() <topstep_backtest.harness.Report.show> (temp file +
default browser, the write is documented there).
SCHEMA_VERSION
module-attribute
¶
Version of the embedded JSON payload contract (bumped on breaking changes).
ReplaySpec
module-attribute
¶
How much of a recording the tearsheet embeds — see Report.to_html.
REPLAY_AUTO_FRAME_LIMIT
module-attribute
¶
Frames replay="auto" will embed before falling back to a window.
Payload weight is roughly linear in frames (indicator strings dominate), and
past this many the document crosses from "large" to "hostile to browsers".
"full" overrides deliberately; the auto window centres on the MLL breach
when there is one — the moment worth stepping through — and otherwise takes
the tail.
render_sweep_html
¶
render_sweep_html(sweep: WindowSweep | SpacedSweep) -> str
Render a sweep as one self-contained HTML document.
Pure function of the frozen sweep data: rendering twice is byte-identical. Everything — styling, charts, the interaction script — is inlined; the document opens offline and can be archived next to a run.
Source code in src/topstep_backtest/tearsheet/sweep.py
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | |
render_html
¶
render_html(report: Report, *, replay: ReplaySpec = 'auto', confidence: MonteCarloConfidence | None = None, crosscheck: CrossCheck | None = None) -> str
Render report as one self-contained interactive HTML document.
Pure function of the frozen inputs: rendering twice is byte-identical.
The returned string embeds the payload JSON, the vendored charting library
and all styling — nothing is fetched at view time. replay selects how
much of a recording is embedded (see Report.to_html); it is inert when
the report carries none.
confidence (a :func:~topstep_backtest.metrics.confidence.mc_confidence
bundle) adds the Monte-Carlo cards — estimate with its CI, block-length
sensitivity, per-year strata; crosscheck
(:func:~topstep_backtest.metrics.confidence.crosscheck) adds the
bootstrap-vs-real-windows card. Both are computed by the caller, never
here: a render must stay a pure formatting pass, and the simulations they
involve are neither cheap nor this module's business.
Source code in src/topstep_backtest/tearsheet/__init__.py
1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 | |