@@ -16,16 +16,16 @@ import { Decimal } from "./decimal";
1616 * - `sharpeRatio` returns the per-period ratio. `annualizeSharpe` scales it by
1717 * `sqrt(periodsPerYear)`, the convention for i.i.d. periods. Use 365 for a
1818 * daily stablecoin-vault series, 52 weekly, 12 monthly.
19- * - `maxDrawdown` is a signed decline , so it is 0 or lower. `valueAtRisk` is a
20- * loss magnitude, so a positive result is a loss. The two signs differ by
21- * intent and each is documented on its own function .
19+ * - `maxDrawdown` is a non-negative magnitude , so it is 0 or higher.
20+ * `valueAtRisk` is also a loss magnitude, so a positive result is a loss.
21+ * Both are quoted as positive losses, matching the report field convention .
2222 */
2323
2424/** Scale used for ratio arithmetic. Stroops are too coarse for a variance. */
2525const METRICS_SCALE = 18 ;
2626
2727export interface RiskMetrics {
28- /** Most negative entry of the drawdown series, 0 or lower . */
28+ /** Most negative entry of the drawdown series as a magnitude , 0 or higher . */
2929 readonly maxDrawdown : Decimal ;
3030 /** Per-period Sharpe ratio. Annualize with `annualizeSharpe`. */
3131 readonly sharpeRatio : Decimal ;
@@ -134,8 +134,9 @@ export function valueAtRisk(
134134
135135/**
136136 * Most negative entry of the drawdown series, where each entry is the running
137- * `value / peak - 1` decline. An empty series, and a series that never leaves
138- * its running peak, both give `0`.
137+ * `value / peak - 1` decline. The result is reported as a non-negative
138+ * magnitude: the sign of the worst decline is flipped, so a series that never
139+ * leaves its running peak gives `0`. An empty series also gives `0`.
139140 */
140141export function maxDrawdown ( drawdown : readonly Decimal [ ] ) : Decimal {
141142 const scale = workingScale ( drawdown ) ;
@@ -145,7 +146,7 @@ export function maxDrawdown(drawdown: readonly Decimal[]): Decimal {
145146 worst = value . rescale ( scale ) ;
146147 }
147148 }
148- return worst ;
149+ return worst . neg ( ) ;
149150}
150151
151152/** Computes all three metrics from the collector's series in one call. */
0 commit comments