openalgo-script 0.4.0 → 0.6.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 (359) hide show
  1. package/CHANGELOG.md +1050 -0
  2. package/README.md +111 -27
  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 +89 -16
  10. package/dist/adapters/charts/run.js.map +1 -1
  11. package/dist/adapters/charts/tables.d.ts +6 -19
  12. package/dist/adapters/charts/tables.d.ts.map +1 -1
  13. package/dist/adapters/charts/tables.js.map +1 -1
  14. package/dist/adapters/charts/undrawable.d.ts +4 -0
  15. package/dist/adapters/charts/undrawable.d.ts.map +1 -0
  16. package/dist/adapters/charts/undrawable.js +47 -0
  17. package/dist/adapters/charts/undrawable.js.map +1 -0
  18. package/dist/adapters/charts/venue.d.ts +73 -0
  19. package/dist/adapters/charts/venue.d.ts.map +1 -0
  20. package/dist/adapters/charts/venue.js +104 -0
  21. package/dist/adapters/charts/venue.js.map +1 -0
  22. package/dist/core/accounting/analysis.d.ts +111 -0
  23. package/dist/core/accounting/analysis.d.ts.map +1 -0
  24. package/dist/core/accounting/analysis.js +123 -0
  25. package/dist/core/accounting/analysis.js.map +1 -0
  26. package/dist/core/accounting/equity.d.ts +33 -0
  27. package/dist/core/accounting/equity.d.ts.map +1 -1
  28. package/dist/core/accounting/equity.js +12 -0
  29. package/dist/core/accounting/equity.js.map +1 -1
  30. package/dist/core/accounting/index.d.ts +2 -0
  31. package/dist/core/accounting/index.d.ts.map +1 -1
  32. package/dist/core/accounting/index.js +1 -0
  33. package/dist/core/accounting/index.js.map +1 -1
  34. package/dist/core/accounting/report.d.ts +3 -0
  35. package/dist/core/accounting/report.d.ts.map +1 -1
  36. package/dist/core/accounting/report.js +2 -0
  37. package/dist/core/accounting/report.js.map +1 -1
  38. package/dist/core/accounting/statistics.d.ts +12 -0
  39. package/dist/core/accounting/statistics.d.ts.map +1 -1
  40. package/dist/core/accounting/statistics.js +23 -1
  41. package/dist/core/accounting/statistics.js.map +1 -1
  42. package/dist/core/backtest/case.d.ts +60 -0
  43. package/dist/core/backtest/case.d.ts.map +1 -0
  44. package/dist/core/backtest/case.js +319 -0
  45. package/dist/core/backtest/case.js.map +1 -0
  46. package/dist/core/backtest/compare.d.ts.map +1 -1
  47. package/dist/core/backtest/compare.js +2 -0
  48. package/dist/core/backtest/compare.js.map +1 -1
  49. package/dist/core/backtest/deliver.d.ts +93 -0
  50. package/dist/core/backtest/deliver.d.ts.map +1 -0
  51. package/dist/core/backtest/deliver.js +94 -0
  52. package/dist/core/backtest/deliver.js.map +1 -0
  53. package/dist/core/backtest/drive.d.ts +101 -8
  54. package/dist/core/backtest/drive.d.ts.map +1 -1
  55. package/dist/core/backtest/drive.js +114 -158
  56. package/dist/core/backtest/drive.js.map +1 -1
  57. package/dist/core/backtest/index.d.ts +26 -12
  58. package/dist/core/backtest/index.d.ts.map +1 -1
  59. package/dist/core/backtest/index.js +21 -10
  60. package/dist/core/backtest/index.js.map +1 -1
  61. package/dist/core/backtest/record.d.ts +63 -2
  62. package/dist/core/backtest/record.d.ts.map +1 -1
  63. package/dist/core/backtest/record.js +71 -4
  64. package/dist/core/backtest/record.js.map +1 -1
  65. package/dist/core/backtest/replay.d.ts.map +1 -1
  66. package/dist/core/backtest/replay.js +11 -1
  67. package/dist/core/backtest/replay.js.map +1 -1
  68. package/dist/core/backtest/simulate.d.ts +113 -1
  69. package/dist/core/backtest/simulate.d.ts.map +1 -1
  70. package/dist/core/backtest/simulate.js +123 -5
  71. package/dist/core/backtest/simulate.js.map +1 -1
  72. package/dist/core/backtest/walk.d.ts +39 -0
  73. package/dist/core/backtest/walk.d.ts.map +1 -0
  74. package/dist/core/backtest/walk.js +125 -0
  75. package/dist/core/backtest/walk.js.map +1 -0
  76. package/dist/core/catalogue/catalogue.generated.d.ts +179 -2
  77. package/dist/core/catalogue/catalogue.generated.d.ts.map +1 -1
  78. package/dist/core/catalogue/catalogue.generated.js +19 -2
  79. package/dist/core/catalogue/catalogue.generated.js.map +1 -1
  80. package/dist/core/catalogue/types.d.ts +8 -2
  81. package/dist/core/catalogue/types.d.ts.map +1 -1
  82. package/dist/core/catalogue/values.generated.d.ts +51 -0
  83. package/dist/core/catalogue/values.generated.d.ts.map +1 -1
  84. package/dist/core/check/assigned.d.ts +19 -0
  85. package/dist/core/check/assigned.d.ts.map +1 -0
  86. package/dist/core/check/assigned.js +14 -0
  87. package/dist/core/check/assigned.js.map +1 -0
  88. package/dist/core/check/call-sites.d.ts.map +1 -1
  89. package/dist/core/check/call-sites.js +9 -4
  90. package/dist/core/check/call-sites.js.map +1 -1
  91. package/dist/core/check/calls.d.ts.map +1 -1
  92. package/dist/core/check/calls.js +12 -4
  93. package/dist/core/check/calls.js.map +1 -1
  94. package/dist/core/check/check.d.ts.map +1 -1
  95. package/dist/core/check/check.js +15 -2
  96. package/dist/core/check/check.js.map +1 -1
  97. package/dist/core/check/checker.d.ts +26 -0
  98. package/dist/core/check/checker.d.ts.map +1 -1
  99. package/dist/core/check/checker.js +38 -2
  100. package/dist/core/check/checker.js.map +1 -1
  101. package/dist/core/check/constant.d.ts +16 -0
  102. package/dist/core/check/constant.d.ts.map +1 -1
  103. package/dist/core/check/constant.js +52 -0
  104. package/dist/core/check/constant.js.map +1 -1
  105. package/dist/core/check/deleted.d.ts +3 -0
  106. package/dist/core/check/deleted.d.ts.map +1 -0
  107. package/dist/core/check/deleted.js +109 -0
  108. package/dist/core/check/deleted.js.map +1 -0
  109. package/dist/core/check/expressions.js +1 -1
  110. package/dist/core/check/expressions.js.map +1 -1
  111. package/dist/core/check/library-orders.js +2 -2
  112. package/dist/core/check/library-orders.js.map +1 -1
  113. package/dist/core/check/library-output.d.ts.map +1 -1
  114. package/dist/core/check/library-output.js +1 -0
  115. package/dist/core/check/library-output.js.map +1 -1
  116. package/dist/core/check/library-prose.generated.js +12 -12
  117. package/dist/core/check/library-prose.generated.js.map +1 -1
  118. package/dist/core/check/library.d.ts +7 -0
  119. package/dist/core/check/library.d.ts.map +1 -1
  120. package/dist/core/check/library.js +1 -0
  121. package/dist/core/check/library.js.map +1 -1
  122. package/dist/core/check/surface.d.ts +9 -0
  123. package/dist/core/check/surface.d.ts.map +1 -1
  124. package/dist/core/check/surface.js +13 -0
  125. package/dist/core/check/surface.js.map +1 -1
  126. package/dist/core/emit/canonical.d.ts +22 -8
  127. package/dist/core/emit/canonical.d.ts.map +1 -1
  128. package/dist/core/emit/canonical.js +67 -6
  129. package/dist/core/emit/canonical.js.map +1 -1
  130. package/dist/core/engine/arithmetic.d.ts +6 -25
  131. package/dist/core/engine/arithmetic.d.ts.map +1 -1
  132. package/dist/core/engine/arithmetic.js +48 -3
  133. package/dist/core/engine/arithmetic.js.map +1 -1
  134. package/dist/core/engine/bar-source.d.ts +65 -0
  135. package/dist/core/engine/bar-source.d.ts.map +1 -0
  136. package/dist/core/engine/bar-source.js +58 -0
  137. package/dist/core/engine/bar-source.js.map +1 -0
  138. package/dist/core/engine/engine.d.ts +9 -11
  139. package/dist/core/engine/engine.d.ts.map +1 -1
  140. package/dist/core/engine/engine.js +24 -24
  141. package/dist/core/engine/engine.js.map +1 -1
  142. package/dist/core/engine/guard.d.ts.map +1 -1
  143. package/dist/core/engine/guard.js +10 -0
  144. package/dist/core/engine/guard.js.map +1 -1
  145. package/dist/core/engine/host.d.ts +4 -2
  146. package/dist/core/engine/host.d.ts.map +1 -1
  147. package/dist/core/engine/host.js.map +1 -1
  148. package/dist/core/engine/index.d.ts +2 -1
  149. package/dist/core/engine/index.d.ts.map +1 -1
  150. package/dist/core/engine/index.js +1 -1
  151. package/dist/core/engine/index.js.map +1 -1
  152. package/dist/core/engine/library/arrays.d.ts.map +1 -1
  153. package/dist/core/engine/library/arrays.js +8 -2
  154. package/dist/core/engine/library/arrays.js.map +1 -1
  155. package/dist/core/engine/library/binding.d.ts +2 -0
  156. package/dist/core/engine/library/binding.d.ts.map +1 -1
  157. package/dist/core/engine/library/binding.js.map +1 -1
  158. package/dist/core/engine/library/code-points.d.ts +40 -0
  159. package/dist/core/engine/library/code-points.d.ts.map +1 -0
  160. package/dist/core/engine/library/code-points.js +74 -0
  161. package/dist/core/engine/library/code-points.js.map +1 -0
  162. package/dist/core/engine/library/index.d.ts +13 -0
  163. package/dist/core/engine/library/index.d.ts.map +1 -1
  164. package/dist/core/engine/library/index.js +15 -0
  165. package/dist/core/engine/library/index.js.map +1 -1
  166. package/dist/core/engine/library/objects.d.ts.map +1 -1
  167. package/dist/core/engine/library/objects.js +1 -1
  168. package/dist/core/engine/library/objects.js.map +1 -1
  169. package/dist/core/engine/library/text.d.ts.map +1 -1
  170. package/dist/core/engine/library/text.js +51 -34
  171. package/dist/core/engine/library/text.js.map +1 -1
  172. package/dist/core/engine/load.d.ts +20 -0
  173. package/dist/core/engine/load.d.ts.map +1 -1
  174. package/dist/core/engine/load.js +62 -0
  175. package/dist/core/engine/load.js.map +1 -1
  176. package/dist/core/engine/request-body.d.ts +3 -1
  177. package/dist/core/engine/request-body.d.ts.map +1 -1
  178. package/dist/core/engine/request-body.js +3 -1
  179. package/dist/core/engine/request-body.js.map +1 -1
  180. package/dist/core/engine/request-plan.d.ts +3 -3
  181. package/dist/core/engine/request-plan.js +3 -3
  182. package/dist/core/engine/requests.d.ts +2 -2
  183. package/dist/core/engine/requests.d.ts.map +1 -1
  184. package/dist/core/engine/requests.js +5 -4
  185. package/dist/core/engine/requests.js.map +1 -1
  186. package/dist/core/engine/series.d.ts +18 -6
  187. package/dist/core/engine/series.d.ts.map +1 -1
  188. package/dist/core/engine/series.js +24 -5
  189. package/dist/core/engine/series.js.map +1 -1
  190. package/dist/core/engine/session/record.d.ts +4 -4
  191. package/dist/core/engine/session/record.js +4 -4
  192. package/dist/core/engine/verify-tables.d.ts.map +1 -1
  193. package/dist/core/engine/verify-tables.js +41 -0
  194. package/dist/core/engine/verify-tables.js.map +1 -1
  195. package/dist/core/importer/calls.d.ts +29 -0
  196. package/dist/core/importer/calls.d.ts.map +1 -0
  197. package/dist/core/importer/calls.js +267 -0
  198. package/dist/core/importer/calls.js.map +1 -0
  199. package/dist/core/importer/context.d.ts +118 -0
  200. package/dist/core/importer/context.d.ts.map +1 -0
  201. package/dist/core/importer/context.js +120 -0
  202. package/dist/core/importer/context.js.map +1 -0
  203. package/dist/core/importer/expressions.d.ts +44 -0
  204. package/dist/core/importer/expressions.d.ts.map +1 -0
  205. package/dist/core/importer/expressions.js +223 -0
  206. package/dist/core/importer/expressions.js.map +1 -0
  207. package/dist/core/importer/importer.d.ts +13 -0
  208. package/dist/core/importer/importer.d.ts.map +1 -0
  209. package/dist/core/importer/importer.js +220 -0
  210. package/dist/core/importer/importer.js.map +1 -0
  211. package/dist/core/importer/index.d.ts +20 -0
  212. package/dist/core/importer/index.d.ts.map +1 -0
  213. package/dist/core/importer/index.js +18 -0
  214. package/dist/core/importer/index.js.map +1 -0
  215. package/dist/core/importer/lexer.d.ts +68 -0
  216. package/dist/core/importer/lexer.d.ts.map +1 -0
  217. package/dist/core/importer/lexer.js +207 -0
  218. package/dist/core/importer/lexer.js.map +1 -0
  219. package/dist/core/importer/names.d.ts +41 -0
  220. package/dist/core/importer/names.d.ts.map +1 -0
  221. package/dist/core/importer/names.js +78 -0
  222. package/dist/core/importer/names.js.map +1 -0
  223. package/dist/core/importer/orders.d.ts +8 -0
  224. package/dist/core/importer/orders.d.ts.map +1 -0
  225. package/dist/core/importer/orders.js +332 -0
  226. package/dist/core/importer/orders.js.map +1 -0
  227. package/dist/core/importer/outputs.d.ts +19 -0
  228. package/dist/core/importer/outputs.d.ts.map +1 -0
  229. package/dist/core/importer/outputs.js +266 -0
  230. package/dist/core/importer/outputs.js.map +1 -0
  231. package/dist/core/importer/parser.d.ts +5 -0
  232. package/dist/core/importer/parser.d.ts.map +1 -0
  233. package/dist/core/importer/parser.js +439 -0
  234. package/dist/core/importer/parser.js.map +1 -0
  235. package/dist/core/importer/presence.d.ts +32 -0
  236. package/dist/core/importer/presence.d.ts.map +1 -0
  237. package/dist/core/importer/presence.js +146 -0
  238. package/dist/core/importer/presence.js.map +1 -0
  239. package/dist/core/importer/settle.d.ts +23 -0
  240. package/dist/core/importer/settle.d.ts.map +1 -0
  241. package/dist/core/importer/settle.js +135 -0
  242. package/dist/core/importer/settle.js.map +1 -0
  243. package/dist/core/importer/statements.d.ts +4 -0
  244. package/dist/core/importer/statements.d.ts.map +1 -0
  245. package/dist/core/importer/statements.js +339 -0
  246. package/dist/core/importer/statements.js.map +1 -0
  247. package/dist/core/importer/syntax.d.ts +182 -0
  248. package/dist/core/importer/syntax.d.ts.map +1 -0
  249. package/dist/core/importer/syntax.js +14 -0
  250. package/dist/core/importer/syntax.js.map +1 -0
  251. package/dist/core/importer/table.d.ts +52 -0
  252. package/dist/core/importer/table.d.ts.map +1 -0
  253. package/dist/core/importer/table.js +156 -0
  254. package/dist/core/importer/table.js.map +1 -0
  255. package/dist/core/importer/values.d.ts +27 -0
  256. package/dist/core/importer/values.d.ts.map +1 -0
  257. package/dist/core/importer/values.js +236 -0
  258. package/dist/core/importer/values.js.map +1 -0
  259. package/dist/core/index.d.ts +22 -5
  260. package/dist/core/index.d.ts.map +1 -1
  261. package/dist/core/index.js +19 -3
  262. package/dist/core/index.js.map +1 -1
  263. package/dist/core/stdlib/calendar/civil.d.ts.map +1 -1
  264. package/dist/core/stdlib/calendar/civil.js +5 -2
  265. package/dist/core/stdlib/calendar/civil.js.map +1 -1
  266. package/dist/core/stdlib/index.d.ts +1 -1
  267. package/dist/core/stdlib/index.d.ts.map +1 -1
  268. package/dist/core/stdlib/index.js +1 -1
  269. package/dist/core/stdlib/index.js.map +1 -1
  270. package/dist/core/stdlib/maths/index.d.ts +1 -1
  271. package/dist/core/stdlib/maths/index.d.ts.map +1 -1
  272. package/dist/core/stdlib/maths/index.js +1 -1
  273. package/dist/core/stdlib/maths/index.js.map +1 -1
  274. package/dist/core/stdlib/maths/rounding.d.ts +5 -0
  275. package/dist/core/stdlib/maths/rounding.d.ts.map +1 -1
  276. package/dist/core/stdlib/maths/rounding.js +19 -1
  277. package/dist/core/stdlib/maths/rounding.js.map +1 -1
  278. package/dist/core/version/version.generated.d.ts +1 -1
  279. package/dist/core/version/version.generated.js +1 -1
  280. package/package.json +17 -2
  281. package/spec/README.md +2 -1
  282. package/spec/errors.json +383 -23
  283. package/src/adapters/charts/driving.ts +109 -0
  284. package/src/adapters/charts/run.ts +126 -28
  285. package/src/adapters/charts/tables.ts +6 -19
  286. package/src/adapters/charts/undrawable.ts +51 -0
  287. package/src/adapters/charts/venue.ts +132 -0
  288. package/src/core/accounting/analysis.ts +188 -0
  289. package/src/core/accounting/equity.ts +38 -0
  290. package/src/core/accounting/index.ts +2 -0
  291. package/src/core/accounting/report.ts +5 -0
  292. package/src/core/accounting/statistics.ts +38 -1
  293. package/src/core/backtest/case.ts +395 -0
  294. package/src/core/backtest/compare.ts +2 -0
  295. package/src/core/backtest/deliver.ts +161 -0
  296. package/src/core/backtest/drive.ts +233 -217
  297. package/src/core/backtest/index.ts +26 -12
  298. package/src/core/backtest/record.ts +134 -5
  299. package/src/core/backtest/replay.ts +11 -1
  300. package/src/core/backtest/simulate.ts +201 -6
  301. package/src/core/backtest/walk.ts +182 -0
  302. package/src/core/catalogue/catalogue.generated.ts +19 -2
  303. package/src/core/catalogue/types.ts +8 -2
  304. package/src/core/catalogue/values.generated.ts +16 -0
  305. package/src/core/check/assigned.ts +31 -0
  306. package/src/core/check/call-sites.ts +11 -4
  307. package/src/core/check/calls.ts +13 -4
  308. package/src/core/check/check.ts +14 -2
  309. package/src/core/check/checker.ts +39 -2
  310. package/src/core/check/constant.ts +57 -0
  311. package/src/core/check/deleted.ts +135 -0
  312. package/src/core/check/expressions.ts +1 -1
  313. package/src/core/check/library-orders.ts +2 -2
  314. package/src/core/check/library-output.ts +1 -0
  315. package/src/core/check/library-prose.generated.ts +12 -12
  316. package/src/core/check/library.ts +8 -0
  317. package/src/core/check/surface.ts +16 -0
  318. package/src/core/emit/canonical.ts +67 -9
  319. package/src/core/engine/arithmetic.ts +23 -3
  320. package/src/core/engine/bar-source.ts +113 -0
  321. package/src/core/engine/engine.ts +26 -25
  322. package/src/core/engine/guard.ts +12 -1
  323. package/src/core/engine/host.ts +4 -2
  324. package/src/core/engine/index.ts +2 -1
  325. package/src/core/engine/library/arrays.ts +8 -2
  326. package/src/core/engine/library/binding.ts +2 -0
  327. package/src/core/engine/library/code-points.ts +73 -0
  328. package/src/core/engine/library/index.ts +17 -0
  329. package/src/core/engine/library/objects.ts +1 -6
  330. package/src/core/engine/library/text.ts +53 -35
  331. package/src/core/engine/load.ts +68 -0
  332. package/src/core/engine/request-body.ts +5 -7
  333. package/src/core/engine/request-plan.ts +3 -3
  334. package/src/core/engine/requests.ts +11 -8
  335. package/src/core/engine/series.ts +30 -6
  336. package/src/core/engine/session/record.ts +4 -4
  337. package/src/core/engine/verify-tables.ts +43 -0
  338. package/src/core/importer/calls.ts +274 -0
  339. package/src/core/importer/context.ts +197 -0
  340. package/src/core/importer/expressions.ts +247 -0
  341. package/src/core/importer/importer.ts +226 -0
  342. package/src/core/importer/index.ts +19 -0
  343. package/src/core/importer/lexer.ts +285 -0
  344. package/src/core/importer/names.ts +104 -0
  345. package/src/core/importer/orders.ts +307 -0
  346. package/src/core/importer/outputs.ts +245 -0
  347. package/src/core/importer/parser.ts +436 -0
  348. package/src/core/importer/presence.ts +164 -0
  349. package/src/core/importer/settle.ts +141 -0
  350. package/src/core/importer/statements.ts +331 -0
  351. package/src/core/importer/syntax.ts +144 -0
  352. package/src/core/importer/table.ts +191 -0
  353. package/src/core/importer/values.ts +241 -0
  354. package/src/core/index.ts +29 -2
  355. package/src/core/stdlib/calendar/civil.ts +5 -2
  356. package/src/core/stdlib/index.ts +1 -0
  357. package/src/core/stdlib/maths/index.ts +1 -0
  358. package/src/core/stdlib/maths/rounding.ts +23 -1
  359. package/src/core/version/version.generated.ts +1 -1
