feat(research): disclose saved result provenance and limitations
This commit is contained in:
parent
43ffb547be
commit
fe00ecd0e2
12 changed files with 456 additions and 12 deletions
|
|
@ -157,7 +157,7 @@ describe('pure stored backtest result conversion', () => {
|
|||
expect(row).toEqual(before);
|
||||
});
|
||||
|
||||
test('legacy explicit zero fees and absent optional analytics keep their existing defaults', () => {
|
||||
test('legacy explicit zero fees remain compatibility defaults, missing analytics are unknown', () => {
|
||||
const row = fixture();
|
||||
row.backtest_config = {
|
||||
name: 'Legacy',
|
||||
|
|
@ -176,10 +176,108 @@ describe('pure stored backtest result conversion', () => {
|
|||
dataFrequency: '1h',
|
||||
parameters: row.backtest_config,
|
||||
},
|
||||
analytics: { exposureTime: 0 },
|
||||
analytics: { exposureTime: null },
|
||||
});
|
||||
});
|
||||
|
||||
test('legacy_missing_provenance: mutable definition fallback is explicitly not saved evidence', () => {
|
||||
const row = fixture();
|
||||
row.backtest_config = { name: 'Changed later', commission: 0.25 };
|
||||
const result = mapStoredBacktestResult(row);
|
||||
expect(result.config.name).toBe('Changed later'); // Old consumers keep their display fallback.
|
||||
expect(result.provenance).toMatchObject({
|
||||
configurationSource: 'legacy-definition-fallback',
|
||||
datasetHash: null,
|
||||
engineVersion: null,
|
||||
economicsVersion: null,
|
||||
strategyArtifactHash: null,
|
||||
});
|
||||
expect(result.provenance?.limitations.map(item => item.code)).toContain(
|
||||
'missing-configuration'
|
||||
);
|
||||
expect(result.provenance?.limitations.map(item => item.code)).toContain(
|
||||
'unversioned-execution'
|
||||
);
|
||||
});
|
||||
|
||||
test('frozen_config_not_mutable_definition: all stored inputs and dataset identity survive definition edits', () => {
|
||||
const row = fixture();
|
||||
row.engine = 'typescript';
|
||||
row.configuration = {
|
||||
name: 'Frozen strategy',
|
||||
strategy: 'saved-strategy',
|
||||
symbols: ['B.US'],
|
||||
startDate: '2023-01-01',
|
||||
endDate: '2023-02-01',
|
||||
initialCapital: 1000,
|
||||
commission: 0.0007,
|
||||
slippage: 0.0002,
|
||||
dataFrequency: '1m',
|
||||
parameters: { lookback: 14 },
|
||||
dataset: {
|
||||
version: 1,
|
||||
hash: 'a'.repeat(64),
|
||||
instruments: [{ id: 'B.US', symbol: 'B', exchange: 'US' }],
|
||||
startDate: '2023-01-01',
|
||||
endDate: '2023-02-01',
|
||||
interval: '1m',
|
||||
policy: { adjustment: 'raw', timestamp: 'utc-instant' },
|
||||
volumePolicy: 'reported',
|
||||
qualityPolicy: 'reject-invalid-no-interpolation',
|
||||
sources: [],
|
||||
barCount: 10,
|
||||
},
|
||||
};
|
||||
const first = mapStoredBacktestResult(row);
|
||||
row.strategy = 'changed-strategy';
|
||||
row.symbols = ['C.US'];
|
||||
row.initial_capital = 999999;
|
||||
row.backtest_config = { commission: 0.9, slippage: 0.9, dataFrequency: '1d' };
|
||||
const reopened = mapStoredBacktestResult(row);
|
||||
expect(reopened.config).toEqual(first.config);
|
||||
expect(reopened.provenance).toEqual(first.provenance);
|
||||
expect(reopened.provenance).toMatchObject({
|
||||
configurationSource: 'stored-snapshot',
|
||||
datasetHash: 'a'.repeat(64),
|
||||
engineVersion: null,
|
||||
economicsVersion: null,
|
||||
strategyArtifactHash: null,
|
||||
});
|
||||
expect(reopened.provenance?.limitations.map(item => item.code)).not.toContain(
|
||||
'missing-configuration'
|
||||
);
|
||||
});
|
||||
|
||||
test('null_metrics: known placeholders are unavailable without discarding computed statistics or mutating storage', () => {
|
||||
const row = fixture();
|
||||
row.engine = 'native';
|
||||
row.metrics.sharpeRatio = 1.2;
|
||||
row.metrics.sortinoRatio = 1.4;
|
||||
row.analytics = {
|
||||
exposureTime: 0,
|
||||
riskMetrics: { value_at_risk_95: 0, volatility: 0.12, downside_deviation: 0.08 },
|
||||
};
|
||||
const before = structuredClone(row);
|
||||
const result = mapStoredBacktestResult(row);
|
||||
expect(result.analytics.exposureTime).toBeNull();
|
||||
expect(result.analytics.riskMetrics).toEqual({
|
||||
value_at_risk_95: null,
|
||||
volatility: 0.12,
|
||||
downside_deviation: 0.08,
|
||||
});
|
||||
expect(result.metrics.sharpeRatio).toBe(1.2);
|
||||
expect(result.metrics.sortinoRatio).toBe(1.4);
|
||||
expect(row).toEqual(before);
|
||||
row.engine = 'typescript';
|
||||
row.analytics = { exposureTime: 0, riskMetrics: { var95: 0 } };
|
||||
expect(mapStoredBacktestResult(row).analytics).toEqual({
|
||||
exposureTime: 0,
|
||||
riskMetrics: { var95: 0 },
|
||||
});
|
||||
row.engine = 'legacy';
|
||||
expect(mapStoredBacktestResult(row).analytics.exposureTime).toBeNull();
|
||||
});
|
||||
|
||||
test('malformed trade identities fail instead of fabricating an execution time or price', () => {
|
||||
const row = fixture();
|
||||
delete row.trades[0]!.entryDate;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue