@christtrade/depth 0.12.24 → 0.12.25

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.
@@ -0,0 +1,91 @@
1
+ import type { StrategyStats } from './strategy-runtime';
2
+ export interface WalkForwardSpec {
3
+ /** How many out-of-sample segments to test. */
4
+ windows: number;
5
+ /**
6
+ * In-sample length as a multiple of out-of-sample length.
7
+ *
8
+ * 3 or 4 is conventional: enough history to optimise on, tested against a
9
+ * meaningful stretch of what followed. At 1 the optimiser sees as much data
10
+ * as it is judged on, which makes every window statistically thin.
11
+ */
12
+ isMultiple: number;
13
+ /**
14
+ * Anchored keeps the in-sample start fixed and lets it grow; rolling slides
15
+ * a fixed-width window.
16
+ *
17
+ * Neither is correct in general. Anchored uses more data and assumes the
18
+ * distant past still applies; rolling adapts to regime change and forgets.
19
+ * Which one flatters a strategy is itself a finding.
20
+ */
21
+ anchored: boolean;
22
+ }
23
+ export interface WalkForwardWindow {
24
+ index: number;
25
+ /** Bar indices, half-open: [from, to). */
26
+ isFrom: number;
27
+ isTo: number;
28
+ oosFrom: number;
29
+ oosTo: number;
30
+ }
31
+ export interface WalkForwardWindowResult {
32
+ window: WalkForwardWindow;
33
+ /** What the optimiser chose on the in-sample segment. */
34
+ params: Record<string, unknown>;
35
+ inSample: StrategyStats;
36
+ outOfSample: StrategyStats;
37
+ }
38
+ export interface ParameterStability {
39
+ param: string;
40
+ /** The value chosen in each window, in order. */
41
+ values: number[];
42
+ distinct: number;
43
+ /**
44
+ * Standard deviation over the mean. Scale-free, so a period and a percentage
45
+ * are comparable.
46
+ *
47
+ * Under ~0.15 the windows broadly agree. Over ~0.5 they do not, and a single
48
+ * "optimal" value quoted from the full-history sweep is a coincidence.
49
+ */
50
+ coefficientOfVariation: number;
51
+ }
52
+ /**
53
+ * Divides a series into overlapping optimise/test windows.
54
+ *
55
+ * Anchored keeps every in-sample segment starting at bar zero instead.
56
+ *
57
+ * Returns an empty array when the series cannot support the schedule. Refusing
58
+ * is the honest answer - a walk-forward over 40-bar windows produces numbers
59
+ * that look like analysis and are noise.
60
+ */
61
+ export declare function planWalkForward(barCount: number, spec: WalkForwardSpec): WalkForwardWindow[];
62
+ /**
63
+ * How much of the optimised edge survived on unseen data.
64
+ *
65
+ * Per-bar instead of total - anchored windows differ in length and an
66
+ * unweighted ratio would let the longest in-sample segment dominate.
67
+ *
68
+ * 1.0 means out-of-sample matched in-sample. Below ~0.5 is the usual warning
69
+ * line. Negative means the optimised parameters lost money on what followed,
70
+ * which is the most useful result a backtest can give you.
71
+ *
72
+ * Returns 0 when in-sample made nothing - there is no ratio to a zero
73
+ * denominator, and reporting Infinity as "infinitely efficient" would be absurd.
74
+ */
75
+ export declare function walkForwardEfficiency(results: WalkForwardWindowResult[]): number;
76
+ /**
77
+ * Whether the optimiser kept choosing the same thing.
78
+ *
79
+ * Only numeric parameters - the spread of a boolean or a string across windows
80
+ * has no meaningful coefficient.
81
+ */
82
+ export declare function parameterStability(results: WalkForwardWindowResult[]): ParameterStability[];
83
+ /**
84
+ * Picks the best row of a scored grid.
85
+ *
86
+ * `higherIsBetter` is false for drawdown-like objectives. Rows whose metric is
87
+ * not finite are skipped rather than winning: a profit factor of Infinity means
88
+ * a run with no losing trade, which on a two-trade in-sample window is noise
89
+ * dressed as perfection.
90
+ */
91
+ export declare function pickBest<T>(rows: T[], metric: (row: T) => number | undefined, higherIsBetter?: boolean): T | null;
@@ -126,6 +126,8 @@ export interface ChartDataResult {
126
126
  seekHorizon: (horizon: bigint, triggerResample?: boolean, hotPath?: boolean,
127
127
  /** Explicit navigation: bring the view along instead of leaving it behind. */
128
128
  recenter?: boolean) => void;
129
+ /** Frames a span of time. Does not move the playhead - see 'chart:goto-range'. */
130
+ gotoRange: (fromNs: bigint, toNs?: bigint, padding?: number) => void;
129
131
  applyHorizon: (horizon: bigint, triggerResample?: boolean, hotPath?: boolean) => void;
130
132
  scheduleResample: () => void;
131
133
  runIndicatorWorker: (trades: SerialTrade[], barNs: bigint) => void;
@@ -45,6 +45,7 @@ export interface UseChartSubscriptionsParams {
45
45
  setPluginChartTypes: (types: ChartTypePlugin[]) => void;
46
46
  setChartSettings: (updater: ChartSettings | ((prev: ChartSettings) => ChartSettings)) => void;
47
47
  resetView: () => void;
48
+ gotoRange: (fromNs: bigint, toNs?: bigint, padding?: number) => void;
48
49
  buildChartTypeActiveCtx: () => ChartTypeActiveContext;
49
50
  pushDrawParams: () => void;
50
51
  runIndicatorWorker: (trades: SerialTrade[], barNs: bigint) => void;
@@ -13,7 +13,7 @@ import type { SerialTrade, PriceHistory } from '../../lib/types';
13
13
  import type { FootprintBar } from '../../lib/types/footprint';
14
14
  import type { BracketAmendment } from '../../lib/types/trading-types';
15
15
  import type { PlaceOrderRequest } from '../../lib/matchingEngine';
16
- export type PluginType = 'indicator' | 'drawing' | 'chart-type' | 'data-source' | 'extension';
16
+ export type PluginType = 'indicator' | 'drawing' | 'chart-type' | 'data-source' | 'extension' | 'strategy';
17
17
  export type Permission = 'data:read' | 'data:write' | 'eventbus:emit' | 'eventbus:intercept' | 'ui:pane' | 'ui:panel' | 'ui:toolbar' | 'ui:context-menu' | 'render:overlay' | 'render:shader' | 'drawing:register' | 'chart-type:register' | 'theme:register' | 'audio' | 'network' | 'storage' | 'intercept' | 'execution:read' | 'execution:write';
18
18
  export interface ToolbarItem {
19
19
  id: string;