@@ -1,4 +1,4 @@
1
- import { canonicalise, programHash, sha256 } from '../emit/index.js';
1
+ import { canonicalNumber, canonicalise, programHash, sha256, sourceHash } from '../emit/index.js';
2
2
  import { VERSION } from '../version/index.js';
3
3
  /**
4
4
  * The revision of this document's own shape.
@@ -8,7 +8,21 @@ import { VERSION } from '../version/index.js';
8
8
  * file alone. It moves when a channel is added or a meaning changes, never when
9
9
  * a figure in a report does.
10
10
  */
11
- export const RECORD_VERSION = 1;
11
+ export const RECORD_VERSION = 4;
12
+ /**
13
+ * The revision each later channel arrived in.
14
+ *
15
+ * A record written before a channel existed reads with that channel absent,
16
+ * and this table is what `recordFromJson` reads it from: one row per channel
17
+ * added since version 1, so the rule for an old record is stated once and
18
+ * grows by a line when the next channel does.
19
+ *
20
+ * `frameTime` is a field of a row rather than a channel of the document, and it
21
+ * is a row here for the same reason the other two are: what a reader has to
22
+ * know is which revision it arrived in. Where the absence is written differs,
23
+ * and that is the reader's business below, not this table's.
24
+ */
25
+ const ADDED_IN = { sourceText: 2, instrument: 3, frameTime: 4 };
12
26
  /** What this engine calls itself in a record it wrote. */
