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
|
|
@ -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}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue