openalgo-script 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/CHANGELOG.md +929 -0
  2. package/README.md +69 -16
  3. package/dist/adapters/charts/driving.d.ts +50 -0
  4. package/dist/adapters/charts/driving.d.ts.map +1 -0
  5. package/dist/adapters/charts/driving.js +57 -0
  6. package/dist/adapters/charts/driving.js.map +1 -0
  7. package/dist/adapters/charts/run.d.ts +20 -0
  8. package/dist/adapters/charts/run.d.ts.map +1 -1
  9. package/dist/adapters/charts/run.js +83 -16
  10. package/dist/adapters/charts/run.js.map +1 -1
  11. package/dist/adapters/charts/venue.d.ts +73 -0
  12. package/dist/adapters/charts/venue.d.ts.map +1 -0
  13. package/dist/adapters/charts/venue.js +104 -0
  14. package/dist/adapters/charts/venue.js.map +1 -0
  15. package/dist/core/accounting/analysis.d.ts +111 -0
  16. package/dist/core/accounting/analysis.d.ts.map +1 -0
  17. package/dist/core/accounting/analysis.js +123 -0
  18. package/dist/core/accounting/analysis.js.map +1 -0
  19. package/dist/core/accounting/equity.d.ts +33 -0
  20. package/dist/core/accounting/equity.d.ts.map +1 -1
  21. package/dist/core/accounting/equity.js +12 -0
  22. package/dist/core/accounting/equity.js.map +1 -1
  23. package/dist/core/accounting/index.d.ts +2 -0
  24. package/dist/core/accounting/index.d.ts.map +1 -1
  25. package/dist/core/accounting/index.js +1 -0
  26. package/dist/core/accounting/index.js.map +1 -1
  27. package/dist/core/accounting/report.d.ts +3 -0
  28. package/dist/core/accounting/report.d.ts.map +1 -1
  29. package/dist/core/accounting/report.js +2 -0
  30. package/dist/core/accounting/report.js.map +1 -1
  31. package/dist/core/accounting/statistics.d.ts +12 -0
  32. package/dist/core/accounting/statistics.d.ts.map +1 -1
  33. package/dist/core/accounting/statistics.js +23 -1
  34. package/dist/core/accounting/statistics.js.map +1 -1
  35. package/dist/core/backtest/case.d.ts +60 -0
  36. package/dist/core/backtest/case.d.ts.map +1 -0
  37. package/dist/core/backtest/case.js +319 -0
  38. package/dist/core/backtest/case.js.map +1 -0
  39. package/dist/core/backtest/compare.d.ts.map +1 -1
  40. package/dist/core/backtest/compare.js +2 -0
  41. package/dist/core/backtest/compare.js.map +1 -1
  42. package/dist/core/backtest/deliver.d.ts +93 -0
  43. package/dist/core/backtest/deliver.d.ts.map +1 -0
  44. package/dist/core/backtest/deliver.js +94 -0
  45. package/dist/core/backtest/deliver.js.map +1 -0
  46. package/dist/core/backtest/drive.d.ts +66 -8
  47. package/dist/core/backtest/drive.d.ts.map +1 -1
  48. package/dist/core/backtest/drive.js +109 -59
  49. package/dist/core/backtest/drive.js.map +1 -1
  50. package/dist/core/backtest/index.d.ts +24 -12
  51. package/dist/core/backtest/index.d.ts.map +1 -1
  52. package/dist/core/backtest/index.js +21 -10
  53. package/dist/core/backtest/index.js.map +1 -1
  54. package/dist/core/backtest/record.d.ts +63 -2
  55. package/dist/core/backtest/record.d.ts.map +1 -1
  56. package/dist/core/backtest/record.js +71 -4
  57. package/dist/core/backtest/record.js.map +1 -1
  58. package/dist/core/backtest/replay.d.ts.map +1 -1
  59. package/dist/core/backtest/replay.js +11 -1
  60. package/dist/core/backtest/replay.js.map +1 -1
  61. package/dist/core/backtest/simulate.d.ts +113 -1
  62. package/dist/core/backtest/simulate.d.ts.map +1 -1
  63. package/dist/core/backtest/simulate.js +123 -5
  64. package/dist/core/backtest/simulate.js.map +1 -1
  65. package/dist/core/catalogue/catalogue.generated.d.ts +1 -1
  66. package/dist/core/catalogue/catalogue.generated.js +1 -1
  67. package/dist/core/catalogue/catalogue.generated.js.map +1 -1
  68. package/dist/core/check/library-orders.js +2 -2
  69. package/dist/core/check/library-orders.js.map +1 -1
  70. package/dist/core/check/library-prose.generated.js +2 -2
  71. package/dist/core/check/library-prose.generated.js.map +1 -1
  72. package/dist/core/emit/canonical.d.ts +22 -8
  73. package/dist/core/emit/canonical.d.ts.map +1 -1
  74. package/dist/core/emit/canonical.js +67 -6
  75. package/dist/core/emit/canonical.js.map +1 -1
  76. package/dist/core/engine/arithmetic.d.ts +6 -25
  77. package/dist/core/engine/arithmetic.d.ts.map +1 -1
  78. package/dist/core/engine/arithmetic.js +48 -3
  79. package/dist/core/engine/arithmetic.js.map +1 -1
  80. package/dist/core/engine/index.d.ts +1 -1
  81. package/dist/core/engine/index.d.ts.map +1 -1
  82. package/dist/core/engine/index.js +1 -1
  83. package/dist/core/engine/index.js.map +1 -1
  84. package/dist/core/engine/library/arrays.d.ts.map +1 -1
  85. package/dist/core/engine/library/arrays.js +8 -2
  86. package/dist/core/engine/library/arrays.js.map +1 -1
  87. package/dist/core/engine/library/code-points.d.ts +40 -0
  88. package/dist/core/engine/library/code-points.d.ts.map +1 -0
  89. package/dist/core/engine/library/code-points.js +74 -0
  90. package/dist/core/engine/library/code-points.js.map +1 -0
  91. package/dist/core/engine/library/index.d.ts +5 -0
  92. package/dist/core/engine/library/index.d.ts.map +1 -1
  93. package/dist/core/engine/library/index.js +5 -0
  94. package/dist/core/engine/library/index.js.map +1 -1
  95. package/dist/core/engine/library/text.d.ts.map +1 -1
  96. package/dist/core/engine/library/text.js +51 -34
  97. package/dist/core/engine/library/text.js.map +1 -1
  98. package/dist/core/engine/load.d.ts +20 -0
  99. package/dist/core/engine/load.d.ts.map +1 -1
  100. package/dist/core/engine/load.js +62 -0
  101. package/dist/core/engine/load.js.map +1 -1
  102. package/dist/core/engine/verify-tables.d.ts.map +1 -1
  103. package/dist/core/engine/verify-tables.js +41 -0
  104. package/dist/core/engine/verify-tables.js.map +1 -1
  105. package/dist/core/index.d.ts +10 -5
  106. package/dist/core/index.d.ts.map +1 -1
  107. package/dist/core/index.js +8 -3
  108. package/dist/core/index.js.map +1 -1
  109. package/dist/core/stdlib/index.d.ts +1 -1
  110. package/dist/core/stdlib/index.d.ts.map +1 -1
  111. package/dist/core/stdlib/index.js +1 -1
  112. package/dist/core/stdlib/index.js.map +1 -1
  113. package/dist/core/stdlib/maths/index.d.ts +1 -1
  114. package/dist/core/stdlib/maths/index.d.ts.map +1 -1
  115. package/dist/core/stdlib/maths/index.js +1 -1
  116. package/dist/core/stdlib/maths/index.js.map +1 -1
  117. package/dist/core/stdlib/maths/rounding.d.ts +5 -0
  118. package/dist/core/stdlib/maths/rounding.d.ts.map +1 -1
  119. package/dist/core/stdlib/maths/rounding.js +19 -1
  120. package/dist/core/stdlib/maths/rounding.js.map +1 -1
  121. package/dist/core/version/version.generated.d.ts +1 -1
  122. package/dist/core/version/version.generated.js +1 -1
  123. package/package.json +14 -2
  124. package/spec/README.md +2 -1
  125. package/spec/errors.json +3 -3
  126. package/src/adapters/charts/driving.ts +109 -0
  127. package/src/adapters/charts/run.ts +120 -28
  128. package/src/adapters/charts/venue.ts +132 -0
  129. package/src/core/accounting/analysis.ts +188 -0
  130. package/src/core/accounting/equity.ts +38 -0
  131. package/src/core/accounting/index.ts +2 -0
  132. package/src/core/accounting/report.ts +5 -0
  133. package/src/core/accounting/statistics.ts +38 -1
  134. package/src/core/backtest/case.ts +395 -0
  135. package/src/core/backtest/compare.ts +2 -0
  136. package/src/core/backtest/deliver.ts +161 -0
  137. package/src/core/backtest/drive.ts +175 -71
  138. package/src/core/backtest/index.ts +24 -12
  139. package/src/core/backtest/record.ts +134 -5
  140. package/src/core/backtest/replay.ts +11 -1
  141. package/src/core/backtest/simulate.ts +201 -6
  142. package/src/core/catalogue/catalogue.generated.ts +1 -1
  143. package/src/core/check/library-orders.ts +2 -2
  144. package/src/core/check/library-prose.generated.ts +2 -2
  145. package/src/core/emit/canonical.ts +67 -9
  146. package/src/core/engine/arithmetic.ts +23 -3
  147. package/src/core/engine/index.ts +1 -1
  148. package/src/core/engine/library/arrays.ts +8 -2
  149. package/src/core/engine/library/code-points.ts +73 -0
  150. package/src/core/engine/library/index.ts +6 -0
  151. package/src/core/engine/library/text.ts +53 -35
  152. package/src/core/engine/load.ts +68 -0
  153. package/src/core/engine/verify-tables.ts +43 -0
  154. package/src/core/index.ts +16 -2
  155. package/src/core/stdlib/index.ts +1 -0
  156. package/src/core/stdlib/maths/index.ts +1 -0
  157. package/src/core/stdlib/maths/rounding.ts +23 -1
  158. package/src/core/version/version.generated.ts +1 -1