13
27
  const ENGINE_NAME = 'openscript';
14
28
  /**
@@ -23,11 +37,13 @@ export function recordOf(parts) {
23
37
  return {
24
38
  recordVersion: RECORD_VERSION,
25
39
  engine: { name: ENGINE_NAME, version: VERSION },
26
- languageVersion: String(parts.program.openscript.language),
40
+ languageVersion: canonicalNumber(parts.program.openscript.language),
27
41
  program: parts.program,
28
42
  programHash: programHash(parts.program),
29
43
  source: parts.program.source,
44
+ sourceText: textFor(parts),
30
45
  settings: parts.settings,
46
+ instrument: parts.instrument,
31
47
  bars: barsIn(parts.bars, parts.form),
32
48
  frames: parts.frames,
33
49
  fills: parts.fills,
@@ -36,6 +52,24 @@ export function recordOf(parts) {
36
52
  report: parts.report,
37
53
  };
38
54
  }
55
+ /**
56
+ * The source text, checked against the hash the program already carries.
57
+ *
58
+ * A check rather than a promise, and it costs one hash of a few kilobytes. The
59
+ * failure it exists for is quiet: a caller that passes the text of a different
60
+ * revision than the one it compiled produces a case whose script does not make
61
+ * its own expected output, and the engine being tested gets the blame for a
62
+ * disagreement that was in the case all along.
63
+ */
64
+ function textFor(parts) {
65
+ const text = parts.sourceText;
66
+ if (text === undefined)
67
+ return null;
68
+ if (sourceHash(text) !== parts.program.source.hash) {
69
+ throw new Error('openscript: the source text does not hash to the source hash the program carries');
70
+ }
71
+ return text;
72
+ }
39
73
  /**
40
74
  * The bars, held or pointed at, and the same hash either way.
41
75
  *
@@ -122,7 +156,40 @@ export function recordFromJson(text) {
122
156
  if (parsed === null || typeof parsed !== 'object')
123
157
  return null;
124
158
  const record = parsed;
125
- return record.recordVersion === RECORD_VERSION ? record : null;
159
+ const version = record.recordVersion;
160
+ if (typeof version !== 'number' || version < 1 || version > RECORD_VERSION)
161
+ return null;
162
+ // An earlier revision is readable and a later one is not, and the asymmetry
163
+ // is the point. A later revision may mean something by a field this one
164
+ // thinks it knows, which is how a record silently becomes a different run. An
165
+ // earlier one only ever has fewer: every channel it carries means here what
166
+ // it meant there, and the ones added since are absent rather than wrong. So a
167
+ // run stored months ago still reads, which is the whole of what it was stored
168
+ // for, and a channel it never carried reads as absent.
169
+ if (version === RECORD_VERSION)
170
+ return record;
171
+ return {
172
+ ...record,
173
+ sourceText: version >= ADDED_IN.sourceText ? record.sourceText : null,
174
+ instrument: version >= ADDED_IN.instrument ? record.instrument : null,
175
+ frames: version >= ADDED_IN.frameTime ? record.frames : timeless(record.frames),
176
+ };
177
+ }
178
+ /**
179
+ * The frames of a record written before a frame carried an instant.
180
+ *
181
+ * The absence is written on every frame rather than on the record, because the
182
+ * channel is a field of a row: a reader that left the field undefined would
183
+ * hand the case projection an undefined where the column's absent spelling
184
+ * belongs, and the file would read `undefined` back to the next engine. The
185
+ * frames are left as they are when they are not an array, because this is a
186
+ * parse and not a validation and a document this engine did not write is the
187
+ * caller's to trust or not.
188
+ */
189
+ function timeless(frames) {
190
+ if (!Array.isArray(frames))
191
+ return frames;
192
+ return frames.map((frame) => ({ ...frame, time: null }));
126
193
  }
