feat(research): disclose saved result provenance and limitations

This commit is contained in:
Boki 2026-10-22 14:50:24 -04:00
parent 43ffb547be
commit fe00ecd0e2
12 changed files with 456 additions and 12 deletions

View file

@ -331,7 +331,8 @@ export function BacktestDetailPageV2() {
)}
</h1>
<p className="text-xs text-text-secondary">
{backtest?.strategy || ''} • {backtest?.symbols.join(', ') || ''}
Current definition: {backtest?.strategy || ''} •{' '}
{backtest?.symbols.join(', ') || ''}
</p>
</div>

View file

@ -5,6 +5,7 @@ import type { Position } from '../types/backtest.types';
import { BacktestChart } from './BacktestChart';
import { CompactPerformanceMetrics } from './CompactPerformanceMetrics';
import { PositionsSummary } from './PositionsSummary';
import { ResultProvenance } from './ResultProvenance';
interface BacktestPlaybackProps {
result: RunResult | null;
@ -68,6 +69,10 @@ export const BacktestPlayback = memo(function BacktestPlayback({
</ErrorBoundary>
</div>
<div className="flex-shrink-0 max-h-64 overflow-y-auto">
<ResultProvenance result={result} />
</div>
{/* Performance Metrics and Positions - Fixed height section */}
<div className="flex-shrink-0 grid grid-cols-1 lg:grid-cols-2 gap-4">
<CompactPerformanceMetrics result={result} isLoading={isLoading} />

View file

@ -7,6 +7,7 @@ interface ExtendedMetrics {
maxDrawdown?: number | null;
winRate?: number | null;
totalProfit?: number | null;
totalPnl?: number | null;
profitFactor?: number | null;
totalTrades?: number | null;
avgWin?: number | null;
@ -55,10 +56,13 @@ export function CompactPerformanceMetrics({ result, isLoading }: CompactPerforma
...metrics,
};
// Calculate totalProfit if not provided
// Never infer a historical cash amount from a mutable legacy definition's capital.
const totalProfit =
allMetrics.totalProfit ??
(typeof allMetrics.totalReturn === 'number' && typeof result.config?.initialCapital === 'number'
allMetrics.totalPnl ??
(result.provenance?.configurationSource === 'stored-snapshot' &&
typeof allMetrics.totalReturn === 'number' &&
typeof result.config?.initialCapital === 'number'
? allMetrics.totalReturn * result.config.initialCapital
: undefined);

View file

@ -0,0 +1,89 @@
import type { BacktestRunResult } from '@stock-bot/types';
/** Display saved evidence only; the mutable definition remains a separate settings view. */
export function ResultProvenance({ result }: { result: BacktestRunResult }) {
const provenance = result.provenance;
const config = provenance?.configurationSource === 'stored-snapshot' ? result.config : null;
return (
<section
aria-label="Result provenance and limitations"
className="bg-surface-secondary border border-warning/40 rounded-lg p-3 text-sm space-y-2"
>
<div className="flex flex-wrap items-center gap-2">
<h3 className="font-medium text-text-primary">Saved run evidence</h3>
<span className="text-xs text-warning">Research only · Unverified economics</span>
</div>
<p className="text-text-secondary">
Completion is not financial validation. Do not use this result alone as evidence for
promotion to paper or live trading.
</p>
<p className="text-text-secondary">
Known limitations: same-bar execution, funding constraints, strategy attribution and metric
conventions.
</p>
<details>
<summary className="cursor-pointer text-text-primary">
Configuration, provenance and simulation limitations
</summary>
<div className="mt-3 space-y-3">
<dl className="grid grid-cols-1 sm:grid-cols-2 gap-2 text-text-secondary break-words">
<div>
<dt>Run</dt>
<dd>{result.runId}</dd>
</div>
<div>
<dt>Recorded engine</dt>
<dd>{result.engine === 'legacy' ? 'Unknown' : result.engine}</dd>
</div>
<div>
<dt>Engine build</dt>
<dd>{provenance?.engineVersion ?? 'Unknown — not recorded'}</dd>
</div>
<div>
<dt>Financial semantics version</dt>
<dd>{provenance?.economicsVersion ?? 'Unknown — not recorded'}</dd>
</div>
<div>
<dt>Strategy artifact</dt>
<dd>{provenance?.strategyArtifactHash ?? 'Unknown — not recorded'}</dd>
</div>
<div>
<dt>Dataset hash</dt>
<dd>{provenance?.datasetHash ?? 'Unknown — not recorded'}</dd>
</div>
</dl>
{config ? (
<div>
<h4 className="font-medium text-text-primary">Stored run configuration</h4>
<p className="text-text-secondary">
Exact saved snapshot, including parameters and data policy when recorded. This is
not the current editable definition.
</p>
<pre className="mt-2 overflow-auto max-h-64 text-xs text-text-secondary">
{JSON.stringify(config, null, 2)}
</pre>
</div>
) : (
<p className="text-text-secondary">
Stored run configuration: Unknown. Current strategy settings and defaults are not
historical evidence.
</p>
)}
{provenance ? (
<ul className="list-disc pl-5 space-y-1 text-text-secondary">
{provenance.limitations.map(limitation => (
<li key={limitation.code}>{limitation.message}</li>
))}
</ul>
) : (
<p className="text-text-secondary">
Provenance metadata is unavailable from this API. Execution timing, funding, strategy
attribution and metric conventions are unverified.
</p>
)}
</div>
</details>
</section>
);
}

View file

@ -78,7 +78,7 @@ export interface BacktestResult {
positions: Position[];
trades: Trade[];
performanceData: PerformanceDataPoint[];
analytics?: { exposureTime?: number };
analytics?: { exposureTime?: number | null };
}
export interface OrderBookLevel {