import type { Diagnostic } from '../diagnostics/index.js'; import type { CompiledProgram } from '../emit/index.js'; import type { Drawing, Grid, Instrument, RequestProvider, Value } from '../engine/index.js'; import type { RecordedBar, RecordedFrame, RunRecord } from './record.js'; import type { LogLine } from './walk.js'; import type { BacktestSettings } from './settings.js'; /** What a run came to, or why it could not be carried out at all. */ export type BacktestResult = { readonly ok: true; readonly record: RunRecord; readonly rows?: readonly (readonly Value[])[]; readonly log?: readonly LogLine[]; readonly surface?: Surface; } | { readonly ok: false; readonly diagnostic: Diagnostic; }; /** The drawing objects and the grids the last bar left, `conformance.md` section 4. */ export interface Surface { readonly drawings: readonly Drawing[]; readonly tables: readonly Grid[]; } /** * The facts of `host-interface.md` 4.1 that the contract does not hold. * * The contract already states six of the twelve, the ones the money is priced * under, and a fact stated in two places is a fact that can disagree with * itself: a tick size the engine rounds to and a different one the venue * worsens a fill by is a run under two instruments. So the other six are * stated here and the six the contract holds cannot be, which the compiler * enforces rather than a check at run time. */ export type InstrumentFacts = Omit; /** The few choices a driver has that are not settings of the run itself. */ export interface DriveOptions { /** Whether the bars travel in the record. Inline is the conformance form. */ readonly form?: 'inline' | 'referenced'; /** * What the host states about the instrument beside the contract, so the * record it produces is a conformance case. * * A case holds `instrument.json`, which `conformance.md` section 2 says is * the record of `host-interface.md` 4.1, and that page requires one fact of * every host: `hasVolume`, because no derivation recovers it (4.2). The * engine reads the record and does not refuse a run without it, so a caller * that leaves this out gets a record that replays and reruns like any other * and cannot become a case, exactly as one without `sourceText` cannot. * * A session stated without a timezone is refused at load, OS6012, by the * same rule that refuses it for any host. */ readonly instrument?: InstrumentFacts; /** * The script's own text, so the record it produces is a conformance case. * * A compiled program identifies its source and cannot reproduce it, and a * case has to hold `script.os`. A caller holding only a program leaves this * out and gets a record that replays and reruns like any other; the one * thing it cannot do is be handed to somebody else's engine as a case. * * It is checked against the program's own source hash, so text from a * different revision than the one that was compiled is refused rather than * written into a case that could never make its own expected output. */ readonly sourceText?: string; /** * Whether to hand back every channel's value on every bar that ran, beside * the record rather than inside it. * * A conformance case that asserts `values` compares one value per bar per * plot, and the record holds none of them: it is the reproducible run, and a * curve per plot is bytes it would carry for every run to serve the few cases * that ask. So the rows are asked for, and a run that does not ask pays * nothing. A bar that failed has no row, as in the second engine. */ readonly rows?: boolean; /** Whether to hand back every line `print` wrote, beside the record, for the same reason. */ readonly log?: boolean; /** Whether to hand back the drawing objects and grids the last bar left, for the same reason. */ readonly surface?: boolean; /** * Bars for another instrument, `host-interface.md` 5, for a run whose host * serves them. * * Left out, the run holds the chart's own bars and nothing else: a read of * the chart's instrument at a coarser interval is folded from them, and a * program that reads another instrument declares a capability this host does * not have and is refused at load by name. Given, the host serves duty 3 and * the engine asks it once per read, before bar 0. */ readonly requestBars?: RequestProvider; } /** * One run against a simulated destination, from a compiled program to a record. * * The frames are the destination's own: it is handed the orders, it reads the * bars, and what it answers is what the engine folds. A run whose frames * somebody else is supplying is `backtestSupplied` below. */ export declare function backtest(program: CompiledProgram, bars: readonly RecordedBar[], settings: BacktestSettings, options?: DriveOptions): BacktestResult; /** * One run over the frames somebody else supplied, which this engine does not * choose and does not add to. * * `conformance.md` section 3 gives a case a `frames.csv` that supplies order * frames the way `bars.csv` supplies bars, so that a case asserts the fold * against input the engine did not choose. Every other argument is `backtest`'s * and means there what it means here. A row is delivered at the boundary it * names and folded before the next bar, and the record carries the rows it was * handed rather than a second spelling of them. * * **Nothing is invented.** No fill is priced off a bar, no order rests and no * schedule is read, so an order the frames say nothing about stays where its * placement left it, which is what a case saying nothing about it means. * * **A record made here is a record of this run and not of a simulated one.** * `rerun` puts a record's program back on a simulated destination, because a * record does not say which of the two answered it, so a rerun of one of these * reproduces it only where that destination would answer these same frames. */ export declare function backtestSupplied(program: CompiledProgram, bars: readonly RecordedBar[], settings: BacktestSettings, frames: readonly RecordedFrame[], options?: DriveOptions): BacktestResult; //# sourceMappingURL=drive.d.ts.map