127
194
  /**
128
195
  * One ledger row, flattened into the words a case file prints.
@@ -1 +1 @@
1
- {"version":3,"file":"record.js","sourceRoot":"","sources":["../../../src/core/backtest/record.ts"],"names":[],"mappings":"AA4BA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAGrE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAwG9C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAEhC,0DAA0D;AAC1D,MAAM,WAAW,GAAG,YAAY,CAAC;AAwBjC;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAkB;IACzC,OAAO;QACL,aAAa,EAAE,cAAc;QAC7B,MAAM,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE;QAC/C,eAAe,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC;QAC1D,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,WAAW,EAAE,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC;QACvC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM;QAC5B,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC;QACpC,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,MAAM,EAAE,KAAK,CAAC,MAAM;KACrB,CAAC;AACJ,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AAM,CAAA;CAAE,GAC9C;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAA;CAAE,CAAC;AAE5D;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,GAAE,SAAS,WAAW,EAAE,GAAG,IAAW,GAAG,YAAY,CAoBlG;AAED;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,GAAE,SAAS,WAAW,EAAE,GAAG,IAAW,GAAG,cAAc,CAcnG;AAED,KAAK,UAAU,GACX;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,WAAW,EAAE,CAAA;CAAE,GAC5D;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAA;CAAE,CAAC;AAE5D;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,WAAW,EAAE,GAAG,IAAI,GAAG,UAAU,CAY7F"}
@@ -71,7 +71,17 @@ export function rerun(record, bars = null) {
71
71
  const held = barsOf(record, bars);
72
72
  if (!held.ok)
73
73
  return { ok: false, diagnostic: held.diagnostic };
74
- return backtest(record.program, held.bars, record.settings, { form: record.bars.form });
74
+ // Everything the run depended on, and that includes the two channels that
75
+ // arrived after the sentence above was written. The instrument record is what
76
+ // the engine read at load, so a rerun handed the contract alone runs under
77
+ // different session facts and does not reproduce the bytes; the text is what
78
+ // makes the rerun's record harvestable, and dropping it would turn a record
79
+ // that could become a case into one that cannot, by being rerun.
80
+ return backtest(record.program, held.bars, record.settings, {
81
+ form: record.bars.form,
82
+ ...(record.instrument === null ? {} : { instrument: record.instrument }),
83
+ ...(record.sourceText === null ? {} : { sourceText: record.sourceText }),
84
+ });
75
85
  }
76
86
  /**
77
87
  * The bars a record was made from, proved to be those bars.
@@ -1 +1 @@
1
- {"version":3,"file":"replay.js","sourceRoot":"","sources":["../../../src/core/backtest/replay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAE3E,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAQvC;;;;;;GAMG;AACH,MAAM,UAAU,MAAM,CAAC,MAAiB,EAAE,OAAsC,IAAI;IAClF,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAClC,IAAI,CAAC,IAAI,CAAC,EAAE;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC;IAEhE,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC3D,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC;IAEpE,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACvC,IAAI,CAAC,QAAQ,CAAC,EAAE;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,UAAU,EAAE,CAAC;IAExE,OAAO;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ACjC,CAAC,CAAC;IACH,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC;IACpE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;AACxF,CAAC;AAED,qFAAqF;AACrF,SAAS,UAAU,CAAC,MAAiB,EAAE,QAAwB;IAC7D,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;IACjE,OAAO,uBAAuB,CAC5B,QAAQ,CAAC,UAAU,EACnB,QAAQ,CAAC,cAAc,EACvB,QAAQ,CAAC,QAAQ,EACjB,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EACjC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAChC,CAAC;AACJ,CAAC;AAED,0EAA0E;AAC1E,MAAM,WAAW,GAAuB,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC"}
@@ -30,16 +30,87 @@
30
30
  * intent no row holds and the fold would refuse it. The row a bracket wants is
31
31
  * decision 55 and it is not in this release, so a stop cannot fill here and a
32
32
  * page that says it can is ahead of the engine.
33
+ *
34
+ * **A destination that behaves badly does it on a schedule, stated before the
35
+ * run and never by chance.** Every case harvested before this one ran against a
36
+ * venue that filled every order whole and on time, so two engines were proved
37
+ * to agree about the half of a day that costs nobody anything. The other half
38
+ * is a partial fill, an order arriving in pieces, a rejection, a cancellation,
39
+ * an expiry and a fill that turns up after the order has ended, and
40
+ * `SimulatorOptions.fill` carries the schedule saying which order each of those
41
+ * happens to and at which boundary. There is no random number here and there
42
+ * will not be one: `stdlib.md` 8.2 keeps a script that answers differently on a
43
+ * second run out of a conformance suite, and a venue rolling a die would make
44
+ * every case it wrote unreproducible in the same breath. **An order the
45
+ * schedule names is answered by the schedule and by nothing else**, so a run
46
+ * stating none is the run the cases before this one were harvested from, to the
47
+ * bit, which is what lets this exist at all.
33
48
  */
