feat(research): compare immutable fee and slippage scenarios
This commit is contained in:
parent
3ed7b98f7c
commit
397cd0e160
41 changed files with 3234 additions and 144 deletions
64
apps/stock/config/src/contracts/cost-sensitivity.ts
Normal file
64
apps/stock/config/src/contracts/cost-sensitivity.ts
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/** Cost diagnostics reuse ordinary experiments and the authoritative Rust matcher. */
|
||||
import { z } from 'zod';
|
||||
import type { financialDecimal } from '@stock-bot/types';
|
||||
import { canonicalResearchSettingsSchema, type CanonicalRunRequest } from './canonical-research';
|
||||
import {
|
||||
MAX_EXPERIMENT_TRIALS,
|
||||
type ExperimentCandidate,
|
||||
type ExperimentDetail,
|
||||
type ExperimentPreview,
|
||||
type ExperimentRetryResult,
|
||||
type ExperimentTrial,
|
||||
} from './experiments';
|
||||
|
||||
export type { financialDecimal };
|
||||
|
||||
/** Exact decimal fractions: 0.001 is 10 basis points, not 0.001 percent. */
|
||||
export const costScenarioSchema = canonicalResearchSettingsSchema
|
||||
.pick({ feeRate: true, slippageRate: true })
|
||||
.strict();
|
||||
export const costSensitivityInputSchema = z
|
||||
.object({
|
||||
backtestId: z.string().uuid(),
|
||||
name: z.string().trim().min(1),
|
||||
/** Baseline is automatic and consumes one of the existing 100 trial slots. */
|
||||
scenarios: z
|
||||
.array(costScenarioSchema)
|
||||
.min(1)
|
||||
.max(MAX_EXPERIMENT_TRIALS - 1),
|
||||
})
|
||||
.strict();
|
||||
export const costSensitivitySubmissionSchema = costSensitivityInputSchema.extend({
|
||||
previewHash: z.string().regex(/^[a-f0-9]{64}$/),
|
||||
});
|
||||
export type CostScenario = z.input<typeof costScenarioSchema>;
|
||||
export type CostSensitivityInput = z.input<typeof costSensitivityInputSchema>;
|
||||
export type CostSensitivitySubmission = z.input<typeof costSensitivitySubmissionSchema>;
|
||||
export interface CostSensitivityCandidate extends ExperimentCandidate {
|
||||
/** Index zero is the unchanged-cost baseline; later indexes follow input order. */
|
||||
costs: CostScenario;
|
||||
}
|
||||
export interface CostSensitivityPreview {
|
||||
version: 'cost-sensitivity-preview/v1';
|
||||
previewHash: string;
|
||||
input: CostSensitivityInput;
|
||||
/** Original approved template and empty parameter grid, before cost overrides. */
|
||||
source: ExperimentPreview;
|
||||
/** Exact mirrors of the source, for existing experiment provenance consumers. */
|
||||
request: CanonicalRunRequest;
|
||||
dataset: ExperimentPreview['dataset'];
|
||||
candidates: CostSensitivityCandidate[];
|
||||
}
|
||||
export interface CostSensitivityTrial extends ExperimentTrial {
|
||||
costs: CostScenario;
|
||||
}
|
||||
export interface CostSensitivityDetail extends Omit<ExperimentDetail, 'preview' | 'trials'> {
|
||||
preview: CostSensitivityPreview;
|
||||
trials: CostSensitivityTrial[];
|
||||
}
|
||||
/** Only the ordinary workbench accepts both kinds. Validation sources stay v1. */
|
||||
export type WorkbenchExperimentPreview = ExperimentPreview | CostSensitivityPreview;
|
||||
export type WorkbenchExperimentDetail = ExperimentDetail | CostSensitivityDetail;
|
||||
export type WorkbenchExperimentRetryResult = Omit<ExperimentRetryResult, 'experiment'> & {
|
||||
experiment: WorkbenchExperimentDetail;
|
||||
};
|
||||
|
|
@ -99,6 +99,8 @@ export type ExperimentRunStatus =
|
|||
| 'cancelled';
|
||||
export type ExperimentCounts = Record<ExperimentRunStatus, number>;
|
||||
export interface ExperimentSummary {
|
||||
/** Optional for older clients/fixtures; absent means a parameter experiment. */
|
||||
kind?: 'parameters' | 'cost-sensitivity';
|
||||
id: string;
|
||||
name: string;
|
||||
backtestId: string;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue