openalgo-script 0.2.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 (357) hide show
  1. package/CHANGELOG.md +1198 -0
  2. package/README.md +127 -40
  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/surfaces.d.ts +17 -0
  12. package/dist/adapters/charts/surfaces.d.ts.map +1 -1
  13. package/dist/adapters/charts/tables.js +82 -0
  14. package/dist/adapters/charts/tables.js.map +1 -1
  15. package/dist/adapters/charts/venue.d.ts +73 -0
  16. package/dist/adapters/charts/venue.d.ts.map +1 -0
  17. package/dist/adapters/charts/venue.js +104 -0
  18. package/dist/adapters/charts/venue.js.map +1 -0
  19. package/dist/adapters/codemirror/commands.d.ts +14 -0
  20. package/dist/adapters/codemirror/commands.d.ts.map +1 -0
  21. package/dist/adapters/codemirror/commands.js +52 -0
  22. package/dist/adapters/codemirror/commands.js.map +1 -0
  23. package/dist/adapters/codemirror/completion.d.ts +15 -0
  24. package/dist/adapters/codemirror/completion.d.ts.map +1 -0
  25. package/dist/adapters/codemirror/completion.js +64 -0
  26. package/dist/adapters/codemirror/completion.js.map +1 -0
  27. package/dist/adapters/codemirror/contract.d.ts +156 -0
  28. package/dist/adapters/codemirror/contract.d.ts.map +1 -0
  29. package/dist/adapters/codemirror/contract.js +42 -0
  30. package/dist/adapters/codemirror/contract.js.map +1 -0
  31. package/dist/adapters/codemirror/index.d.ts +43 -0
  32. package/dist/adapters/codemirror/index.d.ts.map +1 -0
  33. package/dist/adapters/codemirror/index.js +8 -0
  34. package/dist/adapters/codemirror/index.js.map +1 -0
  35. package/dist/adapters/codemirror/lint.d.ts +17 -0
  36. package/dist/adapters/codemirror/lint.d.ts.map +1 -0
  37. package/dist/adapters/codemirror/lint.js +62 -0
  38. package/dist/adapters/codemirror/lint.js.map +1 -0
  39. package/dist/adapters/codemirror/positions.d.ts +16 -0
  40. package/dist/adapters/codemirror/positions.d.ts.map +1 -0
  41. package/dist/adapters/codemirror/positions.js +65 -0
  42. package/dist/adapters/codemirror/positions.js.map +1 -0
  43. package/dist/adapters/codemirror/stream.d.ts +23 -0
  44. package/dist/adapters/codemirror/stream.d.ts.map +1 -0
  45. package/dist/adapters/codemirror/stream.js +70 -0
  46. package/dist/adapters/codemirror/stream.js.map +1 -0
  47. package/dist/adapters/codemirror/tokens.d.ts +44 -0
  48. package/dist/adapters/codemirror/tokens.d.ts.map +1 -0
  49. package/dist/adapters/codemirror/tokens.js +34 -0
  50. package/dist/adapters/codemirror/tokens.js.map +1 -0
  51. package/dist/adapters/codemirror/tooltips.d.ts +35 -0
  52. package/dist/adapters/codemirror/tooltips.d.ts.map +1 -0
  53. package/dist/adapters/codemirror/tooltips.js +108 -0
  54. package/dist/adapters/codemirror/tooltips.js.map +1 -0
  55. package/dist/core/accounting/analysis.d.ts +111 -0
  56. package/dist/core/accounting/analysis.d.ts.map +1 -0
  57. package/dist/core/accounting/analysis.js +123 -0
  58. package/dist/core/accounting/analysis.js.map +1 -0
  59. package/dist/core/accounting/charges.d.ts +136 -0
  60. package/dist/core/accounting/charges.d.ts.map +1 -0
  61. package/dist/core/accounting/charges.js +362 -0
  62. package/dist/core/accounting/charges.js.map +1 -0
  63. package/dist/core/accounting/equity.d.ts +191 -0
  64. package/dist/core/accounting/equity.d.ts.map +1 -0
  65. package/dist/core/accounting/equity.js +167 -0
  66. package/dist/core/accounting/equity.js.map +1 -0
  67. package/dist/core/accounting/index.d.ts +46 -0
  68. package/dist/core/accounting/index.d.ts.map +1 -0
  69. package/dist/core/accounting/index.js +37 -0
  70. package/dist/core/accounting/index.js.map +1 -0
  71. package/dist/core/accounting/markers.d.ts +43 -0
  72. package/dist/core/accounting/markers.d.ts.map +1 -0
  73. package/dist/core/accounting/markers.js +64 -0
  74. package/dist/core/accounting/markers.js.map +1 -0
  75. package/dist/core/accounting/monthly.d.ts +52 -0
  76. package/dist/core/accounting/monthly.d.ts.map +1 -0
  77. package/dist/core/accounting/monthly.js +99 -0
  78. package/dist/core/accounting/monthly.js.map +1 -0
  79. package/dist/core/accounting/report.d.ts +41 -0
  80. package/dist/core/accounting/report.d.ts.map +1 -0
  81. package/dist/core/accounting/report.js +65 -0
  82. package/dist/core/accounting/report.js.map +1 -0
  83. package/dist/core/accounting/shapes.d.ts +70 -0
  84. package/dist/core/accounting/shapes.d.ts.map +1 -0
  85. package/dist/core/accounting/shapes.js +21 -0
  86. package/dist/core/accounting/shapes.js.map +1 -0
  87. package/dist/core/accounting/statistics.d.ts +87 -0
  88. package/dist/core/accounting/statistics.d.ts.map +1 -0
  89. package/dist/core/accounting/statistics.js +268 -0
  90. package/dist/core/accounting/statistics.js.map +1 -0
  91. package/dist/core/accounting/trades.d.ts +118 -0
  92. package/dist/core/accounting/trades.d.ts.map +1 -0
  93. package/dist/core/accounting/trades.js +186 -0
  94. package/dist/core/accounting/trades.js.map +1 -0
  95. package/dist/core/backtest/case.d.ts +60 -0
  96. package/dist/core/backtest/case.d.ts.map +1 -0
  97. package/dist/core/backtest/case.js +319 -0
  98. package/dist/core/backtest/case.js.map +1 -0
  99. package/dist/core/backtest/compare.d.ts +38 -0
  100. package/dist/core/backtest/compare.d.ts.map +1 -0
  101. package/dist/core/backtest/compare.js +191 -0
  102. package/dist/core/backtest/compare.js.map +1 -0
  103. package/dist/core/backtest/declaration.d.ts +52 -0
  104. package/dist/core/backtest/declaration.d.ts.map +1 -0
  105. package/dist/core/backtest/declaration.js +48 -0
  106. package/dist/core/backtest/declaration.js.map +1 -0
  107. package/dist/core/backtest/deliver.d.ts +93 -0
  108. package/dist/core/backtest/deliver.d.ts.map +1 -0
  109. package/dist/core/backtest/deliver.js +94 -0
  110. package/dist/core/backtest/deliver.js.map +1 -0
  111. package/dist/core/backtest/drive.d.ts +87 -0
  112. package/dist/core/backtest/drive.d.ts.map +1 -0
  113. package/dist/core/backtest/drive.js +312 -0
  114. package/dist/core/backtest/drive.js.map +1 -0
  115. package/dist/core/backtest/index.d.ts +58 -0
  116. package/dist/core/backtest/index.d.ts.map +1 -0
  117. package/dist/core/backtest/index.js +47 -0
  118. package/dist/core/backtest/index.js.map +1 -0
  119. package/dist/core/backtest/range.d.ts +84 -0
  120. package/dist/core/backtest/range.d.ts.map +1 -0
  121. package/dist/core/backtest/range.js +90 -0
  122. package/dist/core/backtest/range.js.map +1 -0
  123. package/dist/core/backtest/record.d.ts +299 -0
  124. package/dist/core/backtest/record.d.ts.map +1 -0
  125. package/dist/core/backtest/record.js +243 -0
  126. package/dist/core/backtest/record.js.map +1 -0
  127. package/dist/core/backtest/replay.d.ts +48 -0
  128. package/dist/core/backtest/replay.d.ts.map +1 -0
  129. package/dist/core/backtest/replay.js +137 -0
  130. package/dist/core/backtest/replay.js.map +1 -0
  131. package/dist/core/backtest/resting.d.ts +62 -0
  132. package/dist/core/backtest/resting.d.ts.map +1 -0
  133. package/dist/core/backtest/resting.js +59 -0
  134. package/dist/core/backtest/resting.js.map +1 -0
  135. package/dist/core/backtest/settings.d.ts +117 -0
  136. package/dist/core/backtest/settings.d.ts.map +1 -0
  137. package/dist/core/backtest/settings.js +207 -0
  138. package/dist/core/backtest/settings.js.map +1 -0
  139. package/dist/core/backtest/simulate.d.ts +258 -0
  140. package/dist/core/backtest/simulate.d.ts.map +1 -0
  141. package/dist/core/backtest/simulate.js +335 -0
  142. package/dist/core/backtest/simulate.js.map +1 -0
  143. package/dist/core/catalogue/catalogue.generated.d.ts +66 -0
  144. package/dist/core/catalogue/catalogue.generated.d.ts.map +1 -1
  145. package/dist/core/catalogue/catalogue.generated.js +6 -0
  146. package/dist/core/catalogue/catalogue.generated.js.map +1 -1
  147. package/dist/core/catalogue/values.generated.d.ts +24 -0
  148. package/dist/core/catalogue/values.generated.d.ts.map +1 -1
  149. package/dist/core/check/index.d.ts +2 -1
  150. package/dist/core/check/index.d.ts.map +1 -1
  151. package/dist/core/check/index.js +1 -1
  152. package/dist/core/check/index.js.map +1 -1
  153. package/dist/core/check/library-orders.js +2 -2
  154. package/dist/core/check/library-orders.js.map +1 -1
  155. package/dist/core/check/library-prose.generated.d.ts +16 -0
  156. package/dist/core/check/library-prose.generated.d.ts.map +1 -0
  157. package/dist/core/check/library-prose.generated.js +353 -0
  158. package/dist/core/check/library-prose.generated.js.map +1 -0
  159. package/dist/core/check/surface.d.ts +24 -0
  160. package/dist/core/check/surface.d.ts.map +1 -1
  161. package/dist/core/check/surface.js +29 -0
  162. package/dist/core/check/surface.js.map +1 -1
  163. package/dist/core/emit/canonical.d.ts +22 -8
  164. package/dist/core/emit/canonical.d.ts.map +1 -1
  165. package/dist/core/emit/canonical.js +67 -6
  166. package/dist/core/emit/canonical.js.map +1 -1
  167. package/dist/core/emit/defaults.d.ts +35 -16
  168. package/dist/core/emit/defaults.d.ts.map +1 -1
  169. package/dist/core/emit/defaults.js +66 -0
  170. package/dist/core/emit/defaults.js.map +1 -1
  171. package/dist/core/emit/index.d.ts +2 -0
  172. package/dist/core/emit/index.d.ts.map +1 -1
  173. package/dist/core/emit/index.js +2 -0
  174. package/dist/core/emit/index.js.map +1 -1
  175. package/dist/core/engine/arithmetic.d.ts +6 -25
  176. package/dist/core/engine/arithmetic.d.ts.map +1 -1
  177. package/dist/core/engine/arithmetic.js +48 -3
  178. package/dist/core/engine/arithmetic.js.map +1 -1
  179. package/dist/core/engine/index.d.ts +2 -2
  180. package/dist/core/engine/index.d.ts.map +1 -1
  181. package/dist/core/engine/index.js +2 -2
  182. package/dist/core/engine/index.js.map +1 -1
  183. package/dist/core/engine/library/arrays.d.ts.map +1 -1
  184. package/dist/core/engine/library/arrays.js +8 -2
  185. package/dist/core/engine/library/arrays.js.map +1 -1
  186. package/dist/core/engine/library/code-points.d.ts +40 -0
  187. package/dist/core/engine/library/code-points.d.ts.map +1 -0
  188. package/dist/core/engine/library/code-points.js +74 -0
  189. package/dist/core/engine/library/code-points.js.map +1 -0
  190. package/dist/core/engine/library/index.d.ts +5 -0
  191. package/dist/core/engine/library/index.d.ts.map +1 -1
  192. package/dist/core/engine/library/index.js +5 -0
  193. package/dist/core/engine/library/index.js.map +1 -1
  194. package/dist/core/engine/library/text.d.ts.map +1 -1
  195. package/dist/core/engine/library/text.js +51 -34
  196. package/dist/core/engine/library/text.js.map +1 -1
  197. package/dist/core/engine/load.d.ts +35 -1
  198. package/dist/core/engine/load.d.ts.map +1 -1
  199. package/dist/core/engine/load.js +63 -0
  200. package/dist/core/engine/load.js.map +1 -1
  201. package/dist/core/engine/verify-tables.d.ts.map +1 -1
  202. package/dist/core/engine/verify-tables.js +41 -0
  203. package/dist/core/engine/verify-tables.js.map +1 -1
  204. package/dist/core/index.d.ts +43 -4
  205. package/dist/core/index.d.ts.map +1 -1
  206. package/dist/core/index.js +23 -2
  207. package/dist/core/index.js.map +1 -1
  208. package/dist/core/stdlib/index.d.ts +1 -1
  209. package/dist/core/stdlib/index.d.ts.map +1 -1
  210. package/dist/core/stdlib/index.js +1 -1
  211. package/dist/core/stdlib/index.js.map +1 -1
  212. package/dist/core/stdlib/maths/index.d.ts +1 -1
  213. package/dist/core/stdlib/maths/index.d.ts.map +1 -1
  214. package/dist/core/stdlib/maths/index.js +1 -1
  215. package/dist/core/stdlib/maths/index.js.map +1 -1
  216. package/dist/core/stdlib/maths/rounding.d.ts +5 -0
  217. package/dist/core/stdlib/maths/rounding.d.ts.map +1 -1
  218. package/dist/core/stdlib/maths/rounding.js +19 -1
  219. package/dist/core/stdlib/maths/rounding.js.map +1 -1
  220. package/dist/core/version/version.generated.d.ts +1 -1
  221. package/dist/core/version/version.generated.js +1 -1
  222. package/dist/editor/complete.d.ts +40 -0
  223. package/dist/editor/complete.d.ts.map +1 -0
  224. package/dist/editor/complete.js +206 -0
  225. package/dist/editor/complete.js.map +1 -0
  226. package/dist/editor/diagnose.d.ts +18 -0
  227. package/dist/editor/diagnose.d.ts.map +1 -0
  228. package/dist/editor/diagnose.js +70 -0
  229. package/dist/editor/diagnose.js.map +1 -0
  230. package/dist/editor/format.d.ts +11 -0
  231. package/dist/editor/format.d.ts.map +1 -0
  232. package/dist/editor/format.js +50 -0
  233. package/dist/editor/format.js.map +1 -0
  234. package/dist/editor/highlight.d.ts +28 -0
  235. package/dist/editor/highlight.d.ts.map +1 -0
  236. package/dist/editor/highlight.js +65 -0
  237. package/dist/editor/highlight.js.map +1 -0
  238. package/dist/editor/hover.d.ts +40 -0
  239. package/dist/editor/hover.d.ts.map +1 -0
  240. package/dist/editor/hover.js +147 -0
  241. package/dist/editor/hover.js.map +1 -0
  242. package/dist/editor/index.d.ts +60 -0
  243. package/dist/editor/index.d.ts.map +1 -0
  244. package/dist/editor/index.js +7 -0
  245. package/dist/editor/index.js.map +1 -0
  246. package/dist/editor/kinds.d.ts +27 -0
  247. package/dist/editor/kinds.d.ts.map +1 -0
  248. package/dist/editor/kinds.js +118 -0
  249. package/dist/editor/kinds.js.map +1 -0
  250. package/dist/editor/layout.d.ts +47 -0
  251. package/dist/editor/layout.d.ts.map +1 -0
  252. package/dist/editor/layout.js +135 -0
  253. package/dist/editor/layout.js.map +1 -0
  254. package/dist/editor/manifest.d.ts +47 -0
  255. package/dist/editor/manifest.d.ts.map +1 -0
  256. package/dist/editor/manifest.js +93 -0
  257. package/dist/editor/manifest.js.map +1 -0
  258. package/dist/editor/reading.d.ts +41 -0
  259. package/dist/editor/reading.d.ts.map +1 -0
  260. package/dist/editor/reading.js +51 -0
  261. package/dist/editor/reading.js.map +1 -0
  262. package/dist/editor/scan.d.ts +26 -0
  263. package/dist/editor/scan.d.ts.map +1 -0
  264. package/dist/editor/scan.js +139 -0
  265. package/dist/editor/scan.js.map +1 -0
  266. package/dist/editor/scope.d.ts +19 -0
  267. package/dist/editor/scope.d.ts.map +1 -0
  268. package/dist/editor/scope.js +99 -0
  269. package/dist/editor/scope.js.map +1 -0
  270. package/dist/editor/signature.d.ts +38 -0
  271. package/dist/editor/signature.d.ts.map +1 -0
  272. package/dist/editor/signature.js +112 -0
  273. package/dist/editor/signature.js.map +1 -0
  274. package/dist/editor/site.d.ts +46 -0
  275. package/dist/editor/site.d.ts.map +1 -0
  276. package/dist/editor/site.js +184 -0
  277. package/dist/editor/site.js.map +1 -0
  278. package/dist/editor/spacing.d.ts +29 -0
  279. package/dist/editor/spacing.d.ts.map +1 -0
  280. package/dist/editor/spacing.js +116 -0
  281. package/dist/editor/spacing.js.map +1 -0
  282. package/package.json +42 -3
  283. package/spec/README.md +2 -1
  284. package/spec/errors.json +141 -1
  285. package/src/adapters/charts/driving.ts +109 -0
  286. package/src/adapters/charts/run.ts +120 -28
  287. package/src/adapters/charts/surfaces.ts +17 -0
  288. package/src/adapters/charts/tables.ts +88 -0
  289. package/src/adapters/charts/venue.ts +132 -0
  290. package/src/adapters/codemirror/commands.ts +53 -0
  291. package/src/adapters/codemirror/completion.ts +74 -0
  292. package/src/adapters/codemirror/contract.ts +156 -0
  293. package/src/adapters/codemirror/index.ts +66 -0
  294. package/src/adapters/codemirror/lint.ts +66 -0
  295. package/src/adapters/codemirror/positions.ts +79 -0
  296. package/src/adapters/codemirror/stream.ts +87 -0
  297. package/src/adapters/codemirror/tokens.ts +64 -0
  298. package/src/adapters/codemirror/tooltips.ts +113 -0
  299. package/src/core/accounting/analysis.ts +188 -0
  300. package/src/core/accounting/charges.ts +452 -0
  301. package/src/core/accounting/equity.ts +314 -0
  302. package/src/core/accounting/index.ts +51 -0
  303. package/src/core/accounting/markers.ts +95 -0
  304. package/src/core/accounting/monthly.ts +137 -0
  305. package/src/core/accounting/report.ts +94 -0
  306. package/src/core/accounting/shapes.ts +73 -0
  307. package/src/core/accounting/statistics.ts +387 -0
  308. package/src/core/accounting/trades.ts +313 -0
  309. package/src/core/backtest/case.ts +395 -0
  310. package/src/core/backtest/compare.ts +246 -0
  311. package/src/core/backtest/declaration.ts +97 -0
  312. package/src/core/backtest/deliver.ts +161 -0
  313. package/src/core/backtest/drive.ts +468 -0
  314. package/src/core/backtest/index.ts +64 -0
  315. package/src/core/backtest/range.ts +137 -0
  316. package/src/core/backtest/record.ts +470 -0
  317. package/src/core/backtest/replay.ts +168 -0
  318. package/src/core/backtest/resting.ts +125 -0
  319. package/src/core/backtest/settings.ts +280 -0
  320. package/src/core/backtest/simulate.ts +499 -0
  321. package/src/core/catalogue/catalogue.generated.ts +6 -0
  322. package/src/core/catalogue/values.generated.ts +6 -0
  323. package/src/core/check/index.ts +3 -0
  324. package/src/core/check/library-orders.ts +2 -2
  325. package/src/core/check/library-prose.generated.ts +367 -0
  326. package/src/core/check/surface.ts +34 -0
  327. package/src/core/emit/canonical.ts +67 -9
  328. package/src/core/emit/defaults.ts +70 -0
  329. package/src/core/emit/index.ts +2 -0
  330. package/src/core/engine/arithmetic.ts +23 -3
  331. package/src/core/engine/index.ts +2 -2
  332. package/src/core/engine/library/arrays.ts +8 -2
  333. package/src/core/engine/library/code-points.ts +73 -0
  334. package/src/core/engine/library/index.ts +6 -0
  335. package/src/core/engine/library/text.ts +53 -35
  336. package/src/core/engine/load.ts +84 -2
  337. package/src/core/engine/verify-tables.ts +43 -0
  338. package/src/core/index.ts +100 -2
  339. package/src/core/stdlib/index.ts +1 -0
  340. package/src/core/stdlib/maths/index.ts +1 -0
  341. package/src/core/stdlib/maths/rounding.ts +23 -1
  342. package/src/core/version/version.generated.ts +1 -1
  343. package/src/editor/complete.ts +266 -0
  344. package/src/editor/diagnose.ts +71 -0
  345. package/src/editor/format.ts +85 -0
  346. package/src/editor/highlight.ts +110 -0
  347. package/src/editor/hover.ts +199 -0
  348. package/src/editor/index.ts +65 -0
  349. package/src/editor/kinds.ts +157 -0
  350. package/src/editor/layout.ts +189 -0
  351. package/src/editor/manifest.ts +119 -0
  352. package/src/editor/reading.ts +69 -0
  353. package/src/editor/scan.ts +162 -0
  354. package/src/editor/scope.ts +122 -0
  355. package/src/editor/signature.ts +150 -0
  356. package/src/editor/site.ts +233 -0
  357. package/src/editor/spacing.ts +132 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tooltips.js","sourceRoot":"","sources":["../../../src/adapters/codemirror/tooltips.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGzD,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAO9D;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,IAAW;IACpC,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC;IACnC,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS;QAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzD,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS;QAAE,KAAK,CAAC,IAAI,CAAC,gBAAgB,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACzE,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS;QAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzD,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;QAAE,KAAK,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;IAC5E,OAAO,KAAK,CAAC;AACf,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,cAAc,CAAC,IAAmB;IAChD,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5C,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,MAA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AAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;YACnD,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC;SAC5B,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,0BAA0B,CACxC,MAA+B;IAE/B,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,MAAM,IAAI,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC9C,MAAM,EAAE,GAAG,gBAAgB,CAAC,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7D,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACvC,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC;QACrC,OAAO;YACL,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI;YAC9B,KAAK,EAAE,IAAI;YACX,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC;SAC5B,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,111 @@
