/** * The trades taken apart: by direction, by extreme, and by run. * * The summary answers what the whole run did. Three questions it cannot answer * are asked here, and each of them is a question about whether the summary * means what it looks like it means. * * **Which side made the money.** A run whose long trades paid for its short * ones reports a healthy net and is two strategies, one of which is losing. The * summary cannot show that, because every figure in it is folded over both * sides at once. Splitting it is not a refinement of the headline number, it is * the first thing that can contradict it. * * **Whether one trade is the result.** A hundred trades and a profit factor of * two reads as an edge until the largest win is the whole of the net. The * expectancy's standard error already says how wide the spread is; the largest * win and the largest loss say where the width came from, which is the part a * reader can act on. * * **What the run of losses was.** The deepest drawdown is a money figure and * the longest one is a bar count, and neither is the number that actually stops * somebody trading a strategy. That number is how many times in a row it was * wrong. It is not derivable from anything in the summary: the same win rate * over the same trades gives a streak of two or a streak of eleven depending on * an ordering the summary folds away. * * ## Every figure here is over closed trades, and that is the whole rule * * An open trade has no net to win or lose by, so it is in none of these counts, * on either side, in no streak and in no extreme. `statistics.ts` has three * different answers to which trades a figure is counted over, because a summary * carries a capital figure and a bar count that are facts about the run rather * than about its trades. Nothing here is a fact about the run, so there is one * answer, and a reader can hold it. * * The consequence worth stating: `longCount + shortCount` is `tradeCount` and * not the length of the list folded. A run holding an open position reports * fewer trades here than it has, and the summary's `openTradeCount` is where * the difference is accounted for. */ import type { Money } from './shapes.js'; import type { Trade } from './trades.js'; /** One direction's own figures, folded over that side's closed trades. */ export interface SideAnalysis { readonly count: number; readonly wins: number; readonly losses: number; /** Exactly zero net, counted in neither half, as in the summary. */ readonly scratches: number; /** Net after charges, which is the figure the sides are compared on. */ readonly netProfit: Money; /** `wins / (wins + losses)`, null where this side decided nothing. */ readonly winRate: number | null; } /** * The trades by direction, by extreme and by run. * * `long` and `short` partition the closed trades, so their counts sum to the * summary's `tradeCount` and their nets sum to its `netProfit`. That is * asserted rather than assumed, because a partition that stops partitioning is * the defect this shape exists to make visible and it would otherwise show up * as two panels that quietly disagree. */ export interface TradeAnalysis { readonly long: SideAnalysis; readonly short: SideAnalysis; /** * The best closed trade's net, zero where none closed and zero where every * closed trade lost. * * Zero rather than null, and it is the one place here that is worth arguing * about. A run whose every trade lost has no winning trade to name, and null * would say so. It reports zero because the figure is read beside * `largestLoss` and against `netProfit`, and a null in a column of money * forces every reader of the report to handle a case that means "nothing * won", which is what zero already means in this column. */ readonly largestWin: Money; /** The worst closed trade's net as a positive magnitude, zero where none lost. */ readonly largestLoss: Money; /** * The longest run of consecutive winning closed trades, in the order they * closed. * * In the order they closed, and not the order they opened, because that is * the order the account experienced them in and the streak is a fact about * what the account experienced. The two orders differ whenever a trade is * held across another one's whole life, which is every scaling strategy. */ readonly maxConsecutiveWins: number; /** The same, for losses. */ readonly maxConsecutiveLosses: number; } /** * One pass over the closed trades, in closing order. * * The list arrives in opening order, which is what the equity fold needs and * what `tradesOf` produces. The streaks need closing order, so the closed * trades are ordered here rather than anywhere else: reordering the list the * caller holds would change the equity curve, and taking a second list in * opening order and calling its streaks correct would be the defect this * function is supposed to have caught. * * A trade whose net is exactly zero is a scratch, which is the summary's rule * and is applied here for the same reason. A scratch **breaks** a streak * without extending either one: a strategy that went right, flat, right was not * right twice running, and counting the flat trade as either would make the * streak a figure that depends on a rounding at the last digit. */ export declare function analysisOf(trades: readonly Trade[]): TradeAnalysis; //# sourceMappingURL=analysis.d.ts.map