The export file
Specified (GLE-664); written by algo export (GLE-668) and by algo run --export as the set runs (GLE-672); read back by algo report (GLE-676). A run set’s export is one self-contained SQLite file, NAME.algorun. It holds the runs, the bars every run saw, each run’s per-bar equity, trades, fills, the trade director’s log, rolls, instruments, calendars and the metrics Go computed. It is the source of truth for both algo report and AlgoChart, which opens it in a run tab. This chapter is the specification of version 1, algolang.export/1. Both repositories check against it.
What exists today:
- the specification itself, this chapter;
- the package
engine/algorun, which holds:- the canonical schema,
schema.sql; - the chunk codec,
EncodeBars,DecodeBars,EncodeEquityandDecodeEquity; Check, which validates a file against this chapter;- the writer,
Writer(Writing a file); - the reader,
Read(Reading it back);
- the canonical schema,
algo run … --export out.algorun, orreport.exportin a config, which writes the file as the set runs, from the bars each run delivered (Writing the export as the set runs);algo export RESULTS_DIR -o out.algorun, which converts a results folder (Converting a results folder);algo report out.algorun, which reads it back and prints the reports (Reading saved results again);- a hand-made reference file,
testdata/algorun/reference.algorun, the same file as it was first written,reference-first.algorun, three files converted from the design’s runs, and the subset and side goldens, which algochart vendors (The reference file).
The writer uses the pure-Go modernc.org/sqlite, so the engine still builds with CGO_ENABLED=0. AlgoChart reads the file through the system SQLite3 module.
Opening a file
Any SQLite reader opens the file: the sqlite3 shell, Python’s sqlite3 module, DuckDB. The bulky columns, bars and per-bar equity, sit in compressed chunk BLOBs (Chunks). Everything else is plain rows, and JSON text where algolang already has a JSON form:
sqlite3 -readonly testdata/algorun/reference.algorun \
"SELECT key, value FROM meta WHERE key IN ('format', 'set_name');
SELECT ordinal, run_id, status, name FROM runs ORDER BY ordinal;"format|algolang.export/1
set_name|Reference set
1|sma-es-fast-5-slow-20|ok|SMA ES Fast=5 Slow=20
2|sma-es-fast-20-slow-20|failed|SMA ES Fast=20 Slow=20
3|es-nq-spread|ok|ES/NQ spreadWriting the export as the set runs
algo run --export FILE writes the run set to one export as it runs (GLE-672). It works for a single run and with --config. In a config, the global report object’s export names the file, and the flag outranks it:
bin/algo run --config sweep.json --export sweep.algorun"report": {"equity-sampling": "bar", "export": "sweep.algorun"}The results folder is a separate choice. --results-dir writes the same folder, byte for byte, with --export or without it, and an export needs no folder.
What it holds. What algo export would make of the set’s results folder, taken from the runs as they ran rather than from their files:
- The bars each run delivered to its strategy, exactly as received. Each series’ own warm-up bars come first, flagged
warmup, then the main loop’s bars. A continuous series’ bars are in the strategy’s frame, with their dated contract and seam flags. The reach-back batches of the aligned views are not a series’ bars and are not stored. Every series hasbars_source = 'run'. - A series several runs read is stored once. Runs read the same series when they share its key: the adapter and its inputs, the symbol, interval, session and clock, the run’s window, and a continuous series’ snapshot. A later run shares the first stored copy that reaches back to its own first bar. A run whose warm-up reaches further back stores its own copy, so every run’s bars are exactly the ones it saw: a sweep over
Slowstores a copy for each value ofSlow. - Every run’s equity at every bar, in
equity_chunks, whateverreport.equity-samplingsays; that setting still governsequity.csv.meta.equity_samplingisbar. - Every fill, whether or not
report.fillsis on. A set that exports may therefore setreport.fillswithout a results folder. - The rest of each run: its trades, with their orders’ names and labels and their bar anchors; its combo trades; its trade director’s log; its rolls, instruments, calendars and benchmarks; and its metrics as Go computed them. Then the portfolio of the set’s finished runs, and in
metathe config as given, comments stripped (config_json), its path (config_path), the file’s name without.algorun(set_name) and the build (build_id). - Features:
per-bar-equity,fills,series-descriptors,sweeps,order-namesandbar-anchors, each declared asalgo exportdeclares it (Features).
A run exported this way matches algo export of its results folder table by table, its bars included, but for series.bars_source; the tests check it end to end. Across a set the two differ in one more way: algo export fetches a shared series once, from the earliest warm-up start of the runs that read it, where the native export keeps the copies described above.
The file appears at the set’s end. The writer works in a temporary file beside the target (Writing an export). Once the set has ended, it commits, validates the file with Check and renames it into place, and stderr gives its size and the set’s time:
algo: exported sweep.algorun (31.0 MB) in 7m47.629s
A set that stopped at a failed run leaves no file. A set that exports keeps going past a failed run unless report.keep-going is false (When a run of a set fails), and the file keeps each run that failed as a failed run: a runs row with its error, inputs, sweep and config entry, and nothing else of it. So the design’s 63-combination smacross sweep on ES 1d, ten of whose combinations the strategy refuses (Fast (10) must be less than Slow (10)), completes in one go: 63 runs, 10 failed. A single run without a config has no report.keep-going, so a single run that fails leaves no file.
Memory. Each run’s bars are spooled, as they arrive, to temporary files in the system’s temporary directory, one for each series, and streamed into the export when the run ends, one bar at a time. No series is held in memory. A failed run’s spooled bars are discarded.
The trade director. A directed run that exports with no results folder and no --director-log keeps its decision log in a temporary file, which the export reads and then removes (Where the log is written). The export holds the records, as its director rows, and Check holds them to the summary’s count and SHA-256. The run’s director_summary_json names no log file, and its printed summary says log in the export.
Refusals. The export records backtests’ performance, so a run that would record nothing for it is refused before it starts: a live run, a --schema TRADES run and a run with its report off:
algo: engine: --export is a backtest export (a live run's record is its venue ledger)
algo: engine: --export needs a strategy run (schema BARS, not TRADES)
algo: engine: --export needs the performance report (report on)
Converting a results folder
algo export converts a results folder that algo run --results-dir wrote into one export:
bin/algo export results/sample -o sample.algorun
bin/algo export results/sweep --partial -o sweep.algorun --name "SMA ES sweep"| Flag | Meaning |
|---|---|
-o FILE | The export to write (required). It appears only once complete: the writer works in a temporary file beside it and renames it into place. |
--partial | Convert every run folder that holds a result.json, without index.json, as algo report --partial reads a set a failed run stopped. |
--adapter PATH | Fetch the bars through this adapter instead of the one each run recorded (a path, or a name in the adapter directory). |
--name NAME | The set’s name, meta.set_name; the results folder’s name by default. |
--page-size N | The SQLite page size; 65536 by default. |
What it reads. Each run’s result.json (its header, metrics, trades and combo trades), equity.csv, fills.json, plots.json, degradation.json, its trade director’s log, and the manifests and audit logs of its continuous series; and the set’s portfolio/result.json. A run’s benchmark curve goes into its equity only when its primary benchmark held something, as equity.csv has a benchmark column only then, so a run’s export is the same converted or written as it ran.
Failed runs are kept. A row of index.json with "Status": "failed", a run the set kept going past (When a run of a set fails), becomes a failed run with the index’s name, error, strategy, capital, config entry, sweep and template. The index does not record a failed run’s inputs, so its inputs_json is {}; the native export records them.
The bars are fetched again. A results folder holds no bars, so each series is fetched through the run’s adapter, by the run’s own fetch path: a continuous series is built from the feed’s served composite and adjusted at the run’s end, the instant its snapshot was taken at. Its snapshot_json records the token the feed served; when that differs from the token in the run’s manifest, algo export says so, because the archive has moved since the run and the bars may not be the ones the strategy saw. Every series is marked bars_source = 'refetched'. A series several runs read over one window is fetched and stored once.
Described results. A run since GLE-665 records each series’ descriptor and where in its config it came from (Artefact formats). When every run of the folder does, algo export takes from them:
series.label,session,boundaryandclock. A series is fetched from its trading-day session or on its intraday grid, on its continuous clock;snapshot_json’sat, and the token it compares with the feed’s;run_series.role,declaredandname;- the warm-up. A series is fetched from the earliest warm-up start of the runs that read it, as the run built it: a plain series’ warm-up is the bars of a read from that start that close before the run’s first bar, a continuous series’ is its composite read again from that start. Those bars carry the
warmupflag. Each run’swarmup_startis the series’ bar at or after the start it recorded, the first such bar the archive holds now; runs.config_entry,sweep_jsonandtemplate_json.
meta.features then names series-descriptors and sweeps.
Bar anchors. A run since GLE-669 records each fill’s bar and each trade’s entry and exit bars (Artefact formats). When the folder is described, a fill takes series_id and bar_ts from its series and bar, and a trade series_id, entry_bar_ts and exit_bar_ts from its entry’s series: the export keeps one series a trade, so an exit filled in another series of the symbol is anchored on the entry series’ bar before its stamp. An anchor the archive no longer holds falls back to the latest bar before the stamp. meta.features names bar-anchors when every trade and every fill on a bar resolves.
Order names. A run since GLE-666 records each trade’s orders (Artefact formats). Such a trade gives its row entry_client_id, entry_attempt, entry_name, entry_type, exit_client_id, exit_attempt, exit_name, exit_type and exit_kind from the trade itself. An open trade’s end_of_data is not written: its exit_kind stays NULL, since an open trade has no exit (trades), and so do its other exit_ columns. A fill’s name is its order’s name from fills.json, NULL for an unnamed order, and its order_type is the order type of the trade the fill enters or exits, NULL for a fill no trade links. A trade is linked to the fills it entered and exited by, where fills.json has them. meta.features names order-names when every trade of every run carries its orders. A trade recorded before GLE-666 keeps what the converter gave it before: the labels and attempts of the fills linked to it, the exit fill’s kind as its exit_kind, and no names or types.
What older results lack stays out, and meta.features says so. A folder with one such run is converted as older results throughout:
- warm-up bars: the run’s warm-up start is not recorded, so only the run’s window is fetched and no bar is flagged warm-up;
- a series’ trading-day session or intraday grid boundary: such a series is fetched on the plain clock;
- the series descriptors (
series-descriptorsis absent): a series’ role is inferred,tradedfor the run’s first series and for any series its trades are keyed on,referenceotherwise, and its label isSYMBOL@INTERVAL; - sweep metadata (
sweepsis absent): the sweep stays in the run names’Name=valuesuffixes; - bar anchors (
bar-anchorsis absent): a trade’sseries_idis the first series of its key, and no anchor is set; - a benchmark’s weights: its
spec_jsonholds the name, kind and primary flag the result records; - a run’s director configuration (
director_config_json), which the results record only as a hash.
per-bar-equity is present when every run sampled its equity at every bar (report.equity-sampling: "bar"); otherwise equity_daily holds the daily curve. fills is present when every run wrote fills.json.
Writing an export
algorun.Writer writes an export in Go. algo export and the native export of algo run --export both use it, through one converter core, engine/algorun/convert (GLE-672).
w, err := algorun.Create("out.algorun", algorun.Options{})
// w.SetMeta, w.AddRun, w.AddSeries, w.AddRunSeries, w.AddFill, w.AddTrade, ...
bars, err := w.Bars(seriesID) // bars.Append(algorun.Bar{...}) per bar
curve, err := w.Equity(runID) // curve.Append(algorun.Mark{...}) per mark
err = w.Commit() // or w.Abort()
- One transaction in a temporary file.
Createmakes.out.algorun.tmp-*beside the target, sets the identity pragmas and the page size (64 KiB by default), and opens one transaction. Nothing exists at the target untilCommit. - Streams. A
BarStreamorEquityStreamholds at most one chunk: every 8,192 rows it encodes and inserts a chunk, so a series is never held whole in memory. A bar stream keeps the series’ contract dictionary and counters. An equity stream also writesequity_daily, the last mark of each UTC date, once a date of the curve has held two marks; it holds the rows until then, and writes none for a curve with at most one mark a date, whose chunks are its daily marks (GLE-672). - Failure is final. A call that returns an error, a refused value as much as a database error, fails the writer: every later call returns an error wrapping the first, and
Commitaborts. - Commit. It closes the streams still open, supplies the meta defaults (
created_at,accounts = separate,features = []), writescomplete = 1last, commits, runsVACUUM, syncs the file, validates it withCheckand renames it into place. A file that failsCheckis removed and the error returned.
Identity and versions
A file identifies itself three ways, and a reader checks all three before it reads anything else:
| Where | Value |
|---|---|
PRAGMA application_id | 0x414C474F (1095519055), “ALGO” in ASCII |
PRAGMA user_version | 1, the format’s version |
meta.format | algolang.export/1 |
Finished files only. A writer writes the whole file under a temporary name, in one transaction, and renames it into place, as algolang writes its other artefacts. meta.complete = 1 is the last row it writes. A reader refuses a file without it as incomplete.
Evolution. Within version 1, tables, columns, indexes, meta keys, features and bar flags are only ever added, and a reader ignores what it does not know. The values of an enumerated column (runs.status, fills.kind, …) are fixed: a new value is a change of meaning. A change of meaning, whether a column’s unit, a value’s sense or a chunk’s layout, bumps the version, and a reader refuses a version it does not know.
Later additions are optional. A file written before an addition lacks it and is still a version 1 file (GLE-737). The additions so far:
| Addition | Since | A file without it |
|---|---|---|
trades.entry_place and exit_place | GLE-676 | Its trades have no places in their bars. |
plots and annotations, with their indexes | GLE-677 | Its runs have no plots, and it does not list the plots feature. |
books | GLE-1354 | Its runs have no books, and it does not list the books feature. |
slices and slice_chunks | GLE-1354 | It holds no slices, and it does not list the slices feature. |
intraday | GLE-1358 | Its runs have no bar marks, and it does not list the intraday feature. |
position_cost | GLE-1403 | Its runs have no position cost, and it does not list the position-cost feature. |
Checkaccepts a file without an addition, and without the indexes and foreign keys on it. Where the addition is there,Checkvalidates it like the rest of the schema. A file that listsplotsmust have both tables.- A reader gates each addition. It reads
plotsandannotationsonly whenmeta.featureslistsplots,booksonly when it listsbooks,intradayonly when it listsintraday,position_costonly when it listsposition-cost, andsliceswithslice_chunksonly when it listsslices. It reads a trade’s places only whentradeshas the columns (pragma_table_info), and leaves them empty otherwise. engine/algorunlists the additions besideschema.sql, inschema.go. A test fails whenschema.sqlgains a table, column, index or foreign key that the list does not cover:Checkwould then refuse every file written before it. The first file of version 1 is kept, so the test has a file without any addition (The reference file).
One rule changed what a writer writes without changing its meaning. Since GLE-672 a run whose curve has at most one mark a UTC date has no equity_daily rows. A file written before that has a row for each of the run’s marks, which is the same curve. Check accepts those rows only when they are the curve’s marks (equity_daily).
Conventions
- Times are
INTEGERnanoseconds since the Unix epoch, UTC: Go’sUnixNano, good until the year 2262. Dates (equity_daily.date) areTEXTYYYY-MM-DDin UTC. - Booleans are
INTEGER0 or 1. - JSON columns end in
_jsonand hold UTF-8 JSON text. Where the value is an algolang type, its JSON is the type’s, with Go field names and RFC 3339 times, exactly asresult.jsonwrites it:header_jsonis areport.ResultHeader,metrics_jsonareport.Metrics. - Ordinals (
n,seq,ordinal) count from 1, without gaps, in the order the source gives. Chunk indexes count from 0. - NULL means absent or unknown, never zero. A row never stores NaN. Only the chunks’
benchmarkcolumn does. - Money is in the run’s base currency, and prices are in points of the instrument, unless a column says otherwise.
Bar open and bar close
A bar has two instants: t, its open (the wire’s ts_open), and tc, its close (ts_close).
- The close is the bar’s instant in the engine. A bar belongs to a run when
start <= tc < end. The strategy decides attc, and each equity mark is stamped with the close of the bar it follows. - The open is the bar’s key in a chart. Bars are stored in
torder, chunks are indexed ont, and a bar anchor names its bar byt. That is the time a chart draws the bar at.
The instants are those the engine delivered:
- a grid bar’s
tis its grid position and itstcthe nominal end (Intraday grids); - a session bar’s
tandtcare its first and last constituents (Session bars); - a release-stamped bar opens at the previous release (Release-stamped series).
A bar delivered without an open time is stored with t = tc, flagged no_open. Within a series t never decreases. For time bars it strictly increases; activity bars may share a t.
Fill stamps and bar anchors
A fill’s ts is its stamp as the simulator wrote it:
- a fill inside a bar is stamped with that bar’s close: a market order decided at bar N fills at bar N+1’s open price, stamped with N+1’s close;
- a market-on-close order carries the close of the bar it filled in, the bar covering its send time;
- a roll’s legs carry the cut;
- a tick fill carries its print’s time.
A bar anchor, fills.bar_ts and trades.entry_bar_ts/exit_bar_ts, is the t of the bar of the row’s series the fill happened in, as the engine records it (GLE-669): the bar a fill inside a bar was stamped with the close of, a tick fill’s bar, and for a roll’s legs the outgoing contract’s last bar. Where the engine did not record it, or the bar is no longer in the series (a re-fetched series whose archive moved), it is the t of the latest bar of the series whose t is strictly before the stamp, which is the same bar for every stamp above but a print at a bar’s very open. Where activity bars share that t, the anchor is the last of them. Anchors are the chart’s own bar times, so a reader draws a trade without snapping it to a bar.
Adjusted and raw prices
Bars are stored as the strategy received them. Fills keep the venue’s price beside the strategy’s:
| Series | Bars (o h l c) | fills.price | fills.raw_price | Trade prices |
|---|---|---|---|---|
| Plain (dated contract, raw equity, other) | venue prices | venue | venue | venue |
| Continuous future | adjusted on the run’s snapshot (adjusted = 1) | adjusted | venue (the dated contract’s) | adjusted (trades_adjusted = 1) |
Equity adj=split or adj=splitdiv | adjusted view (adjusted = 1) | adjusted | venue | venue (trades_adjusted = 0) |
- The two columns on
seriessay which case applies.adjustedsays the bars are an adjusted view.trades_adjustedsays the trade prices are in that view too. - Trade prices are the report’s.
trades.entry_priceandexit_priceare whattrades.csvandresult.jsonhold. The report records an adjusted equity at its raw projection (Equity qualifiers). - On an adjusted equity, mark a trade at its fills. A reader that marks trades on the chart takes
fills.price(throughentry_fillandexit_fill) whentrades_adjusted = 0andadjusted = 1. - Rolls are in raw prices. A continuous series’
rollshold the outgoing and incoming contracts’ raw prices at each cut, the gap and the cumulative adjustment. - The snapshot pins the adjustment.
snapshot_jsonholdsat, theas_ofinstant the adjustment was taken at (the run’s end),anchor, the contract the snapshot holds, andtoken, the feed’s snapshot token when it served one. A re-fetch of the series pins to it.
Warm-up
- Warm-up bars are the history before the first bar the strategy decided on. The engine delivers them in a batch, with no
OnBar(see Lookback and the Series API). They carry thewarmupflag. - They come first. They are a prefix of the series, and
series.warmup_countcounts them. - Nothing is recorded during warm-up. Equity, trades and fills begin with the first loop bar.
- Runs can share a series. A series row is one distinct delivery: the same descriptor, the same snapshot and the same loop bars. Runs that received the same loop bars share the row, as the members of a sweep do. Each run’s own warm-up then starts at
run_series.warmup_start. Runs over different windows get different rows. - How deep a shared series goes depends on the writer.
algo exportfetches the series once, holding the deepest history any of its runs read. A native export stores what each run delivered, so a run shares a stored row only when the row reaches back to the run’s first bar; a run whose warm-up reaches further back, a longerSlowin a sweep, stores its own row (Writing the export as the set runs).
Sweeps and config entries
A run records where it came from in its config:
config_entryis the path of the entry it expanded from:runs[0], orstrategies[1].runs[2]inside a batch.sweep_jsonholds the inputs the expansion swept and the values this run took, as the config gave them, so{"Fast":5,"Slow":20}keeps its numbers.template_jsonholds a template expansion’s placeholder values.
Sweep siblings share config_entry and differ in sweep_json; AlgoChart groups them on that. name keeps its Name=value suffixes (Config files and run matrices), and capital_units is the entry’s share of the pool.
Failed runs
A run that failed, in a set that kept going past it (When a run of a set fails), is kept:
- it has
status = 'failed'and itserror, the message that stopped it; - its config facts are recorded:
name,strategy,inputs_json,capital,config_entryandsweep_json.inputs_jsonis{}in a file converted from a results folder, whoseindex.jsondoes not record a failed run’s inputs; - it has no rows in the result tables:
equity_chunks,equity_daily,trades,combo_trades,fillsandbenchmarks.
A sweep’s refused combination is such a run: AlgoChart shows it as a “refused” cell.
Bars from the run, or fetched again
bars_source = 'run':algo run --exportrecorded the bars as the engine delivered them during the run, so they are exactly what the strategy saw.bars_source = 'refetched':algo exportfetched them again from the run’s adapter, pinned to the snapshot. The archive may have moved since the run, so a reader checks that the fills lie inside their bars.
Features
meta.features is a JSON array that names what the file holds beyond the minimum. A file converted from older results lacks some features, and a reader falls back where one is missing.
| Feature | Present when |
|---|---|
per-bar-equity | equity_chunks holds every ok run’s curve at every bar. Without it, equity_daily is the only curve. |
fills | fills holds every fill of every ok run. Without it, fills is empty. |
series-descriptors | series and run_series come from the engine’s own descriptors (role, declaration, session, warm-up) rather than inference from the results. |
sweeps | runs records config_entry, sweep_json and template_json. |
order-names | Every trade of every run carries its orders (results recorded since GLE-666): the entry’s and, when closed, the exit’s label, attempt, name and type, and a closed trade an exit_kind. A fill’s name is its order’s name, NULL for an unnamed order, and its order_type the type of the trade it enters or exits. |
bar-anchors | Every trade has a series_id and bar anchors, and fills have them where a series applies. |
plots | plots and annotations hold every ok run’s strategy plots and annotations; a run without rows plotted nothing. Without it both tables are empty. |
books | books holds every ok run’s long and short books (GLE-1354); a run without rows traded nothing. Without it the table is absent or empty. |
intraday | intraday holds every ok run’s bar marks, its curve’s and its books’ (GLE-1358); a run without rows had none. Without it the table is absent or empty, and the runs read back without an intraday drawdown. |
position-cost | position_cost holds every ok run’s position cost (GLE-1403); a run without rows tied nothing up. Without it the table is absent or empty, and the runs read back without a position cost. |
slices | slices and slice_chunks hold the set’s slices (GLE-1354). Without it both are absent or empty. |
A native export (Writing the export as the set runs) holds every run’s curve at every bar and every fill whatever the config says, so it always has per-bar-equity and fills, and it has books, intraday, position-cost and slices. A converted one has the first two when every run sampled its equity at every bar (report.equity-sampling: "bar") and wrote fills.json; books when every run wrote books.csv; intraday when it has books and every run carries an intraday drawdown; position-cost when some run’s equity.csv has a position_cost column, which a run writes when it tied anything up, so a run without one in such a set tied nothing up; and slices when the folder holds slices.json for the runs it converts.
Tables
The schema below is engine/algorun/schema.sql. A writer runs it as given on an empty database. Every table, column, key and index in it is part of the specification. The sections after it give each table’s meaning.
-- The .algorun export, format algolang.export/1 (GLE-664).
-- PRAGMA application_id = 1095519055 (0x414C474F, "ALGO"); PRAGMA user_version = 1.
-- Times are INTEGER nanoseconds since the Unix epoch, UTC. Booleans are INTEGER 0 or 1.
-- JSON columns hold UTF-8 JSON text. Ordinals named n, seq and ordinal count from 1;
-- chunk indexes count from 0.
CREATE TABLE meta (
key TEXT NOT NULL PRIMARY KEY,
value TEXT NOT NULL
);
CREATE TABLE runs (
run_id TEXT NOT NULL PRIMARY KEY, -- the run's results-folder slug
ordinal INTEGER NOT NULL UNIQUE, -- position in the expanded config
name TEXT NOT NULL, -- display name, sweep suffix included
status TEXT NOT NULL, -- ok | failed
error TEXT, -- why a failed run failed; NULL when ok
strategy TEXT NOT NULL, -- strategy binary base name
strategy_name TEXT, -- the name the strategy reports
strategy_version TEXT, -- the version the strategy reports
config_entry TEXT, -- runs[0], strategies[1].runs[2]
sweep_json TEXT, -- swept inputs: {"Fast":2,"Slow":30}
template_json TEXT, -- template placeholders: {"sym":"ES"}
inputs_json TEXT NOT NULL, -- every input as the run received it
capital REAL NOT NULL,
capital_units REAL NOT NULL,
first_bar INTEGER, -- first equity mark
last_bar INTEGER, -- last equity mark
final_open_equity REAL,
final_closed_equity REAL,
header_json TEXT, -- report.ResultHeader
metrics_json TEXT, -- report.Metrics
director_config_json TEXT, -- the run's director settings
director_summary_json TEXT, -- report.DirectorSummary
degradations_json TEXT -- the run's degradation records
);
CREATE TABLE series (
series_id INTEGER NOT NULL PRIMARY KEY,
label TEXT NOT NULL, -- fut:XCME:ES@1d-eth
symbol TEXT NOT NULL,
interval TEXT, -- NULL for activity bar kinds
bar_kind TEXT NOT NULL, -- time, volume, tick, ...
session TEXT, -- 1d and 1w trading-day container
boundary TEXT, -- intraday grid boundary
clock TEXT, -- continuous: session | epoch
continuous INTEGER NOT NULL,
method TEXT, -- continuous adjustment method
held_rank TEXT, -- continuous: F, F+1, ...
snapshot_json TEXT, -- continuous: {"at","anchor","token"}
adjusted INTEGER NOT NULL, -- bars are an adjusted price view
trades_adjusted INTEGER NOT NULL, -- trade prices are in the bars' view
tz TEXT, -- IANA zone of the venue
tick_size REAL,
point_value REAL,
currency TEXT,
contracts_json TEXT NOT NULL, -- the contract dictionary; [""] at least
first_ts INTEGER, -- first bar's t; NULL when no bars
last_ts INTEGER, -- last bar's t
bar_count INTEGER NOT NULL,
warmup_count INTEGER NOT NULL,
bars_source TEXT NOT NULL, -- run | refetched
chart_query_json TEXT -- the feed's mf-chart query (GLE-670); NULL when it supplied none
);
CREATE TABLE run_series (
run_id TEXT NOT NULL REFERENCES runs (run_id),
series_id INTEGER NOT NULL REFERENCES series (series_id),
ordinal INTEGER NOT NULL, -- position in the run's series
role TEXT NOT NULL, -- traded | reference
declared TEXT NOT NULL, -- config | strategy
name TEXT, -- the strategy's name for a declared series
warmup_start INTEGER, -- t of the run's first bar; NULL when none
PRIMARY KEY (run_id, series_id)
);
CREATE TABLE bar_chunks (
series_id INTEGER NOT NULL REFERENCES series (series_id),
chunk INTEGER NOT NULL,
t0 INTEGER NOT NULL, -- first row's t
t1 INTEGER NOT NULL, -- last row's t
n INTEGER NOT NULL, -- rows, 1 to 8192
codec TEXT NOT NULL, -- deflate
data BLOB NOT NULL,
PRIMARY KEY (series_id, chunk)
);
CREATE INDEX bar_chunks_window ON bar_chunks (series_id, t1);
CREATE TABLE equity_chunks (
run_id TEXT NOT NULL REFERENCES runs (run_id),
chunk INTEGER NOT NULL,
t0 INTEGER NOT NULL,
t1 INTEGER NOT NULL,
n INTEGER NOT NULL,
codec TEXT NOT NULL,
data BLOB NOT NULL,
PRIMARY KEY (run_id, chunk)
);
CREATE INDEX equity_chunks_window ON equity_chunks (run_id, t1);
-- A run with equity chunks has rows here only when some UTC date of its curve
-- holds more than one mark; otherwise its chunks are its daily marks.
CREATE TABLE equity_daily (
run_id TEXT NOT NULL REFERENCES runs (run_id),
date TEXT NOT NULL, -- YYYY-MM-DD, UTC
t INTEGER NOT NULL, -- the day's last mark
open REAL NOT NULL,
closed REAL NOT NULL,
in_market INTEGER NOT NULL,
benchmark REAL, -- NULL without a benchmark
PRIMARY KEY (run_id, date)
) WITHOUT ROWID;
CREATE TABLE fills (
run_id TEXT NOT NULL REFERENCES runs (run_id),
seq INTEGER NOT NULL, -- blotter order
ts INTEGER NOT NULL, -- the fill's stamp
kind TEXT NOT NULL, -- order | roll | expiry | corporate_action
symbol TEXT NOT NULL, -- the symbol the strategy traded
contract TEXT NOT NULL, -- the instrument the venue filled
series_id INTEGER REFERENCES series (series_id),
bar_ts INTEGER, -- t of the bar the fill is anchored to
client_id TEXT,
attempt INTEGER,
name TEXT, -- the order's name
parent_client_id TEXT,
broker_order_id TEXT,
exec_id TEXT,
order_ref TEXT,
order_type TEXT,
side TEXT NOT NULL, -- buy | sell
qty INTEGER NOT NULL,
price REAL NOT NULL, -- in the bars' price view
raw_price REAL NOT NULL, -- the venue's price
commission REAL NOT NULL,
slippage REAL, -- points per unit
combo_leg INTEGER,
PRIMARY KEY (run_id, seq)
);
CREATE INDEX fills_order ON fills (run_id, client_id, attempt);
CREATE TABLE trades (
run_id TEXT NOT NULL REFERENCES runs (run_id),
n INTEGER NOT NULL, -- result.json order
key TEXT NOT NULL,
symbol TEXT NOT NULL,
series_id INTEGER REFERENCES series (series_id),
dir INTEGER NOT NULL, -- 1 long, -1 short
qty INTEGER NOT NULL,
open INTEGER NOT NULL,
entry_ts INTEGER NOT NULL,
entry_price REAL NOT NULL,
entry_bar INTEGER NOT NULL, -- 1-based bar ordinal of the key
entry_bar_ts INTEGER,
entry_fill INTEGER, -- fills.seq
entry_client_id TEXT,
entry_attempt INTEGER,
entry_name TEXT,
entry_type TEXT,
exit_ts INTEGER, -- NULL while open
exit_price REAL NOT NULL, -- the last close while open
exit_bar INTEGER NOT NULL,
exit_bar_ts INTEGER,
exit_fill INTEGER,
exit_client_id TEXT,
exit_attempt INTEGER,
exit_name TEXT,
exit_type TEXT,
exit_kind TEXT, -- order | roll | expiry | corporate_action
bars_held INTEGER NOT NULL,
mfe REAL NOT NULL,
mae REAL NOT NULL,
profit_points REAL NOT NULL,
profit_currency REAL NOT NULL,
point_value REAL NOT NULL,
commission REAL NOT NULL,
slippage REAL NOT NULL,
rolls INTEGER NOT NULL,
currency TEXT,
fx_rate REAL,
profit_local REAL,
entry_place TEXT, -- where in its bar the entry filled: Places
exit_place TEXT, -- the exit's; NULL while open
PRIMARY KEY (run_id, n),
FOREIGN KEY (run_id, entry_fill) REFERENCES fills (run_id, seq),
FOREIGN KEY (run_id, exit_fill) REFERENCES fills (run_id, seq)
);
CREATE INDEX trades_entry ON trades (run_id, entry_ts);
CREATE INDEX trades_bar ON trades (series_id, entry_bar_ts);
CREATE TABLE combo_trades (
run_id TEXT NOT NULL REFERENCES runs (run_id),
n INTEGER NOT NULL,
client_id TEXT NOT NULL,
combo TEXT NOT NULL, -- B1@fut:XCME:ES:M26|S1@fut:XCME:ES:H26
units INTEGER NOT NULL,
open INTEGER NOT NULL,
entry_ts INTEGER NOT NULL,
exit_ts INTEGER,
entry_cost REAL NOT NULL,
exit_cost REAL NOT NULL,
profit_currency REAL NOT NULL,
commission REAL NOT NULL,
PRIMARY KEY (run_id, n)
);
-- A strategy's plots (GLE-677). A plot is the values one name took on one
-- series of a run, one a bar; its rows are its chunks, each holding the bars'
-- opens and the values, NaN for a gap.
CREATE TABLE plots (
run_id TEXT NOT NULL REFERENCES runs (run_id),
plot INTEGER NOT NULL, -- the run's plots in the order first plotted
series_id INTEGER NOT NULL REFERENCES series (series_id),
name TEXT NOT NULL,
style_json TEXT NOT NULL, -- {"kind":"line","pane":"rsi","color":"#2962ff"}
chunk INTEGER NOT NULL,
t0 INTEGER NOT NULL,
t1 INTEGER NOT NULL,
n INTEGER NOT NULL,
codec TEXT NOT NULL,
data BLOB NOT NULL,
PRIMARY KEY (run_id, plot, chunk)
);
CREATE INDEX plots_series ON plots (series_id, name);
-- A strategy's annotations (GLE-677): notes on bars.
CREATE TABLE annotations (
run_id TEXT NOT NULL REFERENCES runs (run_id),
n INTEGER NOT NULL, -- the run's annotations in order
series_id INTEGER NOT NULL REFERENCES series (series_id),
bar_ts INTEGER NOT NULL, -- the bar's open
text TEXT NOT NULL,
position TEXT NOT NULL, -- above | below | at
price REAL, -- with position at only
shape TEXT NOT NULL, -- circle | square | arrowUp | arrowDown
color TEXT, -- "#RRGGBB"; NULL for the viewer's choice
PRIMARY KEY (run_id, n)
);
CREATE INDEX annotations_bar ON annotations (series_id, bar_ts);
CREATE TABLE director (
run_id TEXT NOT NULL REFERENCES runs (run_id),
sequence INTEGER NOT NULL,
kind TEXT NOT NULL,
event_time INTEGER,
instant_sequence INTEGER,
phase TEXT,
stage TEXT,
client_id TEXT,
attempt INTEGER,
symbol TEXT,
side TEXT,
requested INTEGER,
accepted INTEGER,
reason_code TEXT,
cause_code TEXT,
rule INTEGER,
record_json TEXT NOT NULL, -- the log line exactly as written
PRIMARY KEY (run_id, sequence)
);
CREATE INDEX director_time ON director (run_id, event_time);
CREATE INDEX director_order ON director (run_id, client_id, attempt);
CREATE TABLE rolls (
series_id INTEGER NOT NULL REFERENCES series (series_id),
cut_ts INTEGER NOT NULL,
from_contract TEXT NOT NULL,
to_contract TEXT NOT NULL,
gap REAL NOT NULL,
ratio REAL NOT NULL,
cumulative REAL NOT NULL,
cum_ratio REAL NOT NULL,
outgoing_price REAL NOT NULL,
incoming_price REAL NOT NULL,
degraded INTEGER NOT NULL,
PRIMARY KEY (series_id, cut_ts)
);
CREATE TABLE instruments (
run_id TEXT NOT NULL REFERENCES runs (run_id),
symbol TEXT NOT NULL,
point_value REAL,
tick_size REAL,
currency TEXT,
margin_json TEXT, -- report.MarginSpec
PRIMARY KEY (run_id, symbol)
);
CREATE TABLE calendars (
run_id TEXT NOT NULL REFERENCES runs (run_id),
root TEXT NOT NULL,
revision TEXT, -- NULL when none was served
info_json TEXT NOT NULL, -- report.CalendarInfo
PRIMARY KEY (run_id, root)
);
CREATE TABLE benchmarks (
run_id TEXT NOT NULL REFERENCES runs (run_id),
ordinal INTEGER NOT NULL, -- report order
name TEXT NOT NULL,
is_primary INTEGER NOT NULL,
spec_json TEXT NOT NULL, -- report.BenchmarkSpec
result_json TEXT, -- report.Benchmark; NULL when not computable
PRIMARY KEY (run_id, ordinal)
);
-- A run's long and short books (GLE-1354). A book is one report key's long or
-- short P&L, marked to market (open) and realized (closed), each net of the
-- commission it paid, and the quantity it held open, at the marks of the run's
-- curve where any of them changed. It holds its last row until its next and is
-- flat before its first. Its rows are its chunks.
CREATE TABLE books (
run_id TEXT NOT NULL REFERENCES runs (run_id),
key TEXT NOT NULL, -- the report key
dir INTEGER NOT NULL, -- 1 long, -1 short
chunk INTEGER NOT NULL,
t0 INTEGER NOT NULL,
t1 INTEGER NOT NULL,
n INTEGER NOT NULL,
codec TEXT NOT NULL,
data BLOB NOT NULL,
PRIMARY KEY (run_id, key, dir, chunk)
);
-- A run's bar marks (GLE-1358): at a mark of its curve, what the bars that
-- closed there add to it inside them, relative to the mark: the lowest the
-- P&L stood (low, <= 0), the highest before that or at the close (high, >= 0)
-- and the deepest fall within them (drop, >= 0). Key '' and dir 0 are the
-- run's curve; a key and dir 1 or -1 one of its books. Only marks with any
-- have rows. Its rows are its chunks.
CREATE TABLE intraday (
run_id TEXT NOT NULL REFERENCES runs (run_id),
key TEXT NOT NULL, -- the report key; '' for the run's curve
dir INTEGER NOT NULL, -- 1 long, -1 short, 0 the run's curve
chunk INTEGER NOT NULL,
t0 INTEGER NOT NULL,
t1 INTEGER NOT NULL,
n INTEGER NOT NULL,
codec TEXT NOT NULL,
data BLOB NOT NULL,
PRIMARY KEY (run_id, key, dir, chunk)
);
-- A run's position cost (GLE-1403): at a mark of its curve, what its open
-- positions tied up, in the base currency: a future's initial margin, an
-- equity's market value. Only marks with a cost have rows. Its rows are its
-- chunks.
CREATE TABLE position_cost (
run_id TEXT NOT NULL REFERENCES runs (run_id),
chunk INTEGER NOT NULL,
t0 INTEGER NOT NULL,
t1 INTEGER NOT NULL,
n INTEGER NOT NULL,
codec TEXT NOT NULL,
data BLOB NOT NULL,
PRIMARY KEY (run_id, chunk)
);
-- The set's slices (GLE-1354): its results by strategy, symbol and side. A
-- slice's trades are its runs' trades of its symbol and side.
CREATE TABLE slices (
n INTEGER NOT NULL PRIMARY KEY, -- the set's slices in order
strategy TEXT, -- the strategy's key; NULL for every strategy
name TEXT, -- the strategy's name; NULL for every strategy
symbol TEXT, -- the report key; NULL for every symbol
side INTEGER NOT NULL, -- 1 long, -1 short, 0 both
runs_json TEXT NOT NULL, -- the run ids it draws on
capital REAL NOT NULL,
risk_free_rate REAL NOT NULL,
first_bar INTEGER,
last_bar INTEGER,
final_open_equity REAL NOT NULL,
final_closed_equity REAL NOT NULL,
avg_hold_seconds REAL NOT NULL,
metrics_json TEXT, -- report.Metrics; NULL with same_as
residual_json TEXT NOT NULL, -- report.SliceResidual
same_as INTEGER REFERENCES slices (n) -- the earlier slice whose curve and figures it shares
);
-- A slice's curve, as equity chunks with a NaN benchmark. A slice with same_as
-- has none.
CREATE TABLE slice_chunks (
slice INTEGER NOT NULL REFERENCES slices (n),
chunk INTEGER NOT NULL,
t0 INTEGER NOT NULL,
t1 INTEGER NOT NULL,
n INTEGER NOT NULL,
codec TEXT NOT NULL,
data BLOB NOT NULL,
PRIMARY KEY (slice, chunk)
);
CREATE TABLE portfolio (
runs_json TEXT NOT NULL, -- the run ids combined
capital REAL NOT NULL,
first_bar INTEGER,
last_bar INTEGER,
final_open_equity REAL NOT NULL,
final_closed_equity REAL NOT NULL,
avg_hold_seconds REAL NOT NULL,
metrics_json TEXT NOT NULL, -- report.Metrics
contribution_json TEXT NOT NULL, -- []report.Contribution
correlation_json TEXT NOT NULL -- report.CorrMatrix
);meta
One row per key; every value is text.
| Key | Value |
|---|---|
format | algolang.export/1. |
complete | 1, written last. |
created_at | When the file was written, RFC 3339 in UTC. |
build_id | The engine build that wrote it. |
features | The features, a JSON array. |
base_currency | The accounts’ currency, ISO 4217. |
risk_free_rate | The annual rate the metrics used, a decimal (0.04). |
equity_sampling | bar when equity_chunks holds every run’s curve at every bar, as a native export’s always does whatever the set’s report.equity-sampling says; daily when a converted file holds only equity_daily, its runs having sampled daily. report.equity-sampling itself governs equity.csv only. |
accounts | separate: every run is its own account, so taking runs out of a combination is exact. It is the only value in version 1; shared accounts (GLE-360) will need another. |
set_name | The set’s name: algo export --name, else the results folder’s name; a native export’s file name without .algorun. |
config_path, config_json | The run config’s path and its text, comments stripped, when the set came from a config. |
capital_pool | The config’s initial-capital, when it set one. |
runs
One row per run, in the order the config expanded. Its key is run_id, the run’s results-folder slug.
statusisokorfailed;errorholds a failed run’s message (see Failed runs).name,strategyandstrategy_nameare the display name, the binary and the name the strategy reports.strategy_versionis the version the strategy reports, when it reports one; none does today.inputs_jsonis every input as the run received it, an object of strings, asResultHeader.Inputs.capitalis the run’s allocated capital andcapital_unitsits share of the pool.first_barandlast_barare the curve’s first and last marks.final_open_equityandfinal_closed_equityare its last values.header_jsonandmetrics_jsonareresult.json’s header and metrics.director_config_jsonis the run’s director settings as configured.director_summary_jsonisResultHeader.DirectorSummary, whoseLogis empty when the run kept its decision log in the export alone.degradations_jsonis the run’sdegradation.json.
series
One row per distinct series, as the warm-up section defines distinct.
- Naming.
labelis the engine’s series label:SYMBOL@INTERVAL[-SESSION], or the construction key for activity bars, such asMSFT@volume:t=1000. - Bar construction.
intervalis NULL for activity bar kinds.bar_kindis the kind’s short name.sessionis a 1d or 1w trading-day container (eth,rth,session).boundaryis an intraday grid’s boundary (utc-day,eth,rth,session). A series has at most one of the two.clockis a continuous run’ssessionorepochclock. - Continuous futures.
continuous,method,held_rankandsnapshot_jsondescribe a continuous future. - Prices.
adjustedandtrades_adjustedare described under Adjusted and raw prices. - The instrument.
tzis the venue’s IANA zone.tick_size,point_valueandcurrencydescribe the instrument, when it has them. - The contract dictionary.
contracts_jsonis the dictionary the chunks’contractcolumn indexes. Entry 0 is always"", “no dated contract”, so a plain series’ dictionary is[""]. - Counts.
first_tsandlast_tsare the first and last bars’t.bar_countcounts every bar andwarmup_countthe warm-up ones. - Provenance.
bars_sourceisrunorrefetched. - The chart query.
chart_query_jsonis the feed’s mf-chart query for the series (GLE-670): a JSON object of mf-chart/api/v1/barsquery parameters, the run descriptor’sChart(Artefact formats). NULL when the feed supplied none, as a file adapter does. A re-fetched series keeps the run’s query: it names the series the run read.
run_series
Which runs read which series. The key is (run_id, series_id).
ordinalis the series’ position in the run’s series list.roleistraded, a series the run’s orders could trade, orreference, data only.declaredisconfig, a series the config named, orstrategy, one the strategy declared.nameis the strategy’s name for a series it declared.warmup_startis thetof the first bar the run received. It is NULL when the run received none.
bar_chunks and equity_chunks
A series’ bars and a run’s equity marks, in chunks of 8,192 rows: see Chunks. t0 and t1 are the chunk’s first and last t, and n its rows. The index on t1 serves a window query.
equity_daily
A run’s curve at the last mark of each UTC date, equity.csv’s daily sampling:
tis the mark’s instant;open,closedandin_marketare the mark’s values;benchmarkis the primary benchmark’s equity, NULL when the run has none or it held nothing, asequity.csvthen has nobenchmarkcolumn.
It is enough to recombine runs at daily resolution without decoding a chunk, for a run whose curve is finer than daily.
A run whose curve has at most one mark a UTC date has no rows here: a run on daily or coarser bars, whose equity_chunks already are its daily marks and would only be copied. A reader takes such a run’s daily marks from its chunks; a run with neither has no curve. This keeps a daily sweep small: its equity_daily would otherwise be the largest table in the file (GLE-672). The table is WITHOUT ROWID, stored in its key’s order, with no separate index. A file written before GLE-672 has a row for each mark of such a run, the same curve, and a reader may ignore them.
fills
One row per fill, in blotter order.
What filled.
symbolis the symbol the strategy traded, the logical one on a continuous run.contractis the instrument the venue filled, the dated contract. A roll leg is not the strategy’s order: itssymbolis its contract, and itspriceis the venue’s (GLE-1385).What kind of fill.
kindis one of:order: an order the strategy placed;roll: a roll leg, whose client id isroll/<symbol>/<cut>/closeor/open;expiry: a contract’s expiry settlement;corporate_action: a corporate action’s leg.
Expiry and corporate-action fills have no client id. A converter that cannot tell them apart by other means takes
expiryfor a future andcorporate_actionfor an equity.Where it sits.
series_idandbar_tsare the fill’s anchor.The order.
client_idandattemptjoin a fill to its trades and to the director’s records.nameis the order’s name (GLE-666), as the blotter records it: NULL for an unnamed order and for a fill of no order.order_typeis the order’s type in the lifecycle trace’s words, from the trade the fill enters or exits: NULL for a fill no trade links, and for every fill of a run recorded before GLE-666.parent_client_id,broker_order_id,exec_idandorder_refare the venue’s identities.Prices and costs.
priceis in the bars’ price view andraw_priceis the venue’s.commissionis the fill’s, as the blotter records it.slippageis in points per unit. It is NULL when the source does not record it.combo_legis a combo leg’s number (GLE-409).
trades
One row per trade, result.json’s Trades in order: closed trades as they closed, then open ones. Every field of report.Trade has its column, but the bar anchors: EntrySeries is series_id, EntryBarTime and ExitBarTime are entry_bar_ts and exit_bar_ts, and the place in the bar, EntryFill and ExitFill, is entry_place and exit_place (GLE-676). The columns entry_fill and exit_fill are other things: the fills’ seq. The orders’ labels, EntryLabel and ExitLabel (GLE-666), are entry_client_id and exit_client_id.
- Prices.
entry_priceandexit_priceare the report’s (see Adjusted and raw prices). An open trade’sexit_priceis its symbol’s last close. - Anchors.
entry_barandexit_barare the report’s 1-based bar ordinals of the key.entry_bar_tsandexit_bar_tsare bar anchors onseries_id, the series the trade’s fills anchor to.entry_placeandexit_placesay where in its bar each fill happened:open,intrabar,close,tick,cutorsettlement; an open trade has noexit_place. A file written before GLE-676 has neither column (Identity and versions). A trade has oneseries_id, so a trade that entered on one interval of a symbol and exited on another is anchored on the entry’s series, and reads back with the entry’s series as its exit’s: a limitation of version 1. - Orders.
entry_fillandexit_fillare the fills’seq.entry_client_id,entry_attempt,entry_nameandentry_typedescribe the entry’s order, and theexit_columns the exit’s. A trade recorded since GLE-666 gives them asresult.jsonrecords them: the fill’s label and attempt, the order’s name (the strategy’s, or the order’s effect:Buy,Sell Short,SellorBuy to Cover) and its type. An older trade has the labels and attempts of the fills linked to it, and no names or types. - How it closed.
exit_kindis the trade’s own:order,rollorexpiryfor a trade recorded since GLE-666, whoseend_of_datais not written. An older trade’s is its exit fill’skind. - Open trades. An open trade has
open = 1, and noexit_ts,exit_fill,exit_bar_tsorexit_kind. - Other currencies.
currency,fx_rateandprofit_localare set when the trade’s symbol is quoted in another currency.
Its indexes serve a run’s trades in time order, and a series’ trades by bar.
combo_trades
One row per combo trade (report.ComboTrade, GLE-409). The combo’s legs are also in trades. combo names the legs per unit, for example B1@fut:XCME:ES|S1@fut:XCME:NQ.
plots
A run’s strategy plots (GLE-677), one row per chunk of a plot. A plot is the values one name took on one series of a run, one a bar, keyed by run_id and plot, which numbers the run’s plots in the order they were first plotted. Every chunk of a plot repeats its series_id, name and style_json. The chunks hold the bars’ opens and the values, NaN for a gap (Chunks). A file written before GLE-677 has neither this table nor annotations (Identity and versions).
annotations
A run’s strategy annotations (GLE-677): one row per note on a bar of series_id, at bar_ts, the bar’s open, in the order the strategy made them.
director
One row per record of a run’s trade director log, director-decisions.jsonl (The decision log), before its footer.
- The record itself.
record_jsonis the line exactly as written, without its newline. - Its fields. The other columns are copies of its fields, for querying:
event_timeis converted to nanoseconds;requestedandacceptedcome fromrequested_quantityandaccepted_quantity;- a field the record does not carry is NULL.
- The footer. It is not a row. Its record count and SHA-256 are in
runs.director_summary_json, asRecordsandLogSHA256. - Checking it. A reader checks the log by hashing each
record_jsonplus a newline, insequenceorder. The digest must equalLogSHA256and the row countRecords.
rolls
One row per roll of a continuous series, from its manifest’s forward adjustments:
cut_tsis the roll’s effective instant;outgoing_priceandincoming_priceare the two contracts’ raw prices at it;gap(panama) andratio(ratio methods, 0 otherwise) are the roll’s adjustment;cumulativeandcum_ratioare the adjustment accumulated through it;degradedmarks a seam built from a fallback price.
instruments
Each run’s instruments:
point_value,tick_sizeandcurrency;margin_json, the run’sreport.MarginSpecfor the symbol, when it held a margin requirement.
calendars
Each run’s exchange-calendar provenance, one row per root, when the run asked for calendars:
info_jsonisreport.CalendarInfo;revisionis its served revision, NULL when none was served.
benchmarks
Each run’s benchmarks, in report order:
spec_jsonis the configuredreport.BenchmarkSpec;result_jsonis the computedreport.Benchmark, NULL when it was not computable;- exactly one benchmark of a run has
is_primary = 1. Its curve is thebenchmarkcolumn of the run’s equity.
books
Each ok run’s long and short books (GLE-1354), one row per chunk of a book. A book is one report key’s long (dir = 1) or short (dir = -1) side: its P&L marked to market and realized, each net of the commission it paid, and the quantity it held open, at the marks of the run’s curve where any of them changed (Chunks). It holds its last row until its next and is flat before its first. A file written before GLE-1354 has no table.
intraday
Each ok run’s bar marks (GLE-1358), one row per chunk: the run’s curve’s (key '', dir = 0) and each of its books’ (their key and dir). A mark is what the bars that closed at one mark of the run’s curve add to it inside them, as equity.csv’s intra_ columns: low, high and drop, relative to the curve’s or the book’s own value at the mark. Only marks with any have rows; a mark without one adds nothing. The run’s metrics_json holds its maximum intraday drawdown, and a reader takes the marks to recompute a slice’s. A file written before GLE-1358 has no table.
position_cost
Each ok run’s position cost (GLE-1403), one row per chunk: at a mark of the run’s curve, what its open positions tied up there, in the base currency, as equity.csv’s position_cost column. A future counts its initial margin and an equity its market value. Only marks with a cost have rows, each above 0; a mark without one tied nothing up. A reader sets each mark’s cost before it folds a day’s marks, so a daily mark carries the most the day tied up, as equity.csv does, and a portfolio’s cost is its runs’ added together. A file written before GLE-1403 has no table.
sqlite3 -readonly testdata/algorun/reference.algorun \
"SELECT run_id, chunk, n, datetime(t0 / 1e9, 'unixepoch') FROM position_cost"sma-es-fast-5-slow-20|0|8192|2026-03-09 01:41:00
sma-es-fast-5-slow-20|1|268|2026-03-17 18:33:00
es-nq-spread|0|46|2026-01-21 00:00:00slices and slice_chunks
The set’s slices (GLE-1354), one row each, numbered by n in the set’s order. strategy is the strategy’s key, name its name and symbol the report key; NULL is every strategy or every symbol. side is 1, -1 or 0, both. runs_json lists the runs it draws on.
metrics_jsonis itsreport.Metrics, the same figures as a run’s, without benchmarks.residual_jsonis itsreport.SliceResidual: what its parts by side, by symbol and by strategy leave of its P&L at its last mark.- A slice that shares an earlier one’s curve and figures names it in
same_as, and has nometrics_jsonand no chunks. slice_chunksholds each other slice’s curve as equity chunks, itsbenchmarkcolumn NaN: every mark, or each UTC date’s last for a slice converted from a daily-sampled results folder.- A slice’s trades are not stored: they are its runs’ trades of its symbol and side, merged in time order for a slice of several runs.
portfolio
At most one row: the combination of the set’s ok runs as Go computed it, which is portfolio/result.json. It is present when the set has two or more ok runs.
runs_jsonlists the runs combined.metrics_json,contribution_jsonandcorrelation_jsonare its metrics, contribution table and correlation matrix.
A reader shows it at once and checks its own recombination against it.
Chunks
A series’ bars and a run’s equity marks are stored in chunks:
- Rows. A chunk holds 8,192 rows, except the last chunk of its series or run, which holds the remaining 1 to 8,192. Chunks count from 0, so row
iof a series is in chunki / 8192. - Layout. A chunk’s
dataholds its columns one after another, each a run ofnlittle-endian values. There is no header:nandcodecare the row’s own columns. - Time columns. These are delta-encoded. The first value is the instant itself, and each later value is the difference from the value before it, in int64 arithmetic that wraps.
- Codec. The concatenated columns are compressed as one stream.
Bar chunk columns, 59 n bytes before compression:
| Column | Type | Meaning |
|---|---|---|
t | int64, delta | Bar open, nanoseconds |
tc | int64, delta | Bar close, nanoseconds |
o, h, l, c | float64 | Prices, in the series’ view |
v | float64 | Volume |
contract | uint16 | Index into series.contracts_json |
flags | uint8 | Bits below |
Equity chunk columns, 33 n bytes before compression:
| Column | Type | Meaning |
|---|---|---|
t | int64, delta | The mark’s instant, a bar close |
open | float64 | Open equity: cash plus open positions at the close |
closed | float64 | Closed equity: capital plus realized P&L less commission |
benchmark | float64 | The primary benchmark’s equity, NaN when the run has none or it held nothing |
in_market | uint8 | 1 any position, 2 a long one, 4 a short one, as equity.csv |
Marks strictly increase in t. The curve is the recorder’s at every bar, the curve the metrics are computed from, whatever the set’s equity_sampling.
Plot chunk columns (GLE-677), 16 n bytes before compression:
| Column | Type | Meaning |
|---|---|---|
t | int64, delta | The bar’s open, a bar of the plot’s series |
v | float64 | The plotted value, NaN for a gap |
Times strictly increase across a plot’s chunks.
Book chunk columns (GLE-1354), 32 n bytes before compression:
| Column | Type | Meaning |
|---|---|---|
t | int64, delta | The mark’s instant, a mark of the run’s curve |
open | float64 | The book’s P&L marked to market, net of its commission |
closed | float64 | Its realized P&L, net of its commission |
qty | int64 | The units it held open |
Times strictly increase across a book’s chunks.
Intraday chunk columns (GLE-1358), 32 n bytes before compression:
| Column | Type | Meaning |
|---|---|---|
t | int64, delta | The mark’s instant, a mark of the run’s curve |
low | float64 | The lowest the P&L stood in the mark’s bars, 0 or less |
high | float64 | The highest before that low, or the close when that is higher, 0 or more |
drop | float64 | The deepest fall within them, 0 or more |
Position cost chunk columns (GLE-1403), 16 n bytes before compression:
| Column | Type | Meaning |
|---|---|---|
t | int64, delta | The mark’s instant, a mark of the run’s curve |
cost | float64 | What the run’s open positions tied up there, above 0 |
Times strictly increase across a curve’s or a book’s chunks.
Bar flags:
| Bit | Name | Meaning |
|---|---|---|
| 1 | warmup | Delivered as warm-up history |
| 2 | late | Delivered late: buffered by the strategy, with no decision on it |
| 4 | seam | A continuous bar whose bucket straddles a roll cut |
| 8 | seam_partial | A seam bar holding only part of its bucket |
| 16 | degraded | Inside a span one of the run’s degradation records names for its series |
| 32 | no_open | Delivered without an open time; t is its close |
Bits 64 and 128 are free for later flags, which a reader ignores.
Codec. codec = 'deflate' is raw DEFLATE (RFC 1951) with no zlib or gzip framing:
| Reader | How it reads it |
|---|---|
| Go | compress/flate |
| Apple | the Compression framework’s COMPRESSION_ZLIB |
| C zlib | inflateInit2 with windowBits = -15 |
| Python | zlib.decompress(data, -15) |
Neither side needs a new dependency. lz4, the LZ4 block format (Apple’s COMPRESSION_LZ4_RAW), is reserved for a later version; version 1 writes deflate only.
A window of bars is one indexed query and a few decompressions:
SELECT chunk, n, codec, data FROM bar_chunks
WHERE series_id = :series AND t1 >= :from AND t0 <= :to
ORDER BY chunk;Decoding a chunk needs nothing beyond a language’s standard library. In Python:
import sqlite3, struct, sys, zlib
db = sqlite3.connect(f"file:{sys.argv[1]}?mode=ro", uri=True)
codec, n, data = db.execute(
"SELECT codec, n, data FROM bar_chunks WHERE series_id = 1 AND chunk = 0").fetchone()
assert codec == "deflate"
raw = zlib.decompress(data, -15) # raw DEFLATE
assert len(raw) == 59 * n
def times(column): # undo the delta encoding
t, out = 0, []
for delta in struct.unpack_from(f"<{n}q", raw, column * 8 * n):
t += delta
out.append(t)
return out
t, tc = times(0), times(1)
o, h, l, c, v = (struct.unpack_from(f"<{n}d", raw, (2 + k) * 8 * n) for k in range(5))
contract = struct.unpack_from(f"<{n}H", raw, 56 * n)
flags = raw[58 * n:]
print(n, t[0], tc[0], c[0], contract[0], flags[0])Size and speed
These figures were measured on the year of smacross 20/60 on ES 1m in the design (2025-10-01 to 2026-09-30, the installed marketfeed adapter):
| Rows | Raw | Deflated | |
|---|---|---|---|
| Bars | 354,161 | 20.90 MB | 2.63 MB |
| Per-bar equity, with a benchmark | 354,161 | 11.69 MB | 1.66 MB |
| Per-bar equity, without one | 354,161 | 11.69 MB | 0.71 MB |
The results folder of the same run is 57 MB, report.html 31 MB of it.
- Page size. The page size is the writer’s choice and not part of the format. A large export reads its BLOBs faster with 64 KiB pages. A small one is smaller with SQLite’s default, because every table and index takes at least one page: the reference file uses 4 KiB.
- Vacuum. A writer
VACUUMs before the rename.
Native exports, measured. The design’s three sets, from the configs in testdata/algorun/configs/, written by algo run --export at the writer’s default 64 KiB pages (GLE-672), beside the design’s estimates and the files algo export converted from the same sets’ results at 4 KiB pages (The reference file):
| Set | Native export | Design estimate | algo export fixture (4 KiB pages) |
|---|---|---|---|
| 4-run sample (ES/NQ 1d, 2018–2026) | 4.8 MB | well under 1 MB | 2.4 MB |
| 63-run ES 1d sweep (10 failed) | 17.1 MB | about 2 MB | 9.5 MB (53 runs) |
| 1 year of ES 1m (6,922 trades) | 12.2 MB | about 6 MB | 8.3 MB |
The design’s estimates counted the bars and the per-bar curves alone, and every file is over them. Measured table by table (SQLite’s dbstat), what fills them:
- The sweep: its per-run JSON, trades and fills. Its runs are on daily bars, so their curves have no
equity_dailyrows: the chunks are their daily marks (GLE-672). Before that rule,equity_dailyand its index took 14 MB of a 31 MB file. Nowrunsandbenchmarks, each run’s header, metrics and benchmark results as JSON, take 7 MB of the 17; the trades 1.5 MB; and the fills 2.8 MB with their indexes. The converted fixture lacks the fills, because its runs wrote nofills.json. The bars are small: the seven stored copies of ES 1d take 0.3 MB, and the 53 per-bar curves 1.8 MB. - The sample and the 1m set: the 64 KiB pages. Every table and index takes at least one page, and the last page of a BLOB is rarely full: 2.3 MB of the sample’s 4.8 MB is unused page space, and 3.6 MB of the 1m file’s 12.2 MB. The rows themselves come to 2.5 MB and 8.6 MB, about what the fixtures hold at 4 KiB pages. In the 1m file the bars take 3.2 MB of pages and the curve 2.8 MB, for 2.6 MB and 1.7 MB of chunks, and the trades and fills with their indexes 4.3 MB.
Time and memory. The 1m set ran in 20.5 s with the export, about what it takes without one. Its peak memory was 1.40 GB, against 1.3 GB for the same run without the export: the bars are spooled to disk, not held.
Checking a file
algorun.Check(path) validates a file against this chapter. It returns every violation it finds, and it refuses outright:
- another application (
ErrNotExport); - an unknown version or format (
ErrVersion); - an unfinished file (
ErrIncomplete).
The schema. Every specified table, column, index and foreign key is present, and each column declares the specified type, NOT NULL and key. More is allowed. Less is allowed only for a later addition, which is checked where it is there (Identity and versions).
Values:
- every value’s storage class matches its column;
- JSON columns are valid JSON, and the ones that hold algolang types decode into them;
- enumerated columns hold their values;
- booleans are 0 or 1;
- every foreign key resolves (
PRAGMA foreign_key_check).
Chunks:
- each chunk decodes to exactly
nrows; - chunks count from 0 without gaps;
- only the last chunk is short;
t0andt1match the rows;- bar times never decrease and marks strictly increase;
- every contract index is inside its dictionary;
- warm-up bars are a prefix, and the series’ counts and bounds match.
Results:
equity_dailyis the last mark of each date, and has no rows for a run whose per-bar curve has at most one mark a date (a file written before GLE-672 may have a row for each of its marks instead);- a run’s bounds and final equity match its curve;
- failed runs have no results;
- ordinals count from 1 without gaps;
- open trades have no exit;
- every bar anchor is a bar of its series;
- every director row is its record under
algolang.director/1, and the run’s summary digests exactly its rows; - a run has one primary benchmark;
- the portfolio combines ok runs.
Writers check what they write before the rename, and the tests check the reference file the same way.
Reading it back
algorun.Read(path, algorun.ReadOptions{Tier: tier}) turns a file back into the run set that wrote it (GLE-1354), the record every output of a set renders from, and algo report FILE.algorun prints from it:
- each run’s
index.jsonrow, inordinalorder, failed runs included with their error; - each ok run’s
result.json: the header and metrics fromheader_jsonandmetrics_json, the trades and combo trades from their rows; - each ok run’s equity curve at the tier: every mark, from the equity chunks, or the last mark of each UTC date. By default it is every mark the file holds, the curve the run was reported from, whatever its sampling. A run without equity chunks has the daily tier only, from
equity_daily, and reads it by default; - each ok run’s strategy plots and annotations, as its
plots.jsonholds them (GLE-677), nil for a run without any; - each ok run’s books, on its curve at the tier: a book’s value at a mark is its last row at or before it;
- the set’s slices, each curve at the tier, its trades its runs’ and its performance shared with its
same_as; - the portfolio row, as
portfolio/result.json, and the meta.
The run set’s portfolio is left to RunSet.Combine, which combines the runs read back at the rate the run recorded, as the engine did; algo report calls it, or recombines a subset for --runs and --without. The fills, the decision log, the rolls and the degradation report stay in their tables: no report reads them back.
It refuses a file Check refuses, with Check’s error, then reads the file in one read-only transaction, so every table comes from the one complete file even if the path is replaced meanwhile. It reads only what the file has of the later additions: plots and annotations from a file that names plots, and a trade’s places from a file whose trades has the columns. The trades’ order names, types and kinds are read only from a file that names order-names; a file converted from older results has labels its results never had, linked from their fills, and they read back empty. An open trade reads back with the exit kind end_of_data. The benchmark column of the curve is read only for a run whose benchmark held something, as equity.csv has it only then.
For a set the engine wrote, algo report of the file prints what the run printed, and algo report --tier daily of the file equals algo report of the results folder byte for byte when the runs sampled daily, on the design’s sample, sweep and year of ES 1m. A results folder written before GLE-676 can differ in two places: a flat short’s P&L, which result.json printed as -0 and the file holds as 0 (an SQLite REAL drops the sign of zero; the engine now records 0), and a trade’s exit series when it exited on another interval of the symbol (above).
The reference file
testdata/algorun/reference.algorun is a small set made by hand to this chapter. algochart vendors it to test its reader. Its bars and fills are made by hand. Its trades, curves, metrics, benchmarks and portfolio are what engine/report computes from them, so every figure agrees with the rest. It holds three runs from one config (meta.config_json, which runconfig expands to these runs, names and capital), a portfolio, and four series.
Run 1, SMA ES Fast=5 Slow=20:
- continuous ES 1m across the March 2026 roll: 9,680 bars in two chunks, the first 20 warm-up and the last 60 degraded;
- six market orders and the roll’s two legs;
- five trades, two of them carried through the roll and one still open;
- per-bar equity in two chunks, and a primary benchmark;
- its position cost (GLE-1403) in two chunks, at a made-up initial margin of $23,000 an ES contract;
- two strategy plots (GLE-677), each in two chunks:
fast, a line whose first point is a gap, andfast-slow, a histogram in the panespread; and three annotations, below, above and at a price.
Run 2, SMA ES Fast=20 Slow=20: its sweep sibling, which the strategy refused, so it is failed.
Run 3, ES/NQ spread, with a trade director:
- continuous ES and NQ 1d, and the weekly COT series
cot:CFTC:13874A:LF@1w, which the strategy declares for reference; - a combo entry and exit;
- a trimmed and a refused order in its director’s log;
- both legs rolled;
- its position cost, at $23,000 an ES and $33,000 an NQ contract.
The portfolio is runs 1 and 3 combined.
The generator is engine/algorun/reference_test.go. To rewrite the file after changing it:
go test ./engine/algorun -run TestReference -updatemake test fails while the committed file differs from what the generator writes.
The first reference file, testdata/algorun/reference-first.algorun, is the reference file as GLE-664 first wrote it (commit eae1108). It is never rewritten. It predates every later addition:
- its trades have no
entry_placeorexit_place; - it has no
plotsorannotationstable, and itsmeta.featuresdoes not listplots; - its
equity_dailyholds a row for each mark of run 3’s daily curve.
It is how the tests know algolang still reads the oldest version 1 file: Check passes it, it reads back as reference.algorun does but for the places, plots and position cost, and algo report prints the same reports from it, byte for byte (GLE-737). algochart vendors it to test its own reader.
The converted fixtures are the design’s three sets, converted by algo export at 4 KiB pages:
| File | Set | Size |
|---|---|---|
testdata/algorun/sample.algorun | The four-run sample portfolio: ES/NQ spread, term carry and COT trend on ES, and a directed SMA cross on NQ, 1d from 2018 | 2.4 MB |
testdata/algorun/sweep.algorun | The smacross Fast × Slow sweep on ES 1d: the 53 combinations the strategy accepts | 9.5 MB |
testdata/algorun/es-1m.algorun | One year of smacross 20/60 on ES 1m: 354,161 bars after a warm-up of 1,380 | 8.3 MB |
They were converted from results that describe their series (GLE-665), anchor their trades and fills on their bars (GLE-669) and name their trades’ orders (GLE-666), so they hold each series’ warm-up and name series-descriptors, sweeps, order-names and bar-anchors, and plots: smacross plots its two averages. The 1m file holds 2.64 MB of bar chunks, 2.63 MB without the warm-up, as measured, and 1.66 MB of equity chunks. Their configs are in testdata/algorun/configs/, and scripts/algorun-fixtures.sh rewrites the three files over the archive. make test validates them with Check.
The chart-query fixture, testdata/algorun/chart-query.algorun (1.6 MB, GLE-710), is a native export of MF-1’s acceptance set (testdata/algorun/configs/chart-query.json): smacross on ES :cont at 1d eth, rth and session and at 1w rth, and on ES H26 in a custom:0930-1600 window. Its bars were recorded during the run, and every series carries the feed’s chart query (chart_query_json), which AlgoChart’s Open in New Tab sends to mf-chart: the four continuous ones pin adjust_anchor and snapshot_token, the dated contract’s names its 1d-custom:0930-1600 window. scripts/algorun-fixtures.sh writes it with a marketfeed adapter from d4c5af1 or later, VACUUMed to 4 KiB pages.
The subset and side goldens in engine/report/testdata/subsets/ are what AlgoChart’s recombination is checked against. set.algorun is three runs of smacross (Fast 2/Slow 5, 3/9 and 5/14) on 30 days of synthetic hourly bars, TEST.csv, with per-bar equity and a held buy-and-hold benchmark; config.json is its config. Beside it:
runs-<letters>-<tier>.json:algo report set.algorun --runs ... --tier <tier> --format jsonfor every non-empty subset of the three runs,a,bandcin order, atdailyandbar;without-<letter>-<long|short>-<tier>.json: the same for all three runs with that run’s long or short book taken out;manifest.json, which lists each file with its runs, tier and the book taken out.
make export-goldens rewrites the directory, offline, and make test fails while a golden differs from what algo report prints.