@@ -0,0 +1,319 @@
1
+ /**
2
+ * A run record, turned into the files a conformance case is made of.
3
+ *
4
+ * **The suite is harvested rather than written.** A case invented by hand tests
5
+ * what somebody imagined a run does; a case taken from a run tests what a run
6
+ * actually did. `conformance.md` section 2 says a case is one directory of named
7
+ * files, and a record already holds every one of them: the script it ran, the
8
+ * bars it ran over, the settings it ran with, and what came back. So this is a
9
+ * projection and not a computation. Nothing here folds money, re-reads a report
10
+ * or decides anything a run did not already decide.
11
+ *
12
+ * **Text out, and no I/O.** Core writes no files, so this returns the bytes and
13
+ * the caller puts them where it likes. That also makes it testable without a
14
+ * disk and usable from a browser, which is where most runs happen.
15
+ *
16
+ * **What it refuses, it refuses loudly.** A case with a missing file is worse
17
+ * than no case: it fails on somebody else's engine and the blame lands on them.
18
+ * So a record that cannot make a whole case does not make a partial one, and a
19
+ * record that cannot make a faithful file does not guess at one: the script it
20
+ * has no text for and the instrument fact its host never stated are both
21
+ * refusals, never a hole and never a default.
22
+ *
23
+ * **Every setting of the run has a place in the case, and the table below says
24
+ * which.** A run once harvested to a case that said nothing about the digit
25
+ * count its money was rounded to, the charge schedule its host supplied or the
26
+ * window its report was about, so a second engine ran under other values and
27
+ * took the blame. `CARRIED` names the file each field of the settings is
28
+ * carried in, the type refuses to compile when the settings gain a field with
29
+ * no row, and a record whose settings hold a field the table does not know is
30
+ * refused by name rather than written into a case that ran under something it
31
+ * does not state.
32
+ */
33
+ import { diagnosticFor } from '../diagnostics/index.js';
34
+ import { canonicalNumber, canonicalise } from '../emit/index.js';
35
+ /**
36
+ * The channels a strategy run can be held to.
37
+ *
38
+ * Only what the record carries folded, and only what another engine could
39
+ * produce independently. A case asserts the channels it names and no others, so
40
+ * a change to drawing output cannot break a case about money.
41
+ */
42
+ const STRATEGY_ASSERTS = ['diagnostics', 'orders', 'trades', 'performance'];
43
+ /**
44
+ * `conformance.md` section 6: the loosest bounds a conformance case may declare.
45
+ *
46
+ * Core reads no page, so the two figures are written here, and
47
+ * `tests/backtest/case-settings.test.ts` reads them out of section 6 and holds
48
+ * these to the page, which is the arrangement `stdlib.md` section 20's figures
49
+ * are under. Past either bound a run may still be a useful comparison; what it
50
+ * is not is a case, so the projection makes no file of it.
51
+ */
52
+ export const TOLERANCE_CAP = {
53
+ rel: 1e-9,
54
+ abs: 1e-12,
55
+ };
56
+ /**
57
+ * Where each setting of a run is carried in a case, sections 2 and 3.
58
+ *
59
+ * Every field of the settings has a row and the type makes a field without one
60
+ * a compile error, so a setting the record gains cannot be left out of a case
61
+ * by forgetting. `fill` is the simulated destination's policy, and what it
62
+ * decided is the frames, which are input: an engine handed `frames.csv` folds
63
+ * them and fills nothing itself.
64
+ */
65
+ const CARRIED = {
66
+ contract: 'instrument.json, and backtest.json for the digit count',
67
+ costs: 'backtest.json',
68
+ range: 'backtest.json',
69
+ inputs: 'settings.json',
70
+ now: 'case.json',
71
+ tolerance: 'case.json',
72
+ fill: 'frames.csv, as the frames it decided',
73
+ };
74
+ /**
75
+ * Where a refusal about a setting points: nowhere in the script.
76
+ *
77
+ * A run setting is what the host stated before the first bar, and a caret
78
+ * under a line of the strategy would blame the one party that did not choose
79
+ * it. The run's own settings check states the same position for the same reason.
80
+ */
81
+ const NO_POSITION = { offset: 0, length: 0, line: 0, column: 0 };
82
+ /**
83
+ * The files for one case, or the reason there are none.
84
+ *
85
+ * `now` is written only when the run pinned one. A case that names it when the
86
+ * script never asked pins a clock the run did not depend on, and the next
87
+ * reader has to work out whether it mattered.
88
+ */
89
+ export function caseFilesFrom(record, identity) {
90
+ if (record.sourceText === null) {
91
+ return refused('the record carries no source text, so the case would have no script.os: ' +
92
+ 'record it with sourceText, or re-run the script to record one that has it');
93
+ }
94
+ if (record.bars.form !== 'inline') {
95
+ return refused('the record points at its bars instead of holding them, and a case holds every ' +
96
+ 'byte of its own input: record it with form "inline"');
97
+ }
98
+ if (identity.id.trim() === '')
99
+ return refused('a case needs an id');
100
+ if (identity.description.trim() === '') {
101
+ return refused('a case needs a one-sentence description, which is its failure message');
102
+ }
103
+ const instrument = instrumentOf(record);
104
+ if (!instrument.ok)
105
+ return instrument;
106
+ const settings = settingsRefusal(record.settings);
107
+ if (settings !== null)
108
+ return settings;
109
+ const files = {
110
+ 'case.json': json({
111
+ id: identity.id,
112
+ category: identity.category ?? 'strategy',
113
+ profile: 'strategy',
114
+ languageVersion: Number(record.languageVersion),
115
+ description: identity.description,
116
+ asserts: [...STRATEGY_ASSERTS],
117
+ ...(record.settings.now === null ? {} : { now: record.settings.now }),
118
+ tolerance: record.settings.tolerance,
119
+ }),
120
+ 'script.os': endsWithNewline(record.sourceText),
121
+ 'bars.csv': barsCsv(record.bars.rows),
122
+ // `conformance.md` section 4: performance is a list of one flat object
123
+ // holding the summary statistics and nothing nested. The trades are their
124
+ // own channel and are not repeated inside it, because a figure stated
125
+ // twice in one case is a figure that can disagree with itself. The equity
126
+ // curve, the monthly table and the markers are not written at all: the
127
+ // first two are not conformance channels, being derived from fills and
128
+ // closes the case already fixes, and a marker is a chart output the
129
+ // `markers` channel owns, which a case about money does not assert.
130
+ 'expected.json': json({
131
+ diagnostics: record.diagnostics,
132
+ orders: record.orders,
133
+ trades: record.report.trades,
134
+ performance: [record.report.summary],
135
+ }),
136
+ // Section 2: the record of `host-interface.md` 4.1, which is what the
137
+ // engine was handed and not the money layer's contract. The suite's
138
+ // defaults for an absent file are boring on purpose and are not this run's
139
+ // instrument, so the file is always written.
140
+ 'instrument.json': json(instrument.value),
141
+ // Section 3: what the report was folded under and the script never states.
142
+ // Always written, because every run rounds money to some digit count, and a
143
+ // strategy case that left it out would be run under whatever count a runner
144
+ // assumed. `costs` is null for the declaration's own schedule and `range`
145
+ // carries null for a bound nobody stated, so the file says what the run ran
146
+ // under in every case rather than leaving a default to a runner.
147
+ 'backtest.json': json({
148
+ digits: record.settings.contract.digits,
149
+ costs: record.settings.costs,
150
+ range: record.settings.range,
151
+ }),
152
+ };
153
+ // Without this the case is unpassable, on every engine including the one that
154
+ // wrote it. `conformance.md` section 3 ends "a case with no `frames.csv` is
155
+ // handed no frames at all", and what `expected.json` asserts through the
156
+ // orders channel is what came of the frames: a status, a cumulative quantity,
157
+ // an average fill price. An engine handed none of them folds nothing and
158
+ // disagrees with every row, and the failure reads as a defect in that engine.
159
+ //
160
+ // Written only when the run had frames, because an empty file and an absent
161
+ // one mean the same thing here and the absent one says it in fewer bytes.
162
+ if (record.frames.length > 0)
163
+ files['frames.csv'] = framesCsv(record.frames);
164
+ // Written only when the run had inputs to write. An empty settings.json says
165
+ // "these are the values" about nothing, and section 2 reads an absent one as
166
+ // every input taking its declared default, which is what actually happened.
167
+ if (Object.keys(record.settings.inputs).length > 0) {
168
+ files['settings.json'] = json(record.settings.inputs);
169
+ }
170
+ return { ok: true, files };
171
+ }
172
+ /** A refusal about what the record holds, which no catalogue entry is about. */
173
+ function refused(reason) {
174
+ return { ok: false, reason, code: null };
175
+ }
176
+ /**
177
+ * The instrument record a case can state faithfully, or why there is none.
178
+ *
179
+ * Two refusals, and both are the same refusal: the file `conformance.md`
180
+ * section 2 names is the record of `host-interface.md` 4.1, and a record that
181
+ * cannot produce that record cannot produce the file.
182
+ *
183
+ * A record written before version 3 carries none, because the facts beside
184
+ * the contract were handed to the engine and written down nowhere. And 4.1
185
+ * requires one fact of every host, `hasVolume`, which is the one the engine
186
+ * does not refuse a run without: a run whose host never stated it ran with the
187
+ * flag absent, so a file stating it would hand a second engine a different
188
+ * study than the one the expected output came from, and a file omitting it is
189
+ * not a 4.1 record. The other rules that page states about a record, a session
190
+ * with no timezone to read it in, are refused at load, so a run that happened
191
+ * cannot carry one.
192
+ */
193
+ function instrumentOf(record) {
194
+ if (record.instrument === null) {
195
+ return refused('the record carries no instrument record, so the case would have no instrument.json: ' +
196
+ 'it was written before record version 3, and re-running the script records one');
197
+ }
198
+ if (typeof record.instrument.hasVolume !== 'boolean') {
199
+ return refused('the run was handed no hasVolume, which host-interface.md 4.1 requires of every ' +
200
+ 'host, so instrument.json cannot be the record that page defines: run the script ' +
201
+ 'with the instrument facts stated');
202
+ }
203
+ return { ok: true, value: record.instrument };
204
+ }
205
+ /**
206
+ * Whether every setting the run was carried out under has a place in the case,
207
+ * and whether its tolerance is one the suite accepts.
208
+ *
209
+ * The first question is asked of the record rather than of the type, because a
210
+ * record read back from JSON is whatever was written: a field this projection
211
+ * has no file for is refused with its name, never passed over into a case that
212
+ * then ran under a value it does not state.
213
+ */
214
+ function settingsRefusal(settings) {
215
+ for (const key of Object.keys(settings)) {
216
+ if (key in CARRIED)
217
+ continue;
218
+ return refused(`the record's settings carry ${key}, which no file of conformance.md section 2 has a ` +
219
+ 'place for, so a case written from it would run under a setting it does not state: ' +
220
+ 'give the setting a file on that page and a row in this projection first');
221
+ }
222
+ return toleranceRefusal(settings.tolerance);
223
+ }
224
+ /**
225
+ * A tolerance past the cap is a comparison somebody may find useful and is not
226
+ * a case, `conformance.md` section 6.
227
+ *
228
+ * Refused here, where the case is written, and not only where one is read,
229
+ * because a directory the suite will not accept fails every runner it meets
230
+ * and the blame lands on the engine under test. The run's own settings check
231
+ * refuses a bound with no reason and a bound below zero before a record
232
+ * exists; the cap is the one rule about a tolerance that is the suite's rather
233
+ * than the run's, so it is the one asked here.
234
+ */
235
+ function toleranceRefusal(tolerance) {
236
+ const { abs, rel } = tolerance;
237
+ if (!Number.isFinite(abs) || !Number.isFinite(rel)) {
238
+ return settingRefusal('a bound is not a finite number');
239
+ }
240
+ if (abs <= TOLERANCE_CAP.abs && rel <= TOLERANCE_CAP.rel)
241
+ return null;
242
+ return settingRefusal(`a bound of ${canonicalNumber(abs)} absolute and ${canonicalNumber(rel)} relative is ` +
243
+ 'past the cap conformance.md section 6 puts on a conformance case, ' +
244
+ `${canonicalNumber(TOLERANCE_CAP.abs)} absolute and ${canonicalNumber(TOLERANCE_CAP.rel)} ` +
245
+ 'relative, so this run is a comparison and not a case');
246
+ }
247
+ /** A refusal about the comparison tolerance, filed under the run's own code for a setting. */
248
+ function settingRefusal(problem) {
249
+ const diagnostic = diagnosticFor('OS6021', NO_POSITION, {
250
+ setting: 'The comparison tolerance',
251
+ problem,
252
+ });
253
+ return { ok: false, reason: diagnostic.message, code: diagnostic.code };
254
+ }
255
+ /**
256
+ * Through the canonical writer, so a case's bytes are the record's bytes.
257
+ *
258
+ * There is one canonical writer in this repository and this is not a second
259
+ * one: key order and number form are fixed for everybody, which is what lets a
260
+ * case be compared as text at all.
261
+ */
262
+ function json(value) {
263
+ return `${canonicalise(value)}\n`;
264
+ }
265
+ /** `conformance.md` section 3: header, one row per bar, oldest first, `none` for absent. */
266
+ function barsCsv(rows) {
267
+ const lines = ['time,open,high,low,close,volume'];
268
+ for (const bar of rows) {
269
+ lines.push([bar.time, bar.open, bar.high, bar.low, bar.close, bar.volume].map(cell).join(','));
270
+ }
271
+ return `${lines.join('\n')}\n`;
272
+ }
273
+ /**
274
+ * `conformance.md` section 3: the fields of a frame, in the order that page names.
275
+ *
276
+ * A projection and not a translation. The record already holds an intent as an
277
+ * ordinal rather than as this engine's own id, for the reason the same section
278
+ * gives: a case cannot know the id another engine minted and must not depend on
279
+ * its spelling.
280
+ *
281
+ * The instant is written on every row, `none` where the destination stated
282
+ * none, through the same cell writer as an absent price. A case whose frames
283
+ * carried instants and whose file did not would assert an `updatedAt` that its
284
+ * own input cannot reproduce, which is what the column closes.
285
+ */
286
+ function framesCsv(frames) {
287
+ const lines = ['afterBar,intent,status,filledQty,avgFillPrice,orderRef,text,time'];
288
+ for (const frame of frames) {
289
+ lines.push([
290
+ canonicalNumber(frame.afterBar),
291
+ canonicalNumber(frame.intent),
292
+ frame.status,
293
+ canonicalNumber(frame.filledQty),
294
+ cell(frame.avgFillPrice),
295
+ frame.orderRef ?? '',
296
+ frame.text ?? '',
297
+ cell(frame.time),
298
+ ].join(','));
299
+ }
300
+ return `${lines.join('\n')}\n`;
301
+ }
302
+ /**
303
+ * One cell, through the one number writer.
304
+ *
305
+ * An absent field is `none` rather than empty, because an empty cell between two
306
+ * commas is indistinguishable from a file somebody's editor trimmed, and a
307
+ * language whose central idea is the absent value cannot be vague about it. A
308
+ * case is compared as text, so the number is written by the rule of
309
+ * `language.md` 5.5 and by the same function that writes every other number in
310
+ * the repository, never by a second spelling that agrees until it does not.
311
+ */
312
+ function cell(value) {
313
+ return value === null || !Number.isFinite(value) ? 'none' : canonicalNumber(value);
314
+ }
315
+ /** A text file ends with a newline, so appending to it never joins two lines. */
316
+ function endsWithNewline(text) {
317
+ return text.endsWith('\n') ? text : `${text}\n`;
318
+ }
319
+ //# sourceMappingURL=case.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"case.js","sourceRoot":"","sources":["../../../src/core/backtest/case.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AA+CjE;;;;;;GAMG;AACH,MAAM,gBAAgB,GAAG,CAAC,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,CAAU,CAAC;AAErF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,aAAa,GAAmD;IAC3E,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,KAAK;CACX,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,OAAO,GAAqD;IAChE,QAAQ,EAAE,wDAAwD;IAClE,KAAK,EAAE,eAAe;IACtB,KAAK,EAAE,eAAe;IACtB,MAAM,EAAE,eAAe;IACvB,GAAG,EAAE,WAAW;IAChB,SAAS,EAAE,WAAW;IACtB,IAAI,EAAE,sCAAsC;CAC7C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,WAAW,GAAuB,EAAE,MAAM,EAAE,C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,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;AACrF,CAAC;AAED,iFAAiF;AACjF,SAAS,eAAe,CAAC,IAAY;IACnC,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC;AAClD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../../../src/core/backtest/compare.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,gDAAgD;AAChD,MAAM,WAAW,aAAa;IAC5B,uDAAuD;IACvD,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,SAAS;QAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC;QACvF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;KACzB,EAAE,CAAC;IACJ,QAAQ,CAAC,MAAM,EAAE,SAAS;QACxB,0BAA0B;QAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;KACxB,EAAE,CAAC;IACJ,yDAAyD;IACzD,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,iEAAiE;IACjE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAuCD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,GAAG,aAAa,CAa9E"}
1
+ {"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../../../src/core/backtest/compare.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,gDAAgD;AAChD,MAAM,WAAW,aAAa;IAC5B,uDAAuD;IACvD,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,SAAS;QAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC;QACvF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;KACzB,EAAE,CAAC;IACJ,QAAQ,CAAC,MAAM,EAAE,SAAS;QACxB,0BAA0B;QAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;KACxB,EAAE,CAAC;IACJ,yDAAyD;IACzD,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,iEAAiE;IACjE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAyCD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,GAAG,aAAa,CAa9E"}
@@ -28,6 +28,8 @@ const COMPARED = [
28
28
  'maxDrawdown',
29
29
  'maxDrawdownPercent',
30
30
  'longestDrawdownBars',
31
+ 'maxRunUp',
32
+ 'maxRunUpPercent',
31
33
  'averageBarsHeld',
32
34
  'barsInMarket',
33
35
  'barCount',
@@ -1 +1 @@
1
- {"version":3,"file":"compare.js","sourceRoot":"","sources":["../../../src/core/backtest/compare.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AA2BhD;;;;;;;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are one correspondence: a case names an
5
+ * order by an ordinal and an engine knows it by an id, so `Delivery` reads an
6
+ * ordinal into the id of the intent the run placed, and `framedAs` writes an id
7
+ * back out as the ordinal a case file prints. Split between two files, the two
8
+ * halves of it drift, and a suite whose rows say one thing and whose records
9
+ * say another is one nobody can read.
10
+ *
11
+ * `conformance.md` section 3: `frames.csv` supplies order frames the way
12
+ * `bars.csv` supplies bars, so a strategy case asserts the fold against input
13
+ * the engine did not choose. `simulate.ts` is the other destination this module
14
+ * has, the one that reads a bar and works out what a venue would have said.
15
+ * This one works nothing out. It holds the rows a case supplied, hands over the
16
+ * ones each boundary names, and the whole of its behaviour is the mapping
17
+ * between a row and a frame.
18
+ *
19
+ * **An ordinal is what a case can name, and an id is not.** A row names the nth
20
+ * intent the run placed, because no case can know the id an engine minted, so
21
+ * the intents are counted here in the order the run handed them over and the
22
+ * ordinal is read against that count. A row naming an ordinal the run never
23
+ * placed is delivered all the same, carrying an id no run mints: step 1 of
24
+ * `stdlib.md` 17.8 refuses a frame naming no row of the ledger, and that
25
+ * refusal is the ledger's to make. A destination that dropped the row instead
26
+ * would answer nothing at all where section 3 hands an engine a frame about an
27
+ * order its ledger does not hold, and the case would pass by the frame never
28
+ * having arrived.
29
+ *
30
+ * **What a row does not carry, this does not invent.** `host-interface.md` 7.2
31
+ * lets a frame say which instrument and product the destination booked the
32
+ * order under, and the file has no column for either, so neither is stated and
33
+ * the row keeps what its placement put there. The instant is the one the file
34
+ * does carry: a row states one or states `none`, and one that states none
35
+ * leaves `updatedAt` where the placement put it, which is what the fold does
36
+ * with a frame whose destination stated no instant.
37
+ */
38
+ import type { OrderFrame, OrderIntent, RoutedEffect } from '../engine/index.js';
39
+ import type { RecordedFrame } from './record.js';
40
+ /** One frame, the boundary it was handed over at, and the row it came from. */
41
+ export interface Delivered {
42
+ readonly frame: OrderFrame;
43
+ readonly afterBar: number;
44
+ /**
45
+ * The row a case supplied, or null where the run's own destination answered
46
+ * the frame and there is no row until the record is written.
47
+ */
48
+ readonly row: RecordedFrame | null;
49
+ }
50
+ /** Where a run's orders go, and what it is told between two of its bars. */
51
+ export interface Destination {
52
+ /** Step 9: what the strategy decided, on the bar it decided it. */
53
+ route(effect: RoutedEffect, barIndex: number): void;
54
+ /** What this destination hands over at the boundary after `barIndex`. */
55
+ answers(barIndex: number): readonly Delivered[];
56
+ /** Every intent it was handed, in the order it was handed them. */
57
+ readonly intents: readonly OrderIntent[];
58
+ }
59
+ /**
60
+ * A destination holding one case's frames, ready at the boundaries they name.
61
+ *
62
+ * Built before the run rather than during it, because the rows are input: what
63
+ * a boundary hands over was decided by whoever wrote the case and not by
64
+ * anything this run does. The one thing it learns as the run goes is which
65
+ * intent an ordinal names, which only the run can say.
66
+ */
67
+ export declare class Delivery implements Destination {
68
+ readonly intents: OrderIntent[];
69
+ /** The rows of each boundary, in file order, which section 3 fixes as the delivery order. */
70
+ private readonly rows;
71
+ constructor(frames: readonly RecordedFrame[]);
72
+ /** Nothing is decided by an order arriving here: it is counted, and that is all. */
73
+ route(effect: RoutedEffect): void;
74
+ answers(barIndex: number): readonly Delivered[];
75
+ }
76
+ /**
77
+ * The ordinal of every intent, which is how a case names one.
78
+ *
79
+ * One, two, three in the order the run placed them, because no engine can know
80
+ * the id another minted and a case that named one would only ever be readable
81
+ * by the engine that wrote it.
82
+ */
83
+ export declare function ordinalsOf(intents: readonly OrderIntent[]): ReadonlyMap<number, number>;
84
+ /**
85
+ * One delivered frame, in the columns a case file prints.
86
+ *
87
+ * The instant travels with it. `stdlib.md` 17.7 folds `updatedAt` from a
88
+ * frame's `time`, so a driver that dropped the field here wrote a record whose
89
+ * ledger no engine could fold from the record's own frames: it would have
90
+ * nothing to move that field to and would leave it at `placedAt`.
91
+ */
92
+ export declare function framedAs(frame: OrderFrame, afterBar: number, ordinals: ReadonlyMap<number, number>): RecordedFrame;
93
+ //# sourceMappingURL=deliver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deliver.d.ts","sourceRoot":"","sources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EAAE,UAAU,EACjB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GACpC,aAAa,CAWf"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * An id no run mints, which a row naming no intent of this run is delivered
3
+ * under.
4
+ *
5
+ * Ids are counted from one by the ledger that mints them, so nothing below one
6
+ * can name a row and the fold refuses the frame by the rule it refuses every
7
+ * other unknown one by. The alternative was an id of a real row chosen by some
8
+ * rule of this file's own, which would fold a case's frame into whichever order
9
+ * happened to be near it.
10
+ */
11
+ const NO_INTENT = -1;
12
+ /**
13
+ * A destination holding one case's frames, ready at the boundaries they name.
14
+ *
15
+ * Built before the run rather than during it, because the rows are input: what
16
+ * a boundary hands over was decided by whoever wrote the case and not by
17
+ * anything this run does. The one thing it learns as the run goes is which
18
+ * intent an ordinal names, which only the run can say.
19
+ */
20
+ export class Delivery {
21
+ intents = [];
22
+ /** The rows of each boundary, in file order, which section 3 fixes as the delivery order. */
23
+ rows = new Map();
24
+ constructor(frames) {
25
+ for (const row of frames) {
26
+ const at = this.rows.get(row.afterBar);
27
+ if (at === undefined)
28
+ this.rows.set(row.afterBar, [row]);
29
+ else
30
+ at.push(row);
31
+ }
32
+ }
33
+ /** Nothing is decided by an order arriving here: it is counted, and that is all. */
34
+ route(effect) {
35
+ for (const intent of effect.intents)
36
+ this.intents.push(intent);
37
+ }
38
+ answers(barIndex) {
39
+ const due = this.rows.get(barIndex) ?? [];
40
+ return due.map((row) => ({
41
+ frame: frameOf(row, this.intents[row.intent - 1]),
42
+ afterBar: barIndex,
43
+ row,
44
+ }));
45
+ }
46
+ }
47
+ /** One row of a case, as the frame `host-interface.md` 7.2 describes. */
48
+ function frameOf(row, intent) {
49
+ return {
50
+ intentId: intent?.intentId ?? NO_INTENT,
51
+ status: row.status,
52
+ filledQty: row.filledQty,
53
+ avgFillPrice: row.avgFillPrice,
54
+ orderRef: row.orderRef,
55
+ text: row.text,
56
+ time: row.time,
57
+ };
58
+ }
59
+ /**
60
+ * The ordinal of every intent, which is how a case names one.
61
+ *
62
+ * One, two, three in the order the run placed them, because no engine can know
63
+ * the id another minted and a case that named one would only ever be readable
64
+ * by the engine that wrote it.
65
+ */
66
+ export function ordinalsOf(intents) {
67
+ const out = new Map();
68
+ for (const intent of intents) {
69
+ if (!out.has(intent.intentId))
70
+ out.set(intent.intentId, out.size + 1);
71
+ }
72
+ return out;
73
+ }
74
+ /**
75
+ * One delivered frame, in the columns a case file prints.
76
+ *
77
+ * The instant travels with it. `stdlib.md` 17.7 folds `updatedAt` from a
78
+ * frame's `time`, so a driver that dropped the field here wrote a record whose
79
+ * ledger no engine could fold from the record's own frames: it would have
80
+ * nothing to move that field to and would leave it at `placedAt`.
81
+ */
82
+ export function framedAs(frame, afterBar, ordinals) {
83
+ return {
84
+ afterBar,
85
+ intent: ordinals.get(frame.intentId) ?? 0,
86
+ status: frame.status,
87
+ filledQty: frame.filledQty,
88
+ avgFillPrice: frame.avgFillPrice ?? null,
89
+ orderRef: frame.orderRef ?? null,
90
+ text: frame.text ?? null,
91
+ time: frame.time ?? null,
92
+ };
93
+ }
94
+ //# sourceMappingURL=deliver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deliver.js","sourceRoot":"","sources":["../../../src/core/backtest/deliver.ts"],"names":[],"mappings":"AA6DA;;;;;;;;;GASG;AACH,MAAM,SAAS,GAAG,CAAC,CAAC,CAAC;AAErB;;;;;;;GAOG;AACH,MAAM,OAAO,QAAQ;IACV,OAAO,GAAkB,EAAE,CAAC;IACrC,6FAA6F;IAC5E,IAAI,GAAG,IAAI,GAAG,EAA2B,CAAC;IAE3D,YAAY,MAAgC;QAC1C,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;YACzB,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACvC,IAAI,EAAE,KAAK,SAAS;gBAAE,IAAI,CAAC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