1
+ /**
2
+ * The trades taken apart: by direction, by extreme, and by run.
3
+ *
4
+ * The summary answers what the whole run did. Three questions it cannot answer
5
+ * are asked here, and each of them is a question about whether the summary
6
+ * means what it looks like it means.
7
+ *
8
+ * **Which side made the money.** A run whose long trades paid for its short
9
+ * ones reports a healthy net and is two strategies, one of which is losing. The
10
+ * summary cannot show that, because every figure in it is folded over both
11
+ * sides at once. Splitting it is not a refinement of the headline number, it is
12
+ * the first thing that can contradict it.
13
+ *
14
+ * **Whether one trade is the result.** A hundred trades and a profit factor of
15
+ * two reads as an edge until the largest win is the whole of the net. The
16
+ * expectancy's standard error already says how wide the spread is; the largest
17
+ * win and the largest loss say where the width came from, which is the part a
18
+ * reader can act on.
19
+ *
20
+ * **What the run of losses was.** The deepest drawdown is a money figure and
21
+ * the longest one is a bar count, and neither is the number that actually stops
22
+ * somebody trading a strategy. That number is how many times in a row it was
23
+ * wrong. It is not derivable from anything in the summary: the same win rate
24
+ * over the same trades gives a streak of two or a streak of eleven depending on
25
+ * an ordering the summary folds away.
26
+ *
27
+ * ## Every figure here is over closed trades, and that is the whole rule
28
+ *
29
+ * An open trade has no net to win or lose by, so it is in none of these counts,
30
+ * on either side, in no streak and in no extreme. `statistics.ts` has three
31
+ * different answers to which trades a figure is counted over, because a summary
32
+ * carries a capital figure and a bar count that are facts about the run rather
33
+ * than about its trades. Nothing here is a fact about the run, so there is one
34
+ * answer, and a reader can hold it.
35
+ *
36
+ * The consequence worth stating: `longCount + shortCount` is `tradeCount` and
37
+ * not the length of the list folded. A run holding an open position reports
38
+ * fewer trades here than it has, and the summary's `openTradeCount` is where
39
+ * the difference is accounted for.
40
+ */
41
+ import type { Money } from './shapes.js';
42
+ import type { Trade } from './trades.js';
43
+ /** One direction's own figures, folded over that side's closed trades. */
44
+ export interface SideAnalysis {
45
+ readonly count: number;
46
+ readonly wins: number;
47
+ readonly losses: number;
48
+ /** Exactly zero net, counted in neither half, as in the summary. */
49
+ readonly scratches: number;
50
+ /** Net after charges, which is the figure the sides are compared on. */
51
+ readonly netProfit: Money;
52
+ /** `wins / (wins + losses)`, null where this side decided nothing. */
53
+ readonly winRate: number | null;
54
+ }
55
+ /**
56
+ * The trades by direction, by extreme and by run.
57
+ *
58
+ * `long` and `short` partition the closed trades, so their counts sum to the
59
+ * summary's `tradeCount` and their nets sum to its `netProfit`. That is
60
+ * asserted rather than assumed, because a partition that stops partitioning is
61
+ * the defect this shape exists to make visible and it would otherwise show up
62
+ * as two panels that quietly disagree.
63
+ */
64
+ export interface TradeAnalysis {
65
+ readonly long: SideAnalysis;
66
+ readonly short: SideAnalysis;
67
+ /**
68
+ * The best closed trade's net, zero where none closed and zero where every
69
+ * closed trade lost.
70
+ *
71
+ * Zero rather than null, and it is the one place here that is worth arguing
72
+ * about. A run whose every trade lost has no winning trade to name, and null
73
+ * would say so. It reports zero because the figure is read beside
74
+ * `largestLoss` and against `netProfit`, and a null in a column of money
75
+ * forces every reader of the report to handle a case that means "nothing
76
+ * won", which is what zero already means in this column.
77
+ */
78
+ readonly largestWin: Money;
79
+ /** The worst closed trade's net as a positive magnitude, zero where none lost. */
80
+ readonly largestLoss: Money;
81
+ /**
82
+ * The longest run of consecutive winning closed trades, in the order they
83
+ * closed.
84
+ *
85
+ * In the order they closed, and not the order they opened, because that is
86
+ * the order the account experienced them in and the streak is a fact about
87
+ * what the account experienced. The two orders differ whenever a trade is
88
+ * held across another one's whole life, which is every scaling strategy.
89
+ */
90
+ readonly maxConsecutiveWins: number;
91
+ /** The same, for losses. */
92
+ readonly maxConsecutiveLosses: number;
93
+ }
94
+ /**
95
+ * One pass over the closed trades, in closing order.
96
+ *
97
+ * The list arrives in opening order, which is what the equity fold needs and
98
+ * what `tradesOf` produces. The streaks need closing order, so the closed
99
+ * trades are ordered here rather than anywhere else: reordering the list the
100
+ * caller holds would change the equity curve, and taking a second list in
101
+ * opening order and calling its streaks correct would be the defect this
102
+ * function is supposed to have caught.
103
+ *
104
+ * A trade whose net is exactly zero is a scratch, which is the summary's rule
105
+ * and is applied here for the same reason. A scratch **breaks** a streak
106
+ * without extending either one: a strategy that went right, flat, right was not
107
+ * right twice running, and counting the flat trade as either would make the
108
+ * streak a figure that depends on a rounding at the last digit.
109
+ */
110
+ export declare function analysisOf(trades: readonly Trade[]): TradeAnalysis;
111
+ //# sourceMappingURL=analysis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analysis.d.ts","sourceRoot":"","sources":["../../../src/core/accounting/analysis.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,0EAA0E;AAC1E,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,oEAAoE;IACpE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,wEAAwE;IACxE,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC;IAC1B,sEAAsE;IACtE,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC;IAC3B,kFAAkF;IAClF,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC;IAC5B;;;;;;;;OAQG;IACH,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,4BAA4B;IAC5B,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;CACvC;AA2BD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,GAAG,aAAa,CAiDlE"}
@@ -0,0 +1,123 @@
1
+ /**
2
+ * The trades taken apart: by direction, by extreme, and by run.
3
+ *
4
+ * The summary answers what the whole run did. Three questions it cannot answer
5
+ * are asked here, and each of them is a question about whether the summary
6
+ * means what it looks like it means.
7
+ *
8
+ * **Which side made the money.** A run whose long trades paid for its short
9
+ * ones reports a healthy net and is two strategies, one of which is losing. The
10
+ * summary cannot show that, because every figure in it is folded over both
11
+ * sides at once. Splitting it is not a refinement of the headline number, it is
12
+ * the first thing that can contradict it.
13
+ *
14
+ * **Whether one trade is the result.** A hundred trades and a profit factor of
15
+ * two reads as an edge until the largest win is the whole of the net. The
16
+ * expectancy's standard error already says how wide the spread is; the largest
17
+ * win and the largest loss say where the width came from, which is the part a
18
+ * reader can act on.
19
+ *
20
+ * **What the run of losses was.** The deepest drawdown is a money figure and
21
+ * the longest one is a bar count, and neither is the number that actually stops
22
+ * somebody trading a strategy. That number is how many times in a row it was
23
+ * wrong. It is not derivable from anything in the summary: the same win rate
24
+ * over the same trades gives a streak of two or a streak of eleven depending on
25
+ * an ordering the summary folds away.
26
+ *
27
+ * ## Every figure here is over closed trades, and that is the whole rule
28
+ *
29
+ * An open trade has no net to win or lose by, so it is in none of these counts,
30
+ * on either side, in no streak and in no extreme. `statistics.ts` has three
31
+ * different answers to which trades a figure is counted over, because a summary
32
+ * carries a capital figure and a bar count that are facts about the run rather
33
+ * than about its trades. Nothing here is a fact about the run, so there is one
34
+ * answer, and a reader can hold it.
35
+ *
36
+ * The consequence worth stating: `longCount + shortCount` is `tradeCount` and
37
+ * not the length of the list folded. A run holding an open position reports
38
+ * fewer trades here than it has, and the summary's `openTradeCount` is where
39
+ * the difference is accounted for.
40
+ */
41
+ function emptySide() {
42
+ return { count: 0, wins: 0, losses: 0, scratches: 0, netProfit: 0 };
43
+ }
44
+ function sideOf(tally) {
45
+ const decided = tally.wins + tally.losses;
46
+ return {
47
+ count: tally.count,
48
+ wins: tally.wins,
49
+ losses: tally.losses,
50
+ scratches: tally.scratches,
51
+ netProfit: tally.netProfit,
52
+ winRate: decided === 0 ? null : tally.wins / decided,
53
+ };
54
+ }
55
+ /**
56
+ * One pass over the closed trades, in closing order.
57
+ *
58
+ * The list arrives in opening order, which is what the equity fold needs and
59
+ * what `tradesOf` produces. The streaks need closing order, so the closed
60
+ * trades are ordered here rather than anywhere else: reordering the list the
61
+ * caller holds would change the equity curve, and taking a second list in
62
+ * opening order and calling its streaks correct would be the defect this
63
+ * function is supposed to have caught.
64
+ *
65
+ * A trade whose net is exactly zero is a scratch, which is the summary's rule
66
+ * and is applied here for the same reason. A scratch **breaks** a streak
67
+ * without extending either one: a strategy that went right, flat, right was not
68
+ * right twice running, and counting the flat trade as either would make the
69
+ * streak a figure that depends on a rounding at the last digit.
70
+ */
71
+ export function analysisOf(trades) {
72
+ const long = emptySide();
73
+ const short = emptySide();
74
+ let largestWin = 0;
75
+ let largestLoss = 0;
76
+ let maxConsecutiveWins = 0;
77
+ let maxConsecutiveLosses = 0;
78
+ let winStreak = 0;
79
+ let lossStreak = 0;
80
+ const closed = trades.filter((trade) => !trade.isOpen).slice();
81
+ // A trade closes on a bar, and two can close on the same one. The opening
82
+ // order breaks the tie, because it is the order the list arrived in and the
83
+ // only other fact available: a sort that is not total gives two engines two
84
+ // different streaks from one list of trades.
85
+ closed.sort((a, b) => (a.closedOnBar ?? 0) - (b.closedOnBar ?? 0) || a.index - b.index);
86
+ for (const trade of closed) {
87
+ const side = trade.side === 'long' ? long : short;
88
+ side.count += 1;
89
+ side.netProfit += trade.netProfit;
90
+ if (trade.netProfit > 0) {
91
+ side.wins += 1;
92
+ if (trade.netProfit > largestWin)
93
+ largestWin = trade.netProfit;
94
+ winStreak += 1;
95
+ lossStreak = 0;
96
+ if (winStreak > maxConsecutiveWins)
97
+ maxConsecutiveWins = winStreak;
98
+ }
99
+ else if (trade.netProfit < 0) {
100
+ side.losses += 1;
101
+ if (-trade.netProfit > largestLoss)
102
+ largestLoss = -trade.netProfit;
103
+ lossStreak += 1;
104
+ winStreak = 0;
105
+ if (lossStreak > maxConsecutiveLosses)
106
+ maxConsecutiveLosses = lossStreak;
107
+ }
108
+ else {
109
+ side.scratches += 1;
110
+ winStreak = 0;
111
+ lossStreak = 0;
112
+ }
113
+ }
114
+ return {
115
+ long: sideOf(long),
116
+ short: sideOf(short),
117
+ largestWin,
118
+ largestLoss,
119
+ maxConsecutiveWins,
120
+ maxConsecutiveLosses,
121
+ };
122
+ }
123
+ //# sourceMappingURL=analysis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AM,CAAC;YACN,IAAI,CAAC,SAAS,IAAI,CAAC,CAAC;YACpB,SAAS,GAAG,CAAC,CAAC;YACd,UAAU,GAAG,CAAC,CAAC;QACjB,CAAC;IACH,CAAC;IAED,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC;QAClB,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC;QACpB,UAAU;QACV,WAAW;QACX,kBAAkB;QAClB,oBAAoB;KACrB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,136 @@
1
+ import type { Diagnostic } from '../diagnostics/index.js';
2
+ import type { Contract, Money, RecordedFill } from './shapes.js';
3
+ /**
4
+ * What a line's rate is measured against.
5
+ *
6
+ * Four bases cover every stack the documentation describes without naming a
7
+ * market: a fraction of turnover, money per unit, money per fill, and a
8
+ * fraction of the lines named before this one, which is the charge on a charge.
9
+ */
10
+ export type ChargeBase = 'turnover' | 'units' | 'order' | 'charges';
11
+ /**
12
+ * Which side of the trade a line applies to.
13
+ *
14
+ * A transaction tax levied on one side is expressed exactly rather than smeared
15
+ * across both fills at half the rate, which is what a reader doing it by hand
16
+ * has to do and what makes their figure disagree with their broker's.
17
+ */
18
+ export type ChargeSide = 'buy' | 'sell' | 'both';
19
+ /** One line of a schedule, applied to one fill. */
20
+ export interface ChargeLine {
21
+ /** The platform's own word. */
22
+ readonly name: string;
23
+ readonly base: ChargeBase;
24
+ readonly side: ChargeSide;
25
+ /**
26
+ * Fraction for turnover and charges, money per unit for units, money for
27
+ * order.
28
+ */
29
+ readonly rate: number;
30
+ /** Floor per application. */
31
+ readonly min: Money | null;
32
+ /** Cap per application. */
33
+ readonly max: Money | null;
34
+ /** Base 'charges' only: names of lines declared before this one. */
35
+ readonly of: readonly string[];
36
+ }
37
+ /** The whole cost model a run was carried out under. */
38
+ export interface ChargeSchedule {
39
+ readonly currency: string;
40
+ readonly digits: number;
41
+ readonly slippageTicks: number;
42
+ /** Applied in order, and order is part of the result. */
43
+ readonly lines: readonly ChargeLine[];
44
+ /**
45
+ * Where the schedule came from.
46
+ *
47
+ * A schedule derived from the declaration is derived again on replay rather
48
+ * than stored, because what the program states is stored once, as the
49
+ * program. A supplied one is the host's choice and travels with the record.
50
+ */
51
+ readonly source: 'declaration' | 'supplied';
52
+ }
53
+ /** What one fill was charged, line by line and in total. */
54
+ export interface ChargeBreakdown {
55
+ readonly lines: readonly {
56
+ readonly name: string;
57
+ readonly amount: Money;
58
+ }[];
59
+ readonly total: Money;
60
+ }
61
+ /**
62
+ * What one fill cost, line by line and in total.
63
+ *
64
+ * **The lines are the arithmetic and the total is the money.** Each line's
65
+ * amount is computed in binary64 and left unrounded, and the per-fill total is
66
+ * rounded once, half to even, to the contract's digits. Rounding each line
67
+ * would round once per line, and two engines rounding in two places disagree in
68
+ * the last bit, which is a failed conformance comparison months later on
69
+ * somebody else's engine. So a reader adding the lines up by hand may land a
70
+ * fraction of the last digit away from the total, and that is the honest way
71
+ * round: the total is the figure the report accumulates.
72
+ *
73
+ * **Half to even, and not the language's own rounding.** `round()` in the
74
+ * language is halves away from zero, because a price a trader reads should
75
+ * agree with what they would write down (`stdlib.md` 8.1). Money folded over
76
+ * thousands of fills is a different question: away from zero biases every exact
77
+ * half upward, and half a unit of the last digit per fill is a bias that grows
78
+ * with the length of the backtest. Two rules, two reasons, both written down.
79
+ *
80
+ * **A line that does not apply to this side is not in the breakdown at all.** A
81
+ * name beside a zero reads as a charge that was levied and came to nothing,
82
+ * which is not what happened, and a later line levied on that name is levied on
83
+ * nothing, which is exactly what a tax on one side of the trade does.
84
+ */
85
+ export declare function chargeFor(schedule: ChargeSchedule, fill: RecordedFill, contract: Contract): ChargeBreakdown;
86
+ /**
87
+ * The declaration's own cost model, as the one schedule this module evaluates.
88
+ *
89
+ * **The declaration is not a second cost engine.** Its three commission
90
+ * spellings are a schedule of one line: a flat fee is a line charged per fill,
91
+ * a per unit fee is a line charged per unit, and a percentage is a line charged
92
+ * on turnover. A second evaluator for the declaration would be the same money
93
+ * computed two ways, and the day the two disagreed the report and the
94
+ * platform's own cost panel would both be defensible.
95
+ *
96
+ * **A commission of zero is no line at all**, rather than a line charging
97
+ * nothing. A zero line would put a name in every breakdown, and it would make a
98
+ * declaration that states no commission indistinguishable from one that states
99
+ * a commission, which is the distinction a run has to make before it accepts a
100
+ * schedule from the host as well.
101
+ *
102
+ * **A flat fee is charged per fill**, which is the one place `language.md` 13.3
103
+ * lets a reasonable person read the words two ways: per order, or per completed
104
+ * round trip. A charge is attributed to the fill that incurred it everywhere in
105
+ * this module, because that is what attributes it to a trade, so a round trip of
106
+ * two fills is charged twice.
107
+ *
108
+ * The currency and the digit count are parameters because neither is the
109
+ * declaration's to state: the declaration's currency is a label and is often
110
+ * left blank, and money rounding is a fact about the contract. A default here
111
+ * would be this module inventing a rounding rule for somebody else's market.
112
+ *
113
+ * `commissionType`'s value set is declared once, in `check/declaration.ts`, and
114
+ * is not restated here: what is below is a mapping from each spelling to the
115
+ * line it means. A program reaching this has been checked, so a fourth spelling
116
+ * cannot arrive, and the spelling that falls through is the declaration's own
117
+ * default rather than a shape this module made up.
118
+ */
119
+ export declare function scheduleFromDeclaration(commission: number, commissionType: string, slippage: number, currency: string, digits: number): ChargeSchedule;
120
+ /**
121
+ * Why this schedule cannot be carried out, or null.
122
+ *
123
+ * **Asked before the first bar, and answered once.** Everything here is a fact
124
+ * about the schedule rather than about any fill, so a run that would produce a
125
+ * number nobody can explain is refused while nothing has been computed and the
126
+ * cost of correcting it is one run. The contract is optional because a schedule
127
+ * is checkable on its own: what it adds is the three questions that need both,
128
+ * which are the currency the money is in, the digits it is rounded to, and the
129
+ * tick a slippage in ticks is measured in.
130
+ *
131
+ * The first problem found is the one reported. A list of everything wrong with
132
+ * a schedule reads as a worse schedule than it is, and it is corrected one line
133
+ * at a time regardless.
134
+ */
135
+ export declare function scheduleProblem(schedule: ChargeSchedule, contract?: Contract | null): Diagnostic | null;
136
+ //# sourceMappingURL=charges.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"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