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 @@
1
+ {"version":3,"file":"venue.js","sourceRoot":"","sources":["../../../src/adapters/charts/venue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAMtF;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,OAAwB;IACjD,OAAO,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC7C,CAAC;AAED,2CAA2C;AAC3C,SAAS,QAAQ,CAAC,GAAa;IAC7B,OAAO;QACL,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,MAAM,EAAE,GAAG,CAAC,MAAM,IAAI,IAAI;QAC1B,EAAE,EAAE,GAAG,CAAC,EAAE,IAAI,IAAI;KACnB,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CACtB,OAAwB,EACxB,IAAyB,EACzB,MAAgC,EAChC,UAAkC;IAElC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAC;IAEtC,MAAM,QAAQ,GAAG,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAEhD,OAAO,IAAI,SAAS,CAAC;QACnB,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC;QACxB,QAAQ,EAAE;YACR,MAAM,EAAE,UAAU,EAAE,MAAM,IAAI,IAAI;YAClC,QAAQ,EAAE,UAAU,EAAE,QAAQ,IAAI,IAAI;YACtC,sEAAsE;YACtE,sEAAsE;YACtE,iEAAiE;YACjE,QAAQ,EAAE,QAAQ,CAAC,QAAQ;YAC3B,QAAQ,EAAE,UAAU,EAAE,QAAQ,IAAI,IAAI;YACtC,OAAO,EAAE,IAAI;YACb,UAAU,EAAE,CAAC;YACb,MAAM,EAAE,CAAC;SACV;QACD,IAAI,EAAE,YAAY;QAClB,qEAAqE;QACrE,yDAAyD;QACzD,aAAa,EAAE,QAAQ,CAAC,QAAQ;QAChC,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,OAAO,EAAE,QAAQ,CAAC,OAAO;KAC1B,CAAC,CAAC;AACL,CAAC;AAeD,gFAAgF;AAChF,MAAM,UAAU,UAAU,CAAC,IAAe,EAAE,QAAgB;IAC1D,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;AAChD,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,SAAS,CAAC,MAAqC;IAC7D,6EAA6E;IAC7E,2EAA2E;IAC3E,2EAA2E;IAC3E,OAAO,CAAC,MAAoB,EAAE,GAAW,EAAE,EAAE;QAC3C,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACrC,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.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analysis.js","sourceRoot":"","sources":["../../../src/core/accounting/analysis.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAmEH,SAAS,SAAS;IAChB,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;AACtE,CAAC;AAED,SAAS,MAAM,CAAC,KAAgB;IAC9B,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC;IAC1C,OAAO;QACL,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,OAAO,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,GAAG,OAAO;KACrD,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,UAAU,CAAC,MAAwB;IACjD,MAAM,IAAI,GAAG,SAAS,EAAE,CAAC;IACzB,MAAM,KAAK,GAAG,SAAS,EAAE,CAAC;IAC1B,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,IAAI,kBAAkB,GAAG,CAAC,CAAC;IAC3B,IAAI,oBAAoB,GAAG,CAAC,CAAC;IAC7B,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,IAAI,UAAU,GAAG,CAAC,CAAC;IAEnB,MAAM,MAAM,GAAG,MAAM,C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AAG,oBAAoB;gBAAE,oBAAoB,GAAG,UAAU,CAAC;QAC3E,CAAC;aAAM,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"}
@@ -104,6 +104,33 @@ export interface EquityPoint {
104
104
  readonly drawdown: Money;
105
105
  /** `drawdown / runningPeak`, a fraction and not a figure times a hundred. */
106
106
  readonly drawdownPercent: number;
107
+ /**
108
+ * The distance above the running trough, zero or positive.
109
+ *
110
+ * Drawdown's mirror, and carried for the same reason drawdown is: it is the
111
+ * run's best stretch measured the same way its worst one is, so the two can
112
+ * be read against each other. A reader handed only the depth learns how bad
113
+ * it got and nothing about whether the run ever climbed far enough for that
114
+ * depth to be a giving back rather than a steady bleed.
115
+ */
116
+ readonly runUp: Money;
117
+ /**
118
+ * `runUp / runningTrough`, a fraction and not a figure times a hundred, and
119
+ * zero where the trough is not above zero.
120
+ *
121
+ * Not the same guard drawdown gets, because the two bases are not the same
122
+ * kind of number. The running peak starts at the capital and only ever rises,
123
+ * so a run with capital above zero has a peak above zero at every point. The
124
+ * running trough starts there and only ever falls, so an account that lost
125
+ * everything has a trough at or below zero, and from that bar on this figure
126
+ * is zero rather than a fraction. Zero is the wrong answer for a run that
127
+ * recovered, and it is reported anyway, because the alternative is a
128
+ * percentage against a negative basis: a positive climb reported as a
129
+ * negative fraction, which is the shape that once gave a profit factor of
130
+ * minus a half. `runUp` itself is unaffected and stays the figure to read on
131
+ * such a run.
132
+ */
133
+ readonly runUpPercent: number;
107
134
  }
108
135
  /**
109
136
  * Whether this trade was still held at the close of this bar.
@@ -141,6 +168,12 @@ export declare function ratioOf(value: number, basis: number): number;
141
168
  * The running peak starts at the capital rather than at the first point, so a
142
169
  * run that is down from its first bar is in drawdown at its first bar. Starting
143
170
  * it at the first point would report every run as having begun at its high.
171
+ *
172
+ * The running trough starts at the capital for the same reason and not for a
173
+ * symmetrical one: a run that is up from its first bar has run up from the
174
+ * money it was given, which is the figure a reader is measuring against. Anchor
175
+ * it at the first point instead and a run that gapped up on bar zero reports
176
+ * that gain as having come from nowhere.
144
177
  */
145
178
  export declare function equityOver(trades: readonly Trade[], marks: readonly BarMark[], contract: Contract, capital: Money): readonly EquityPoint[];
146
179
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"equity.d.ts","sourceRoot":"","sources":["../../../src/core/accounting/equity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmFG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,yEAAyE;AACzE,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,yCAAyC;IACzC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC;IACzB,kBAAkB;IAClB,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IACxB,kCAAkC;IAClC,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC;IAC3B,oCAAoC;IACpC,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,yBAAyB;IACzB,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC;IACvB,mDAAmD;IACnD,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC;IACzB,8CAA8C;IAC9C,Q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CAAC;IACxB,kCAAkC;IAClC,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC;IAC3B,oCAAoC;IACpC,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,yBAAyB;IACzB,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC;IACvB,mDAAmD;IACnD,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC;IACzB,8CAA8C;IAC9C,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC;IACzB,6EAA6E;IAC7E,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC;;;;;;;;OAQG;IACH,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAGjE;AAED;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,SAAS,KAAK,EAAE,EACxB,KAAK,EAAE,SAAS,OAAO,EAAE,EACzB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,KAAK,GACb,SAAS,WAAW,EAAE,CAyExB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,SAAS,KAAK,EAAE,EACxB,MAAM,EAAE,SAAS,WAAW,EAAE,GAC7B,MAAM,CAuBR"}
@@ -40,6 +40,12 @@ export function ratioOf(value, basis) {
40
40
  * The running peak starts at the capital rather than at the first point, so a
41
41
  * run that is down from its first bar is in drawdown at its first bar. Starting
42
42
  * it at the first point would report every run as having begun at its high.
43
+ *
44
+ * The running trough starts at the capital for the same reason and not for a
45
+ * symmetrical one: a run that is up from its first bar has run up from the
46
+ * money it was given, which is the figure a reader is measuring against. Anchor
47
+ * it at the first point instead and a run that gapped up on bar zero reports
48
+ * that gain as having come from nowhere.
43
49
  */
44
50
  export function equityOver(trades, marks, contract, capital) {
45
51
  const points = [];
@@ -48,6 +54,7 @@ export function equityOver(trades, marks, contract, capital) {
48
54
  let realised = 0;
49
55
  let charges = 0;
50
56
  let peak = capital;
57
+ let trough = capital;
51
58
  let mark = null;
52
59
  for (const bar of marks) {
53
60
  // Opened by this bar, charges and all. The pointer is why the trades have
@@ -93,7 +100,10 @@ export function equityOver(trades, marks, contract, capital) {
93
100
  const equity = cash + openProfit;
94
101
  if (equity > peak)
95
102
  peak = equity;
103
+ if (equity < trough)
104
+ trough = equity;
96
105
  const drawdown = equity - peak;
106
+ const runUp = equity - trough;
97
107
  points.push({
98
108
  barIndex: bar.barIndex,
99
109
  time: bar.time,
@@ -105,6 +115,8 @@ export function equityOver(trades, marks, contract, capital) {
105
115
  exposure,
106
116
  drawdown,
107
117
  drawdownPercent: ratioOf(drawdown, peak),
118
+ runUp,
119
+ runUpPercent: ratioOf(runUp, trough),
108
120
  });
109
121
  }
110
122
  return points;
@@ -1 +1 @@
1
- {"version":3,"file":"equity.js","sourceRoot":"","sources":["../../../src/core/accounting/equity.ts"],"names":[],"mappings":"AA6GA;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,SAAS,CAAC,KAAY,EAAE,QAAgB;IACtD,IAAI,QAAQ,GAAG,KAAK,CAAC,WAAW;QAAE,OAAO,KAAK,CAAC;IAC/C,OAAO,KAAK,CAAC,WAAW,KAAK,IAAI,IAAI,QAAQ,GAAG,KAAK,CAAC,WAAW,CAAC;AACpE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,OAAO,CAAC,KAAa,EAAE,KAAa;IAClD,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CA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type { MonthlyReturn } from './monthly.js';
38
38
  export { markersOf } from './markers.js';
39
39
  export type { TradeMarker } from './markers.js';
40
+ export { analysisOf } from './analysis.js';
41
+ export type { SideAnalysis, TradeAnalysis } from './analysis.js';
40
42
  export { summaryOf } from './statistics.js';
41
43
  export type { Summary } from './statistics.js';
42
44
  export { reportOf } from './report.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/accounting/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACnF,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC1E,YAAY,EACV,UAAU,EACV,eAAe,EACf,UAAU,EACV,cAAc,EACd,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,YAAY,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/accounting/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACnF,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC1E,YAAY,EACV,UAAU,EACV,eAAe,EACf,UAAU,EACV,cAAc,EACd,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,YAAY,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
@@ -31,6 +31,7 @@ export { tradesOf } from './trades.js';
31
31
  export { equityOver } from './equity.js';
32
32
  export { monthlyOver } from './monthly.js';
33
33
  export { markersOf } from './markers.js';
34
+ export { analysisOf } from './analysis.js';
34
35
  export { summaryOf } from './statistics.js';
35
36
  export { reportOf } from './report.js';
36
37
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/accounting/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AASnF,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/accounting/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AASnF,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC"}
@@ -1,3 +1,4 @@
1
+ import type { TradeAnalysis } from './analysis.js';
1
2
  import type { ChargeSchedule } from './charges.js';
2
3
  import type { EquityPoint } from './equity.js';
3
4
  import type { MonthlyReturn } from './monthly.js';
@@ -8,6 +9,8 @@ import type { Trade } from './trades.js';
8
9
  /** Everything a run is reported as, and nothing a chart has to compute. */
9
10
  export interface Report {
10
11
  readonly summary: Summary;
12
+ /** The trades by direction, by extreme and by run. */
13
+ readonly analysis: TradeAnalysis;
11
14
  readonly trades: readonly Trade[];
12
15
  readonly equity: readonly EquityPoint[];
13
16
  readonly monthly: readonly MonthlyReturn[];
@@ -1 +1 @@
1
- {"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../../src/core/accounting/report.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE1E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,2EAA2E;AAC3E,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC;IACxC,QAAQ,CAAC,OAAO,EAAE,SAAS,aAAa,EAAE,CAAC;IAC3C,QAAQ,CAAC,OAAO,EAAE,SAAS,WAAW,EAAE,CAAC;CAC1C;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,SAAS,YAAY,EAAE,EAC9B,KAAK,EAAE,SAAS,OAAO,EAAE,EACzB,QAAQ,EAAE,cAAc,GAAG,IAAI,EAC/B,QAAQ,EAAE,QAAQ,EAClB,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structural half of keeping that decision open: when it is taken, the engine
20
20
  * calls this, and there is no second implementation to disagree with.
21
21
  */
22
+ import { analysisOf } from './analysis.js';
22
23
  import { chargeFor } from './charges.js';
23
24
  import { equityOver } from './equity.js';
24
25
  import { monthlyOver } from './monthly.js';
@@ -54,6 +55,7 @@ export function reportOf(fills, marks, schedule, contract, capital) {
54
55
  const summary = summaryOf(trades, equity, contract, capital);
55
56
  return {
56
57
  summary,
58
+ analysis: analysisOf(trades),
57
59
  trades,
58
60
  equity,
59
61
  monthly: monthlyOver(equity, trades),
@@ -1 +1 @@
1
- {"version":3,"file":"report.js","sourceRoot":"","sources":["../../../src/core/accounting/report.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAYvC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,QAAQ,CACtB,KAA8B,EAC9B,KAAyB,EACzB,QAA+B,EAC/B,QAAkB,EAClB,OAAc;IAEd,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IAC5D,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACnC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,QAA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AC;IAC5D,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACnC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,KAAK,CAClE,CAAC;IAEF,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC3D,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC5D,MAAM,OAAO,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IAE7D,OAAO;QACL,OAAO;QACP,QAAQ,EAAE,UAAU,CAAC,MAAM,CAAC;QAC5B,MAAM;QACN,MAAM;QACN,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC;QACpC,OAAO,EAAE,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC;KACpC,CAAC;AACJ,CAAC"}
@@ -59,6 +59,18 @@ export interface Summary {
59
59
  /** A bar time, never an index. */
60
60
  readonly maxDrawdownAt: number | null;
61
61
  readonly longestDrawdownBars: number;
62
+ /**
63
+ * Zero or positive, the mirror of `maxDrawdown` and read against it.
64
+ *
65
+ * The pair is the point of it. A run that made ten and gave back nine is a
66
+ * different strategy from one that made one and never gave any of it back,
67
+ * and the two report the same net. Neither figure says that on its own.
68
+ */
69
+ readonly maxRunUp: Money;
70
+ /** The highest point's own fraction, not the best fraction of any point. */
71
+ readonly maxRunUpPercent: number;
72
+ /** A bar time, never an index, and not the bar `maxDrawdownAt` addresses. */
73
+ readonly maxRunUpAt: number | null;
62
74
  readonly averageBarsHeld: number | null;
63
75
  readonly barsInMarket: number;
64
76
  readonly barCount: number;
@@ -1 +1 @@
1
- {"version":3,"file":"statistics.d.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SAAS,CACvB,MAAM,EAAE,SAAS,KAAK,EAAE,EACxB,MAAM,EAAE,SAAS,WAAW,EAAE,EAC9B,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,KAAK,GACb,OAAO,CA0CT"}
@@ -100,6 +100,9 @@ export function summaryOf(trades, equity, contract, capital) {
100
100
  maxDrawdownPercent: depth.maxDrawdownPercent,
101
101
  maxDrawdownAt: depth.maxDrawdownAt,
102
102
  longestDrawdownBars: depth.longestDrawdownBars,
103
+ maxRunUp: depth.maxRunUp,
104
+ maxRunUpPercent: depth.maxRunUpPercent,
105
+ maxRunUpAt: depth.maxRunUpAt,
103
106
  averageBarsHeld: tally.heldCount === 0 ? null : tally.heldTotal / tally.heldCount,
104
107
  barsInMarket: barsInMarketOver(trades, equity),
105
108
  barCount: equity.length,
@@ -202,6 +205,9 @@ function depthOf(equity) {
202
205
  let maxDrawdownAt = null;
203
206
  let longestDrawdownBars = 0;
204
207
  let under = 0;
208
+ let maxRunUp = 0;
209
+ let maxRunUpPercent = 0;
210
+ let maxRunUpAt = null;
205
211
  for (const point of equity) {
206
212
  if (point.drawdown < maxDrawdown) {
207
213
  maxDrawdown = point.drawdown;
@@ -216,8 +222,24 @@ function depthOf(equity) {
216
222
  else {
217
223
  under = 0;
218
224
  }
225
+ // Strictly greater, so the earliest bar reaching the height wins the tie,
226
+ // which is the rule the depth above is picked by. The two figures address
227
+ // different bars and each addresses the first bar that reached it.
228
+ if (point.runUp > maxRunUp) {
229
+ maxRunUp = point.runUp;
230
+ maxRunUpPercent = point.runUpPercent;
231
+ maxRunUpAt = point.time;
232
+ }
219
233
  }
220
- return { maxDrawdown, maxDrawdownPercent, maxDrawdownAt, longestDrawdownBars };
234
+ return {
235
+ maxDrawdown,
236
+ maxDrawdownPercent,
237
+ maxDrawdownAt,
238
+ longestDrawdownBars,
239
+ maxRunUp,
240
+ maxRunUpPercent,
241
+ maxRunUpAt,
242
+ };
221
243
  }
222
244
  /**
223
245
  * The standard error of the expectancy: the sample deviation over the root of
@@ -1 +1 @@
1
- {"version":3,"file":"statistics.js","sourceRoot":"","sources":["../../../src/core/accounting/statistics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AACH,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AA6FxD;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CACvB,MAAwB,EACxB,MAA8B,EAC9B,QAAkB,EAClB,OAAc;IAEd,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC;IAE1C,8EAA8E;IAC9E,0EAA0E;IAC1E,yEAAyE;IACzE,8EAA8E;IAC9E,8CAA8C;IAC9C,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,GAAG,KAAK,CAAC,UAAU,CAAC;IAEnF,OAAO;QACL,OAAO;QACP,QAAQ,EAAE,QAAQ,CAAC,QAAQ;QAC3B,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,aAAa,EAAE,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC;QAChD,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,OAAO,EAAE,OAA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,GAAG,KAAK,CAAC,KAAK,CAAC;YACvB,eAAe,GAAG,KAAK,CAAC,YAAY,CAAC;YACrC,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,OAAO;QACL,WAAW;QACX,kBAAkB;QAClB,aAAa;QACb,mBAAmB;QACnB,QAAQ;QACR,eAAe;QACf,UAAU;KACX,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAS,eAAe,CACtB,MAAwB,EACxB,UAAiB,EACjB,UAAkB;IAElB,IAAI,UAAU,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC;IAE7B,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,KAAK,CAAC,MAAM;YAAE,SAAS;QAC3B,MAAM,IAAI,GAAG,KAAK,CAAC,SAAS,GAAG,UAAU,CAAC;QAC1C,OAAO,IAAI,IAAI,GAAG,IAAI,CAAC;IACzB,CAAC;IACD,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC;AAC5D,CAAC"}
@@ -0,0 +1,60 @@
1
+ import type { RunRecord } from './record.js';
2
+ /** The files of one case, keyed by the name `conformance.md` section 2 gives them. */
3
+ export type CaseFiles = Readonly<Record<string, string>>;
4
+ /** Why a record could not become a case. */
5
+ export interface CaseRefusal {
6
+ readonly ok: false;
7
+ readonly reason: string;
8
+ /**
9
+ * The catalogue code the refusal is filed under, or null.
10
+ *
11
+ * A refusal about a setting of the run is the catalogue's, OS6021, because
12
+ * it is the same refusal the run makes of a setting it cannot be carried out
13
+ * under. The others here are about what the record holds, a text it never
14
+ * carried, a bar list it only points at, a fact its host never stated, and
15
+ * no catalogue entry is about those.
16
+ */
17
+ readonly code: string | null;
18
+ }
19
+ export interface CaseWritten {
20
+ readonly ok: true;
21
+ readonly files: CaseFiles;
22
+ }
23
+ export type CaseResult = CaseWritten | CaseRefusal;
24
+ /** What the caller has to say, because a record cannot know it. */
25
+ export interface CaseIdentity {
26
+ /**
27
+ * The directory path under the suite root, which is also the case id.
28
+ *
29
+ * The caller's because a record does not know where it will live, and
30
+ * `case.json` repeats it on purpose so a directory that is moved without its
31
+ * id being changed is caught by the suite rather than by a confused reader.
32
+ */
33
+ readonly id: string;
34
+ /** One sentence. It is the failure message a runner prints. */
35
+ readonly description: string;
36
+ /** Section 7's categories. Defaults to the one a strategy run belongs to. */
37
+ readonly category?: string;
38
+ }
39
+ /**
40
+ * `conformance.md` section 6: the loosest bounds a conformance case may declare.
41
+ *
42
+ * Core reads no page, so the two figures are written here, and
43
+ * `tests/backtest/case-settings.test.ts` reads them out of section 6 and holds
44
+ * these to the page, which is the arrangement `stdlib.md` section 20's figures
45
+ * are under. Past either bound a run may still be a useful comparison; what it
46
+ * is not is a case, so the projection makes no file of it.
47
+ */
48
+ export declare const TOLERANCE_CAP: {
49
+ readonly rel: number;
50
+ readonly abs: number;
51
+ };
52
+ /**
53
+ * The files for one case, or the reason there are none.
54
+ *
55
+ * `now` is written only when the run pinned one. A case that names it when the
56
+ * script never asked pins a clock the run did not depend on, and the next
57
+ * reader has to work out whether it mattered.
58
+ */
59
+ export declare function caseFilesFrom(record: RunRecord, identity: CaseIdentity): CaseResult;
60
+ //# sourceMappingURL=case.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"case.d.ts","sourceRoot":"","sources":["../../../src/core/backtest/case.ts"],"names":[],"mappings":"AAoCA,OAAO,KAAK,EAA8B,SAAS,EAAE,MAAM,aAAa,CAAC;AAGzE,sFAAsF;AACtF,MAAM,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEzD,4CAA4C;AAC5C,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB;;;;;;;;OAQG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAClB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;CAC3B;AAED,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,WAAW,CAAC;AAEnD,mEAAmE;AACnE,MAAM,WAAW,YAAY;IAC3B;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,+DAA+D;IAC/D,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,6EAA6E;IAC7E,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAWD;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,EAAE;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAGvE,CAAC;AA8BF;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,GAAG,UAAU,CAsFnF"}