34
49
  import type { Contract } from '../accounting/index.js';
35
50
  import type { OrderFrame, OrderIntent, RoutedEffect } from '../engine/index.js';
36
51
  import type { RecordedBar } from './record.js';
37
52
  import type { FillPolicy } from './settings.js';
53
+ /**
54
+ * What this destination does to one order, at one boundary.
55
+ *
56
+ * Four words reaching every status of `stdlib.md` 17.7 a host may send. `fill`
57
+ * carries the cumulative quantity, so one word covers the acknowledgement
58
+ * before anything has traded, a fill of part of the order and a fill of the
59
+ * whole of it: `working` and `filled` are that quantity read against the
60
+ * order's own rather than two instructions. The other three are the three ways
61
+ * an order ends carrying less than it asked for, and an engine never handed
62
+ * one has never been asked what it does with the quantity still working.
63
+ */
64
+ export type VenueDoes = 'fill' | 'reject' | 'cancel' | 'expire';
65
+ /** One act of the schedule: what the destination does, to which order, when. */
66
+ export interface VenueAct {
67
+ /**
68
+ * The nth order this destination took, counting from one.
69
+ *
70
+ * Orders and not intents: a bracket is never taken and a cancellation is
71
+ * answered without being held, so neither is counted and neither can be named
72
+ * here. An ordinal for the reason `conformance.md` section 3 gives a case's
73
+ * own frames: nobody writing a schedule knows the id an engine will mint.
74
+ */
75
+ readonly order: number;
76
+ /**
77
+ * Boundaries after the one the order arrived at, `0` being that boundary.
78
+ *
79
+ * Counted from the order rather than stated as a bar index, because the bar
80
+ * a strategy decides an order on moves the moment anything else about the run
81
+ * does, and a schedule in bar indices is one nobody can read back.
82
+ */
83
+ readonly afterBars: number;
84
+ readonly does: VenueDoes;
85
+ /**
86
+ * The cumulative quantity a fill reports, in units, or absent for all of it.
87
+ *
88
+ * Cumulative because a frame is (`stdlib.md` 17.8): `0` is the
89
+ * acknowledgement a venue sends before anything has traded, a number below
90
+ * the order's own is a partial fill, and one at or above it completes the
91
+ * order. A quantity below what this venue has already reported is a stale
92
+ * frame, which a venue really sends and the fold has to swallow, so it is
93
+ * stated here rather than refused.
94
+ */
95
+ readonly units?: number | null;
96
+ /** The destination's own text, which the ledger records against the row. */
97
+ readonly text?: string;
98
+ }
99
+ /**
100
+ * The fill policy, and what this destination does to the orders it names.
101
+ *
102
+ * The schedule sits on the policy because it is the same kind of fact: how this
103
+ * destination decides a fill, chosen before the first bar and carried in the
104
+ * record beside the policy's own version, so a stored run replays as it ran.
105
+ */
106
+ export interface VenuePolicy extends FillPolicy {
107
+ readonly schedule?: readonly VenueAct[];
108
+ }
38
109
  /** What the venue prices against and how it decides a fill. */
