feat(research): add strategy catalog and versioned backtest setup
This commit is contained in:
parent
8cca0ee588
commit
d929db707a
44 changed files with 4198 additions and 209 deletions
|
|
@ -1,4 +1,8 @@
|
|||
import { useEffect, useState } from 'react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import {
|
||||
LegacyStrategySelect,
|
||||
StrategySelection,
|
||||
} from '@/features/strategies/components/StrategySelection';
|
||||
import type { BacktestConfig } from '../types';
|
||||
import { HistoricalDataSelection } from './HistoricalDataSelection';
|
||||
|
||||
|
|
@ -31,20 +35,28 @@ export function BacktestConfiguration({
|
|||
}
|
||||
);
|
||||
|
||||
const catalog = formData.strategy === 'catalog' || Boolean(formData.strategyVersionId);
|
||||
const [strategyValid, setStrategyValid] = useState(false);
|
||||
const [selectionEpoch, setSelectionEpoch] = useState(0);
|
||||
const authoritativeConfig = useRef(initialConfig);
|
||||
const [historicalValid, setHistoricalValid] = useState(false);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [saveError, setSaveError] = useState<string | null>(null);
|
||||
const locked = disabled || saving;
|
||||
|
||||
useEffect(() => {
|
||||
if (initialConfig) {
|
||||
if (initialConfig && initialConfig !== authoritativeConfig.current) {
|
||||
authoritativeConfig.current = initialConfig;
|
||||
setFormData(initialConfig);
|
||||
setStrategyValid(false);
|
||||
setSaveError(null);
|
||||
setSelectionEpoch(value => value + 1);
|
||||
}
|
||||
}, [initialConfig]);
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!historicalValid || locked) {
|
||||
if (!historicalValid || (catalog && !strategyValid) || locked) {
|
||||
return;
|
||||
}
|
||||
setSaving(true);
|
||||
|
|
@ -111,30 +123,26 @@ export function BacktestConfiguration({
|
|||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-text-secondary mb-1">Strategy</label>
|
||||
<select
|
||||
name="strategy"
|
||||
{catalog ? (
|
||||
<StrategySelection
|
||||
key={selectionEpoch}
|
||||
allowArchivedSelection
|
||||
value={formData}
|
||||
onChange={selection => setFormData(previous => ({ ...previous, ...selection }))}
|
||||
onValidityChange={setStrategyValid}
|
||||
disabled={Boolean(locked)}
|
||||
/>
|
||||
) : (
|
||||
<LegacyStrategySelect
|
||||
value={formData.strategy}
|
||||
onChange={handleChange}
|
||||
className="w-full px-3 py-2 bg-background border border-border rounded-md text-sm text-text-primary focus:outline-none focus:ring-1 focus:ring-primary-500"
|
||||
disabled={locked}
|
||||
>
|
||||
<option value="sma-crossover">SMA Crossover</option>
|
||||
<option value="mean-reversion">Mean Reversion</option>
|
||||
<option value="ml-enhanced">ML Enhanced (Advanced)</option>
|
||||
<option value="momentum">Momentum (Coming Soon)</option>
|
||||
<option value="pairs-trading">Pairs Trading (Coming Soon)</option>
|
||||
</select>
|
||||
<p className="text-xs text-text-muted mt-1">
|
||||
{formData.strategy === 'sma-crossover' && 'Trades on 10/20 day moving average crossovers'}
|
||||
{formData.strategy === 'mean-reversion' &&
|
||||
'Trades when price deviates from mean by 2+ std devs'}
|
||||
{formData.strategy === 'ml-enhanced' && 'Uses machine learning for signal generation'}
|
||||
{formData.strategy === 'momentum' && 'Follows strong price trends'}
|
||||
{formData.strategy === 'pairs-trading' && 'Trades correlated asset pairs'}
|
||||
</p>
|
||||
</div>
|
||||
onChange={strategy => setFormData(previous => ({ ...previous, strategy }))}
|
||||
disabled={Boolean(locked)}
|
||||
/>
|
||||
)}
|
||||
<p className="text-xs text-text-muted">
|
||||
This saved template keeps its strategy mode. Create another backtest to switch between
|
||||
catalog and legacy modes.
|
||||
</p>
|
||||
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
|
|
@ -172,28 +180,30 @@ export function BacktestConfiguration({
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-text-secondary mb-1">
|
||||
Speed Multiplier
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
name="speedMultiplier"
|
||||
value={formData.speedMultiplier}
|
||||
onChange={handleChange}
|
||||
min="0.1"
|
||||
max="1000"
|
||||
step="0.1"
|
||||
className="w-full px-3 py-2 bg-background border border-border rounded-md text-sm text-text-primary focus:outline-none focus:ring-1 focus:ring-primary-500"
|
||||
disabled={locked}
|
||||
/>
|
||||
<p className="text-xs text-text-muted mt-1">1x = real-time, 10x = 10x faster</p>
|
||||
</div>
|
||||
{!catalog && (
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-text-secondary mb-1">
|
||||
Speed Multiplier
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
name="speedMultiplier"
|
||||
value={formData.speedMultiplier}
|
||||
onChange={handleChange}
|
||||
min="0.1"
|
||||
max="1000"
|
||||
step="0.1"
|
||||
className="w-full px-3 py-2 bg-background border border-border rounded-md text-sm text-text-primary focus:outline-none focus:ring-1 focus:ring-primary-500"
|
||||
disabled={locked}
|
||||
/>
|
||||
<p className="text-xs text-text-muted mt-1">1x = real-time, 10x = 10x faster</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
className="w-full px-4 py-2 bg-primary-500 text-white rounded-md text-sm font-medium hover:bg-primary-600 transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
disabled={locked || !historicalValid}
|
||||
disabled={locked || !historicalValid || (catalog && !strategyValid)}
|
||||
>
|
||||
Save
|
||||
</button>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue