Skip to content

Commit df33698

Browse files
Merge pull request #2 from that-github-user/feature/hindcast-redesign
Redesign hindcast: tracking path + Track Record tab
2 parents 57794c3 + c0f3628 commit df33698

File tree

6 files changed

+457
-245
lines changed

6 files changed

+457
-245
lines changed

src/api/mock.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,18 @@ export function generateMockHindcast(n = 6): HindcastResponse {
200200
return null;
201201
});
202202

203+
// Scoring for predictions with enough realized data
204+
const nRealized = realizedPrices.filter((v) => v != null).length;
205+
const dirLabels = ["LONG", "SHORT", "NEUTRAL"] as const;
206+
const sigDir = dirLabels[Math.floor(rand() * 3)];
207+
const dirCorrect = rand() > 0.4;
208+
const coverageOuter = +(0.5 + rand() * 0.4).toFixed(4);
209+
const coverageInner = +(0.3 + rand() * 0.3).toFixed(4);
210+
const bestRmse = +(0.5 + rand() * 3).toFixed(2);
211+
const trackDur = Math.floor(3 + rand() * 10);
212+
const verdict = coverageOuter >= 0.7 && dirCorrect ? "PASS" as const
213+
: coverageOuter >= 0.5 || dirCorrect ? "PARTIAL" as const : "FAIL" as const;
214+
203215
predictions.push({
204216
timestamp: new Date(predTime).toISOString(),
205217
last_close: round(price),
@@ -208,10 +220,39 @@ export function generateMockHindcast(n = 6): HindcastResponse {
208220
sample_paths: samplePaths,
209221
realized_prices: realizedPrices,
210222
bars_elapsed: barsElapsed,
223+
scoring: nRealized >= 3 ? {
224+
coverage_p10_p90: coverageOuter,
225+
coverage_p25_p75: coverageInner,
226+
direction_correct: dirCorrect,
227+
median_rmse_pts: +(1 + rand() * 5).toFixed(2),
228+
best_paths: [{
229+
path_index: Math.floor(rand() * 30),
230+
path_values: samplePaths[Math.floor(rand() * 30)],
231+
rmse_pts: bestRmse,
232+
tracking_duration_bars: trackDur,
233+
tracking_threshold_pts: 2.0,
234+
deviations: realizedPrices
235+
.filter((v): v is number => v != null)
236+
.map(() => +((rand() - 0.5) * 3).toFixed(2)),
237+
}],
238+
verdict,
239+
signal_direction: sigDir,
240+
expected_return_pts: +((rand() - 0.5) * 8).toFixed(2),
241+
realized_return_pts: +((rand() - 0.5) * 10).toFixed(2),
242+
} : null,
211243
});
212244
}
213245

214-
return { predictions };
246+
return {
247+
predictions,
248+
rolling_accuracy: {
249+
n_evaluated: predictions.length,
250+
coverage_p10_p90: 0.78,
251+
coverage_p25_p75: 0.46,
252+
direction_hit_rate: 0.58,
253+
mean_tracking_rmse_pts: 1.9,
254+
},
255+
};
215256
}
216257

217258
export function generateMockHistory(): HistoryResponse {

src/api/types.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,35 @@ export interface HistoryResponse {
8686
live_num_trades: number | null;
8787
}
8888

89+
export interface PathTrackingInfo {
90+
path_index: number;
91+
path_values: number[];
92+
rmse_pts: number;
93+
tracking_duration_bars: number;
94+
tracking_threshold_pts: number;
95+
deviations: number[];
96+
}
97+
98+
export interface HindcastScored {
99+
coverage_p10_p90: number | null;
100+
coverage_p25_p75: number | null;
101+
direction_correct: boolean | null;
102+
median_rmse_pts: number | null;
103+
best_paths: PathTrackingInfo[] | null;
104+
verdict: "PASS" | "PARTIAL" | "FAIL" | null;
105+
signal_direction: string | null;
106+
expected_return_pts: number | null;
107+
realized_return_pts: number | null;
108+
}
109+
110+
export interface RollingAccuracy {
111+
n_evaluated: number;
112+
coverage_p10_p90: number | null;
113+
coverage_p25_p75: number | null;
114+
direction_hit_rate: number | null;
115+
mean_tracking_rmse_pts: number | null;
116+
}
117+
89118
export interface HindcastPrediction {
90119
timestamp: string;
91120
last_close: number;
@@ -100,10 +129,12 @@ export interface HindcastPrediction {
100129
sample_paths: number[][] | null;
101130
realized_prices: (number | null)[];
102131
bars_elapsed: number;
132+
scoring?: HindcastScored | null;
103133
}
104134

105135
export interface HindcastResponse {
106136
predictions: HindcastPrediction[];
137+
rolling_accuracy?: RollingAccuracy | null;
107138
}
108139

109140
export interface HealthResponse {

0 commit comments

Comments
 (0)