39
110
  export interface SimulatorOptions {
40
111
  readonly bars: readonly RecordedBar[];
41
112
  readonly contract: Contract;
42
- readonly fill: FillPolicy;
113
+ readonly fill: VenuePolicy;
43
114
  /** Adverse always, in ticks, applied to a market fill and to a stop. */
44
115
  readonly slippageTicks: number;
45
116
  /** The declaration's own fill rule: where a market order is priced. */
@@ -120,6 +191,47 @@ export declare class Simulator {
120
191
  * than guessed at here, so by this point the unit is one of two.
121
192
  */
122
193
  private complete;
194
+ /**
195
+ * The acts due at this boundary, in the order the schedule stated them.
196
+ *
197
+ * Due is counted from the bar that sent the order, so an act names a moment
198
+ * in the life of its own order rather than a bar of the run. Two acts due
199
+ * together are answered as written, which is how a schedule states a
200
+ * cancellation and the fill that raced it.
201
+ *
202
+ * Liveness is not consulted. An order that has ended can still be spoken
203
+ * about, because the frame that arrives after it ended is the whole reason
204
+ * this is here: `stdlib.md` 17.8's fill after a terminal status, which a
205
+ * venue sends whenever a cancel races a fill and which an engine refusing it
206
+ * loses, leaving a position the strategy cannot see.
207
+ */
208
+ private perform;
209
+ /**
210
+ * A fill the schedule stated, at this bar's close and worsened like any other.
211
+ *
212
+ * **The average is this venue's own, over the cumulative quantity**, the
213
+ * figure `stdlib.md` 17.8 step 3 says the row takes whole. A venue reporting
214
+ * the last piece's price and calling it an average hands the engine a number
215
+ * that is not one, and the engine may not work its own out from two of them,
216
+ * so the lie settles into the ledger and into every trade folded from it.
217
+ *
218
+ * A stated quantity at or below what this venue has already reported adds
219
+ * nothing and moves nothing: that is a repeated or a stale frame, which a real
220
+ * destination sends and the fold has to swallow. It carries the average this
221
+ * venue holds now rather than then, because it keeps no history of its own
222
+ * averages and the fold ignores the price of a frame adding no quantity. A
223
+ * bar with no close prices nothing, so an act due at one says nothing rather
224
+ * than raising a quantity with no price against it, which step 3 refuses.
225
+ */
226
+ private report;
227
+ /**
228
+ * The order's quantity in units, which is what a fill is counted in.
229
+ *
230
+ * The conversion `complete` did inline, wanted in two places the moment a
231
+ * schedule can fill an order in pieces: the whole a piece is measured
232
+ * against has to be the number the fill path would have reported.
233
+ */
234
+ private unitsOf;
123
235
  /**
124
236
  * A price worsened by the slippage the run was carried out under.
125
237
  *
@@ -1 +1 @@
1
- {"version":3,"file":"simulate.d.ts","sourceRoot":"","sources":["../../../src/core/backtest/simulate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAa,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC3F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,+DAA+D;AAC/D,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,SAAS,WAAW,EAAE,CAAC;IACtC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,wEAAwE;IACxE,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,uEAAuE;IACvE,QAAQ,CAAC,MAA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,OAAO,CAAmB;IAC3C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,gFAAgF;IAChF,QAAQ,CAAC,OAAO,EAAE,WAAW,EAAE,CAAM;IACrC,gFAAgF;IAChF,QAAQ,CAAC,QAAQ,EAAE,WAAW,EAAE,CAAM;IACtC,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,QAAQ,CAAoB;IACpC,OAAO,CAAC,IAAI,CAAK;IACjB,OAAO,CAAC,GAAG,CAAK;gBAEJ,OAAO,EAAE,gBAAgB;IAIrC,2DAA2D;IAC3D,KAAK,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAenD;;;;;;OAMG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,UAAU,EAAE;IAyBlD,wEAAwE;IACxE,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,8DAA8D;IAC9D,OAAO,CAAC,MAAM;IAoBd;;;;;;;OAOG;IACH,OAAO,CAAC,QAAQ;IAYhB;;;;;;;;OAQG;IACH,OAAO,CAAC,IAAI;IAuBZ,yCAAyC;IACzC,OAAO,CAAC,MAAM;IAYd;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,QAAQ;IAQhB;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,OAAO;IAiBf;;;;;;;;;;;;;;;;OAgBG;IACH,OAAO,CAAC,MAAM;IAsBd;;;;;;OAMG;IACH,OAAO,CAAC,OAAO;IAMf;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,CAAC,MAAM;IAOd,4DAA4D;IAC5D,OAAO,CAAC,GAAG;CAuBZ"}
@@ -1,6 +1,19 @@
1
1
  import { testResting } from './resting.js';
2
2
  /** `language.md` 13.3: a market order priced at the close of its own bar. */
3
3
  const AT_CLOSE = 'close';
4
+ /**
5
+ * The word this venue reports each ending under.
6
+ *
7
+ * A destination with words of its own maps them onto the vocabulary in its
8
+ * adapter, which is where `stdlib.md` 17.7 puts the mapping because a status
9
+ * vocabulary differs per destination. This is this one's, and the whole of what
10
+ * a schedule's verb means.
11
+ */
12
+ const ENDED = {
13
+ reject: 'rejected',
14
+ cancel: 'cancelled',
15
+ expire: 'expired',
16
+ };
4
17
  /**
5
18
  * A venue, for one run.
6
19
  *
@@ -48,6 +61,14 @@ export class Simulator {
48
61
  const bar = this.options.bars[barIndex];
49
62
  if (bar !== undefined) {
50
63
  for (const order of this.orders) {
64
+ // An order the schedule names is answered by the schedule, whether or
65
+ // not it is still live: a fill after a cancellation is the one thing
66
+ // this exists for and the order is dead by then.
67
+ if (order.acts.length > 0) {
68
+ if (order.placedOn < barIndex)
69
+ this.perform(order, bar, barIndex);
70
+ continue;
71
+ }
51
72
  if (!order.live || order.rest === null || order.placedOn >= barIndex)
52
73
  continue;
53
74
  this.decide(order, bar, barIndex);
@@ -68,12 +89,17 @@ export class Simulator {
68
89
  /** An order the strategy sent, which this venue now holds. */
69
90
  accept(intent, barIndex) {
70
91
  this.refs += 1;
92
+ // The ordinal of this order among the orders taken, which is what an act
93
+ // names. Read before the order joins them, so the first is one.
94
+ const ordinal = this.orders.length + 1;
71
95
  const order = {
72
96
  intent,
73
97
  ref: refOf(this.refs),
74
98
  placedOn: barIndex,
75
99
  rest: restingFor(intent),
100
+ acts: (this.options.fill.schedule ?? []).filter((act) => act.order === ordinal),
76
101
  filledQty: 0,
102
+ avgPrice: null,
77
103
  live: true,
78
104
  triggered: false,
79
105
  };
@@ -110,6 +136,16 @@ export class Simulator {
110
136
  * where it does not.
111
137
  */
112
138
  open(order, barIndex) {
139
+ // A scheduled order is answered by its schedule from its first breath. The
140
+ // acknowledgement below is a thing this venue chooses to say, so a schedule
141
+ // that wants one states it, and one that wants the destination to sit on an
142
+ // order and say nothing gets that instead.
143
+ if (order.acts.length > 0) {
144
+ const bar = this.options.bars[barIndex];
145
+ if (bar !== undefined)
146
+ this.perform(order, bar, barIndex);
147
+ return;
148
+ }
113
149
  this.say(order.intent, order.ref, 'working', 0, null, barIndex);
114
150
  if (order.rest !== null)
115
151
  return;
@@ -150,13 +186,95 @@ export class Simulator {
150
186
  * than guessed at here, so by this point the unit is one of two.
151
187
  */
152
188
  complete(order, price, barIndex) {
153
- const stated = order.intent.qty ?? 0;
154
- const lot = this.options.contract.lotSize;
155
- const qty = this.options.qtyType === 'lots' && lot !== null && lot > 0 ? stated * lot : stated;
189
+ const qty = this.unitsOf(order.intent);
156
190
  order.filledQty = qty;
191
+ order.avgPrice = price;
157
192
  order.live = false;
158
193
  this.say(order.intent, order.ref, 'filled', qty, price, barIndex);
159
194
  }
195
+ /**
196
+ * The acts due at this boundary, in the order the schedule stated them.
197
+ *
198
+ * Due is counted from the bar that sent the order, so an act names a moment
199
+ * in the life of its own order rather than a bar of the run. Two acts due
200
+ * together are answered as written, which is how a schedule states a
201
+ * cancellation and the fill that raced it.
202
+ *
203
+ * Liveness is not consulted. An order that has ended can still be spoken
204
+ * about, because the frame that arrives after it ended is the whole reason
205
+ * this is here: `stdlib.md` 17.8's fill after a terminal status, which a
206
+ * venue sends whenever a cancel races a fill and which an engine refusing it
207
+ * loses, leaving a position the strategy cannot see.
208
+ */
209
+ perform(order, bar, barIndex) {
210
+ for (const act of order.acts) {
211
+ if (order.placedOn + act.afterBars !== barIndex)
212
+ continue;
213
+ if (act.does === 'fill') {
214
+ this.report(order, act, bar, barIndex);
215
+ continue;
216
+ }
217
+ // The order ends, reporting what it filled before it ended, because a
218
+ // frame is cumulative: `stdlib.md` 17.8 has the row keeping the terminal
219
+ // word and the quantity recording what traded, both true at once.
220
+ order.live = false;
221
+ const ended = ENDED[act.does];
222
+ const price = order.filledQty > 0 ? order.avgPrice : null;
223
+ this.say(order.intent, order.ref, ended, order.filledQty, price, barIndex, act.text ?? '');
224
+ }
225
+ }
226
+ /**
227
+ * A fill the schedule stated, at this bar's close and worsened like any other.
228
+ *
229
+ * **The average is this venue's own, over the cumulative quantity**, the
230
+ * figure `stdlib.md` 17.8 step 3 says the row takes whole. A venue reporting
231
+ * the last piece's price and calling it an average hands the engine a number
232
+ * that is not one, and the engine may not work its own out from two of them,
233
+ * so the lie settles into the ledger and into every trade folded from it.
234
+ *
235
+ * A stated quantity at or below what this venue has already reported adds
236
+ * nothing and moves nothing: that is a repeated or a stale frame, which a real
237
+ * destination sends and the fold has to swallow. It carries the average this
238
+ * venue holds now rather than then, because it keeps no history of its own
239
+ * averages and the fold ignores the price of a frame adding no quantity. A
240
+ * bar with no close prices nothing, so an act due at one says nothing rather
241
+ * than raising a quantity with no price against it, which step 3 refuses.
242
+ */
243
+ report(order, act, bar, barIndex) {
244
+ const whole = this.unitsOf(order.intent);
245
+ const stated = act.units ?? whole;
246
+ const delta = stated - order.filledQty;
247
+ if (delta > 0) {
248
+ if (bar.close === null)
249
+ return;
250
+ // Written in this order and left in it: the source order of a sum is
251
+ // what decides its last bit, and a case harvested from this venue is
252
+ // asserted to the bit.
253
+ const price = this.worsen(bar.close, order.intent.side);
254
+ order.avgPrice = ((order.avgPrice ?? 0) * order.filledQty + price * delta) / stated;
255
+ order.filledQty = stated;
256
+ if (order.filledQty >= whole)
257
+ order.live = false;
258
+ }
259
+ // `working` is live and not completely filled, `filled` is the whole
260
+ // quantity: 17.7's two words read off the quantity rather than stated
261
+ // twice by a schedule that could disagree with the number beside them.
262
+ const status = order.filledQty >= whole ? 'filled' : 'working';
263
+ const price = stated > 0 ? order.avgPrice : null;
264
+ this.say(order.intent, order.ref, status, stated, price, barIndex, act.text ?? '');
265
+ }
266
+ /**
267
+ * The order's quantity in units, which is what a fill is counted in.
268
+ *
269
+ * The conversion `complete` did inline, wanted in two places the moment a
270
+ * schedule can fill an order in pieces: the whole a piece is measured
271
+ * against has to be the number the fill path would have reported.
272
+ */
273
+ unitsOf(intent) {
274
+ const stated = intent.qty ?? 0;
275
+ const lot = this.options.contract.lotSize;
276
+ return this.options.qtyType === 'lots' && lot !== null && lot > 0 ? stated * lot : stated;
277
+ }
160
278
  /**
161
279
  * A price worsened by the slippage the run was carried out under.
162
280
  *
@@ -184,7 +302,7 @@ export class Simulator {
184
302
  return side === 'sell' ? price - move : price + move;
185
303
  }
186
304
  /** One frame, cumulative, in the order this venue spoke. */
187
- say(intent, ref, status, filledQty, avgFillPrice, barIndex) {
305
+ say(intent, ref, status, filledQty, avgFillPrice, barIndex, text = '') {
188
306
  this.seq += 1;
189
307
  this.answered.push({
190
308
  intentId: intent.intentId,
@@ -195,7 +313,7 @@ export class Simulator {
195
313
  sentInstrument: intent.instrument,
196
314
  sentProduct: intent.product,
197
315
  time: this.options.bars[barIndex]?.time ?? null,
198
- text: '',
316
+ text,
199
317
  seq: this.seq,
200
318
  });
201
319
  }
@@ -1 +1 @@
1
- {"version":3,"file":"simulate.js","sourceRoot":"","sources":["../../../src/core/backtest/simulate.ts"],"names":[],"mappings":"AAoCA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAoC3C,6EAA6E;AAC7E,MAAM,QAAQ,GAAG,OAAO,CAAC;AAEzB;;;;;;GAMG;AACH,MAAM,OAAO,SAAS;IACH,OAAO,CAAmB;IAC1B,MAAM,GAAY,EAAE,CAAC;IACtC,gFAAgF;IACvE,OAAO,GAAkB,EAAE,CAAC;IACrC,gFAAgF;IACvE,QAAQ,GAAkB,EAAE,CAAC;IAC9B,MAAM,GAAY,EAAE,CAAC;IACrB,QAAQ,GAAiB,EAAE,CAAC;IAC5B,IAAI,GAAG,CAAC,CAAC;IACT,GAAG,GAAG,CAAC,CAAC;IAEhB,YAAY,OAAyB;QACnC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,2DAA2D;IAC3D,KAAK,CAAC,MAAoB,EAAE,QAAgB;QAC1C,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACpC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC1B,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;gBAC9B,I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AM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC;AAED,6EAA6E;AAC7E,SAAS,UAAU,CAAC,MAAmB;IACrC,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAC1F,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;AAChG,CAAC;AAED,6EAA6E;AAC7E,SAAS,OAAO,CAAC,IAAkB;IACjC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC9E,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * One walk of a backtest's bars, with the venue answering between them.
3
+ *
4
+ * Split from `drive.ts`, which sets a run up and writes its record, because the
5
+ * walk is the one part of a backtest that runs once per bar and it is read on its
6
+ * own: the order in which a frame is delivered, a bar appended and its fills
7
+ * folded is the whole of what makes a backtest reproducible.
8
+ */
9
+ import type { RecordedFill } from '../accounting/index.js';
10
+ import type { Engine, Value } from '../engine/index.js';
11
+ import type { Delivered, Destination } from './deliver.js';
12
+ import type { ReportWindow } from './range.js';
13
+ import type { RecordedBar, RecordedDiagnostic } from './record.js';
14
+ /** One line of the script's log, `conformance.md` section 4. */
15
+ export interface LogLine {
16
+ readonly barIndex: number;
17
+ readonly time: number | null;
18
+ readonly value: Value;
19
+ }
20
+ /** What one walk of the bars produced. */
21
+ export interface Walked {
22
+ readonly fills: readonly RecordedFill[];
23
+ readonly frames: readonly Delivered[];
24
+ readonly diagnostics: readonly RecordedDiagnostic[];
25
+ readonly rows: readonly (readonly Value[])[];
26
+ readonly log: readonly LogLine[];
27
+ }
28
+ /**
29
+ * The bars, in order, with the venue answering between them.
30
+ *
31
+ * The one ordering rule: deliver, then append, then collect what the append
32
+ * reported, then ask the venue what this bar did. A driver that asked the venue
33
+ * before appending would price a fill against a bar the strategy had not seen.
34
+ */
35
+ export declare function walk(engine: Engine, destination: Destination, bars: readonly RecordedBar[], covered: ReportWindow, keep: {
36
+ readonly rows?: boolean;
37
+ readonly log?: boolean;
38
+ }): Walked;
39
+ //# sourceMappingURL=walk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"walk.d.ts","sourceRoot":"","sources":["../../../src/core/backtest/walk.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAa,MAAM,EAAwB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACzF,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEnE,gEAAgE;AAChE,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;CACvB;AAED,0CAA0C;AAC1C,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE,CAAC;IACxC,QAAQ,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,CAAC;IACtC,QAAQ,CAAC,WAAW,EAAE,SAAS,kBAAkB,EAAE,CAAC;IACpD,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,KAAK,EAA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