feat(research): isolate candidates and add reviewed paper promotion
This commit is contained in:
parent
26b97265c6
commit
25b5cbf481
128 changed files with 13038 additions and 1388 deletions
|
|
@ -35,6 +35,7 @@ export function ChronologicalValidationPreflight({
|
|||
backtestId,
|
||||
name,
|
||||
grid,
|
||||
candidate,
|
||||
disabled,
|
||||
eligible,
|
||||
onDirty,
|
||||
|
|
@ -44,6 +45,7 @@ export function ChronologicalValidationPreflight({
|
|||
backtestId: string;
|
||||
name: string;
|
||||
grid: string;
|
||||
candidate?: ChronologicalValidationSubmission['candidate'];
|
||||
disabled: boolean;
|
||||
eligible: boolean;
|
||||
onDirty: (dirty: boolean) => void;
|
||||
|
|
@ -72,7 +74,15 @@ export function ChronologicalValidationPreflight({
|
|||
const request = useRef<AbortController | null>(null);
|
||||
const pending = useRef(false);
|
||||
const alive = useRef(false);
|
||||
const identity = JSON.stringify({ backtestId, name, grid, windows, disabled, eligible });
|
||||
const identity = JSON.stringify({
|
||||
backtestId,
|
||||
name,
|
||||
grid,
|
||||
candidate,
|
||||
windows,
|
||||
disabled,
|
||||
eligible,
|
||||
});
|
||||
const currentIdentity = useRef(identity);
|
||||
currentIdentity.current = identity;
|
||||
const preview =
|
||||
|
|
@ -123,6 +133,7 @@ export function ChronologicalValidationPreflight({
|
|||
backtestId,
|
||||
name,
|
||||
grid: JSON.parse(grid),
|
||||
...(candidate ? { candidate } : {}),
|
||||
recipe: parseValidationWindows(windows),
|
||||
});
|
||||
const value = await chronologicalValidationApi.preview(input, controller.signal);
|
||||
|
|
@ -325,7 +336,9 @@ export function ChronologicalValidationPreflight({
|
|||
</p>
|
||||
<p>
|
||||
Input checks only. Warmup sufficiency is not evidence of profitability or statistical
|
||||
adequacy. Only deterministic, unfitted strategies with zero label horizon are supported.
|
||||
adequacy. Built-in strategies use the declared unfitted model. Candidate warmup is
|
||||
author-declared and candidate behavior is unverified; fitting and nonzero label horizons
|
||||
have no supported validation contract.
|
||||
</p>
|
||||
<div className="grid gap-3 lg:grid-cols-3">
|
||||
{preview.partitions.map(part => (
|
||||
|
|
|
|||
|
|
@ -13,6 +13,10 @@ import {
|
|||
} from '@stock-bot/stock-config/experiments';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { backtestApiV2, type Backtest } from '@/features/backtest/services/backtestApiV2';
|
||||
import {
|
||||
StrategySelection,
|
||||
type CatalogSelection,
|
||||
} from '@/features/strategies/components/StrategySelection';
|
||||
import { useUnsavedWarning } from '@/features/strategies/components/useUnsavedWarning';
|
||||
import {
|
||||
experimentApi,
|
||||
|
|
@ -94,6 +98,19 @@ export function ExperimentEditor({
|
|||
const [backtestId, setBacktestId] = useState(initialBacktestId);
|
||||
const [name, setName] = useState('');
|
||||
const [grid, setGrid] = useState('{}');
|
||||
const [useCandidate, setUseCandidate] = useState(false);
|
||||
const [candidateSelection, setCandidateSelection] = useState<CatalogSelection>({});
|
||||
const [candidateValid, setCandidateValid] = useState(false);
|
||||
const candidateRevision = useRef(0);
|
||||
const candidateValidity = useRef(false);
|
||||
const renderedCandidateRevision = candidateRevision.current;
|
||||
const candidate =
|
||||
useCandidate && candidateSelection.strategyVersionId
|
||||
? {
|
||||
versionId: candidateSelection.strategyVersionId,
|
||||
parameters: candidateSelection.strategyParameters ?? {},
|
||||
}
|
||||
: undefined;
|
||||
const [backtests, setBacktests] = useState<Backtest[]>([]);
|
||||
const [templateLoading, setTemplateLoading] = useState(true);
|
||||
const [templateError, setTemplateError] = useState('');
|
||||
|
|
@ -113,6 +130,7 @@ export function ExperimentEditor({
|
|||
walkForwardDirty ||
|
||||
Boolean(
|
||||
name ||
|
||||
useCandidate ||
|
||||
grid !== '{}' ||
|
||||
backtestId !== initialBacktestId ||
|
||||
mode !== 'parameters' ||
|
||||
|
|
@ -179,7 +197,12 @@ export function ExperimentEditor({
|
|||
change();
|
||||
};
|
||||
const prepare = async () => {
|
||||
if (submissionOwner.current || previewLoading) {
|
||||
if (
|
||||
submissionOwner.current ||
|
||||
previewLoading ||
|
||||
candidateRevision.current !== renderedCandidateRevision ||
|
||||
(useCandidate && !candidateValid)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const current = ++generation.current;
|
||||
|
|
@ -194,11 +217,21 @@ export function ExperimentEditor({
|
|||
const value =
|
||||
modeRef.current === 'cost-sensitivity'
|
||||
? await experimentApi.costPreview(
|
||||
costSensitivityInputSchema.parse({ backtestId, name, scenarios }),
|
||||
costSensitivityInputSchema.parse({
|
||||
backtestId,
|
||||
name,
|
||||
scenarios,
|
||||
...(candidate ? { candidate } : {}),
|
||||
}),
|
||||
controller.signal
|
||||
)
|
||||
: await experimentApi.preview(
|
||||
experimentInputSchema.parse({ backtestId, name, grid: JSON.parse(grid) }),
|
||||
experimentInputSchema.parse({
|
||||
backtestId,
|
||||
name,
|
||||
grid: JSON.parse(grid),
|
||||
...(candidate ? { candidate } : {}),
|
||||
}),
|
||||
controller.signal
|
||||
);
|
||||
if (alive.current && current === generation.current) {
|
||||
|
|
@ -356,6 +389,49 @@ export function ExperimentEditor({
|
|||
Load more backtests
|
||||
</Button>
|
||||
)}
|
||||
<label className="block text-sm">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={useCandidate}
|
||||
disabled={Boolean(lockedBy)}
|
||||
onChange={event => {
|
||||
if (submissionOwner.current) {
|
||||
return;
|
||||
}
|
||||
candidateRevision.current++;
|
||||
invalidate(() => setUseCandidate(event.target.checked));
|
||||
}}
|
||||
/>{' '}
|
||||
Use an isolated candidate version
|
||||
</label>
|
||||
{useCandidate && (
|
||||
<section aria-label="Candidate experiment strategy" className="space-y-2">
|
||||
<p className="text-sm">
|
||||
Select an immutable candidate and validate its base parameters. The saved backtest
|
||||
supplies the dataset, capital and financial policy. Preview checks candidate
|
||||
eligibility.
|
||||
</p>
|
||||
<StrategySelection
|
||||
value={candidateSelection}
|
||||
onChange={value => {
|
||||
if (submissionOwner.current) {
|
||||
return;
|
||||
}
|
||||
candidateRevision.current++;
|
||||
invalidate(() => setCandidateSelection(value));
|
||||
}}
|
||||
onValidityChange={valid => {
|
||||
if (submissionOwner.current || valid === candidateValidity.current) {
|
||||
return;
|
||||
}
|
||||
candidateValidity.current = valid;
|
||||
candidateRevision.current++;
|
||||
invalidate(() => setCandidateValid(valid));
|
||||
}}
|
||||
disabled={Boolean(lockedBy)}
|
||||
/>
|
||||
</section>
|
||||
)}
|
||||
<label className="block text-sm">
|
||||
Experiment type
|
||||
<select
|
||||
|
|
@ -469,6 +545,7 @@ export function ExperimentEditor({
|
|||
disabled={
|
||||
Boolean(lockedBy) ||
|
||||
previewLoading ||
|
||||
(useCandidate && !candidateValid) ||
|
||||
!backtests.some(item => item.id === backtestId) ||
|
||||
!name.trim()
|
||||
}
|
||||
|
|
@ -514,8 +591,13 @@ export function ExperimentEditor({
|
|||
backtestId={backtestId}
|
||||
name={name}
|
||||
grid={grid}
|
||||
candidate={candidate}
|
||||
disabled={mode !== 'parameters' || (lockedBy !== null && lockedBy !== 'chronological')}
|
||||
eligible={!templateLoading && backtests.some(item => item.id === backtestId)}
|
||||
eligible={
|
||||
!templateLoading &&
|
||||
(!useCandidate || candidateValid) &&
|
||||
backtests.some(item => item.id === backtestId)
|
||||
}
|
||||
onDirty={setValidationDirty}
|
||||
claimSubmission={claimSubmission}
|
||||
releaseSubmission={releaseSubmission}
|
||||
|
|
@ -524,8 +606,13 @@ export function ExperimentEditor({
|
|||
backtestId={backtestId}
|
||||
name={name}
|
||||
grid={grid}
|
||||
candidate={candidate}
|
||||
disabled={mode !== 'parameters' || (lockedBy !== null && lockedBy !== 'walk-forward')}
|
||||
eligible={!templateLoading && backtests.some(item => item.id === backtestId)}
|
||||
eligible={
|
||||
!templateLoading &&
|
||||
(!useCandidate || candidateValid) &&
|
||||
backtests.some(item => item.id === backtestId)
|
||||
}
|
||||
onDirty={setWalkForwardDirty}
|
||||
claimSubmission={claimSubmission}
|
||||
releaseSubmission={releaseSubmission}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ export function ExperimentInputs({ preview }: { preview: WorkbenchExperimentPrev
|
|||
<dd>{new Date(dataset.bounds.warmupStart).toISOString()}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Initial capital / owner budget (USD)</dt>
|
||||
<dt>Initial capital / strategy sizing budget (USD)</dt>
|
||||
<dd>
|
||||
{request.policy.matching.risk.ledger.initialCapital} /{' '}
|
||||
{request.strategy.selection.ownerBudget}
|
||||
|
|
@ -50,6 +50,27 @@ export function ExperimentInputs({ preview }: { preview: WorkbenchExperimentPrev
|
|||
<dd>{request.strategy.selection.seed}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
{request.strategy.origin === 'candidate' && (
|
||||
<section aria-label="Isolated candidate execution" className="space-y-1 break-all">
|
||||
<p>
|
||||
Isolated TypeScript candidate ·{' '}
|
||||
{request.strategy.reviewId
|
||||
? `Review ${request.strategy.reviewId}`
|
||||
: 'Unreviewed research candidate'}
|
||||
</p>
|
||||
<p>
|
||||
Author-declared warmup: {request.strategy.package.execution?.warmupBars} bars. Arbitrary
|
||||
code may ignore the seeded RNG; reproduction compares actual economic results.
|
||||
</p>
|
||||
<p>Sandbox image: {request.strategy.execution.imageId}</p>
|
||||
<p>
|
||||
Limits: {request.strategy.execution.profile.limits.memoryBytes / 1048576} MiB memory,{' '}
|
||||
{request.strategy.execution.profile.limits.cpuQuota} CPU,{' '}
|
||||
{request.strategy.execution.profile.limits.wallMs / 1000} seconds per container; an
|
||||
agent attempt deadline may be shorter.
|
||||
</p>
|
||||
</section>
|
||||
)}
|
||||
<p>
|
||||
{costs
|
||||
? 'Template cost diagnostics only. Strategy parameters, dataset, seed, capital, half-spread and risk limits remain fixed; each fee/slippage scenario executes independently. No strategy selection or ranking is performed.'
|
||||
|
|
@ -97,6 +118,13 @@ export function ExperimentInputs({ preview }: { preview: WorkbenchExperimentPrev
|
|||
strategy: {
|
||||
versionId: request.strategy.versionId,
|
||||
reviewId: request.strategy.reviewId,
|
||||
origin: request.strategy.origin,
|
||||
...(request.strategy.origin === 'candidate'
|
||||
? {
|
||||
execution: request.strategy.execution,
|
||||
declaredWarmup: request.strategy.package.execution?.warmupBars,
|
||||
}
|
||||
: {}),
|
||||
selection: request.strategy.selection,
|
||||
artifactHash: request.strategy.package.artifact.sha256,
|
||||
dependencyLockHash: request.strategy.package.dependencyLock.sha256,
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ interface Props {
|
|||
experimentId: string;
|
||||
backtestId: string;
|
||||
previewHash: string;
|
||||
strategyOrigin?: 'builtin' | 'candidate';
|
||||
experimentCancelled: boolean;
|
||||
trial: ExperimentTrial;
|
||||
disabled: boolean;
|
||||
|
|
@ -39,6 +40,7 @@ export function ExperimentTrialRecovery({
|
|||
experimentId,
|
||||
backtestId,
|
||||
previewHash,
|
||||
strategyOrigin = 'builtin',
|
||||
experimentCancelled,
|
||||
trial,
|
||||
disabled,
|
||||
|
|
@ -92,7 +94,7 @@ export function ExperimentTrialRecovery({
|
|||
setHistoryLoading(true);
|
||||
setHistoryError('');
|
||||
void experimentApi
|
||||
.retryHistory(experimentId, trial.runId, trial.trialKey, controller.signal)
|
||||
.retryHistory(experimentId, trial.runId, trial.trialKey, controller.signal, strategyOrigin)
|
||||
.then(value => {
|
||||
if (current) {
|
||||
setHistory(value);
|
||||
|
|
@ -112,7 +114,15 @@ export function ExperimentTrialRecovery({
|
|||
current = false;
|
||||
controller.abort();
|
||||
};
|
||||
}, [experimentId, trial.runId, trial.trialKey, trial.retryCount, historyOpen, historyReload]);
|
||||
}, [
|
||||
experimentId,
|
||||
trial.runId,
|
||||
trial.trialKey,
|
||||
trial.retryCount,
|
||||
historyOpen,
|
||||
historyReload,
|
||||
strategyOrigin,
|
||||
]);
|
||||
const review = () => {
|
||||
if (disabled || !freshAllowed || !trial.runId || intentRef.current) {
|
||||
return;
|
||||
|
|
@ -323,7 +333,7 @@ export function ExperimentTrialRecovery({
|
|||
</div>
|
||||
<div>
|
||||
<dt>Approval at retry admission</dt>
|
||||
<dd>{item.reviewId}</dd>
|
||||
<dd>{item.reviewId ?? 'Unreviewed isolated candidate'}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</article>
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ export function WalkForwardPreflight({
|
|||
backtestId,
|
||||
name,
|
||||
grid,
|
||||
candidate,
|
||||
disabled,
|
||||
eligible,
|
||||
onDirty,
|
||||
|
|
@ -42,6 +43,7 @@ export function WalkForwardPreflight({
|
|||
backtestId: string;
|
||||
name: string;
|
||||
grid: string;
|
||||
candidate?: WalkForwardSubmission['candidate'];
|
||||
disabled: boolean;
|
||||
eligible: boolean;
|
||||
onDirty: (value: boolean) => void;
|
||||
|
|
@ -72,7 +74,15 @@ export function WalkForwardPreflight({
|
|||
posting = useRef(false),
|
||||
generation = useRef(0),
|
||||
read = useRef<AbortController | null>(null);
|
||||
const identity = JSON.stringify({ backtestId, name, grid, windows, disabled, eligible }),
|
||||
const identity = JSON.stringify({
|
||||
backtestId,
|
||||
name,
|
||||
grid,
|
||||
candidate,
|
||||
windows,
|
||||
disabled,
|
||||
eligible,
|
||||
}),
|
||||
currentIdentity = useRef(identity);
|
||||
currentIdentity.current = identity;
|
||||
const preview =
|
||||
|
|
@ -125,6 +135,7 @@ export function WalkForwardPreflight({
|
|||
backtestId,
|
||||
name,
|
||||
grid: JSON.parse(grid),
|
||||
...(candidate ? { candidate } : {}),
|
||||
windows: windows.map((window, index) =>
|
||||
parseValidationWindows(window, `Window ${index + 1} `)
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue