refactor: pre-M0 cleanup, core library hardening, and isolated dev/QA Docker stack
- Remove ~44k LOC of dead code, legacy v1 TS simulator/strategy stack, event-bus, analytics FastAPI prototype, legacy calculation archives, and unused deps (data-ingestion provider API handlers untouched) - Extract @stock-bot/di/http-security and isolate @stock-bot/browser to data-ingestion via ServiceContainerBuilder.withRegistrations() - Harden @stock-bot/mongodb read-only proxies, flatten @stock-bot/postgres with unified master+research migrations, and fix @stock-bot/config EnvLoader, ServiceApplication worker lifecycle, NamespacedCache.clear(), and BatchProcessor error propagation - Flatten workspace root (remove apps/stock/package.json) and collapse orchestrator re-export shims - Pin all Docker image versions, add shm_size/nofile/RAM caps and docker-compose.quant.yml, fix 05-add-visible-column.sql view recreation, and decouple dev/QA Compose project names for side-by-side execution - Update PLATFORM-PLAN, DATA-CONTRACTS (bars_1m PARTITION BY MONTH, Rust bulk ETL, DuckDB limits), MILESTONES, and servers docs
This commit is contained in:
parent
ce9e2df67c
commit
4cd6038063
432 changed files with 1247 additions and 44469 deletions
|
|
@ -1,144 +0,0 @@
|
|||
import type { BacktestResult } from '../types/backtest.types';
|
||||
import { MetricsCard } from './MetricsCard';
|
||||
|
||||
interface BacktestMetricsProps {
|
||||
result: BacktestResult | null;
|
||||
isLoading: boolean;
|
||||
}
|
||||
|
||||
const ratioLabel = (value: number | null | undefined) =>
|
||||
typeof value === 'number' && Number.isFinite(value) ? value.toFixed(2) : 'N/A';
|
||||
|
||||
// Full detailed metrics view - can be used as a separate page/view if needed
|
||||
export function BacktestMetrics({ result, isLoading }: BacktestMetricsProps) {
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
{[...Array(6)].map((_, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className="bg-surface-secondary rounded-lg border border-border p-4 h-24 animate-pulse"
|
||||
>
|
||||
<div className="h-4 bg-surface rounded w-1/2 mb-2"></div>
|
||||
<div className="h-6 bg-surface rounded w-3/4"></div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
return (
|
||||
<div className="bg-surface-secondary rounded-lg border border-border p-8 text-center">
|
||||
<p className="text-text-secondary">Run a backtest to see performance metrics.</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const { metrics } = result;
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
<MetricsCard
|
||||
title="Total Return"
|
||||
value={`${((metrics.totalReturn ?? 0) * 100).toFixed(2)}%`}
|
||||
trend={(metrics.totalReturn ?? 0) >= 0 ? 'up' : 'down'}
|
||||
/>
|
||||
<MetricsCard
|
||||
title="Sharpe Ratio"
|
||||
value={ratioLabel(metrics.sharpeRatio)}
|
||||
trend={
|
||||
typeof metrics.sharpeRatio !== 'number'
|
||||
? undefined
|
||||
: metrics.sharpeRatio > 0
|
||||
? 'up'
|
||||
: 'down'
|
||||
}
|
||||
/>
|
||||
<MetricsCard
|
||||
title="Max Drawdown"
|
||||
value={`${((metrics.maxDrawdown ?? 0) * 100).toFixed(2)}%`}
|
||||
trend="down"
|
||||
/>
|
||||
<MetricsCard
|
||||
title="Win Rate"
|
||||
value={`${((metrics.winRate ?? 0) * 100).toFixed(1)}%`}
|
||||
trend={(metrics.winRate ?? 0) > 0.5 ? 'up' : 'down'}
|
||||
/>
|
||||
<MetricsCard title="Total Trades" value={(metrics.totalTrades ?? 0).toString()} />
|
||||
<MetricsCard
|
||||
title="Profit Factor"
|
||||
value={ratioLabel(metrics.profitFactor)}
|
||||
trend={
|
||||
typeof metrics.profitFactor !== 'number'
|
||||
? undefined
|
||||
: metrics.profitFactor > 1
|
||||
? 'up'
|
||||
: 'down'
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div className="bg-surface-secondary rounded-lg border border-border p-4">
|
||||
<h4 className="text-sm font-medium text-text-secondary mb-3">Trade Statistics</h4>
|
||||
<div className="space-y-2">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-text-secondary text-sm">Profitable Trades</span>
|
||||
<span className="text-text-primary text-sm font-medium">
|
||||
{metrics.profitableTrades ?? 0}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-text-secondary text-sm">Average Win</span>
|
||||
<span className="text-success text-sm font-medium">
|
||||
${(metrics.avgWin ?? 0).toFixed(2)}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-text-secondary text-sm">Average Loss</span>
|
||||
<span className="text-error text-sm font-medium">
|
||||
${Math.abs(metrics.avgLoss ?? 0).toFixed(2)}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-text-secondary text-sm">Expectancy</span>
|
||||
<span
|
||||
className={`text-sm font-medium ${(metrics.expectancy ?? 0) >= 0 ? 'text-success' : 'text-error'}`}
|
||||
>
|
||||
${(metrics.expectancy ?? 0).toFixed(2)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-surface-secondary rounded-lg border border-border p-4">
|
||||
<h4 className="text-sm font-medium text-text-secondary mb-3">Risk Metrics</h4>
|
||||
<div className="space-y-2">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-text-secondary text-sm">Calmar Ratio</span>
|
||||
<span className="text-text-primary text-sm font-medium">
|
||||
{ratioLabel(metrics.calmarRatio)}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-text-secondary text-sm">Sortino Ratio</span>
|
||||
<span className="text-text-primary text-sm font-medium">
|
||||
{ratioLabel(metrics.sortinoRatio)}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-text-secondary text-sm">Exposure Time</span>
|
||||
<span className="text-text-primary text-sm font-medium">
|
||||
{typeof result.analytics?.exposureTime === 'number'
|
||||
? `${(result.analytics.exposureTime * 100).toFixed(1)}%`
|
||||
: 'N/A'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
import { ArrowUpIcon, ArrowDownIcon } from '@heroicons/react/24/solid';
|
||||
|
||||
interface MetricsCardProps {
|
||||
title: string;
|
||||
value: string;
|
||||
trend?: 'up' | 'down';
|
||||
subtitle?: string;
|
||||
}
|
||||
|
||||
export function MetricsCard({ title, value, trend, subtitle }: MetricsCardProps) {
|
||||
return (
|
||||
<div className="bg-background p-4 rounded-lg border border-border">
|
||||
<h4 className="text-sm font-medium text-text-secondary mb-1">{title}</h4>
|
||||
<div className="flex items-center gap-2">
|
||||
<p className={`text-2xl font-bold ${
|
||||
trend === 'up' ? 'text-success' :
|
||||
trend === 'down' ? 'text-error' :
|
||||
'text-text-primary'
|
||||
}`}>
|
||||
{value}
|
||||
</p>
|
||||
{trend && (
|
||||
<span className={`inline-flex ${
|
||||
trend === 'up' ? 'text-success' : 'text-error'
|
||||
}`}>
|
||||
{trend === 'up' ?
|
||||
<ArrowUpIcon className="w-4 h-4" /> :
|
||||
<ArrowDownIcon className="w-4 h-4" />
|
||||
}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{subtitle && (
|
||||
<p className="text-xs text-text-muted mt-1">{subtitle}</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,196 +0,0 @@
|
|||
import {
|
||||
BackwardIcon,
|
||||
ForwardIcon,
|
||||
PauseIcon,
|
||||
PlayIcon,
|
||||
StopIcon,
|
||||
} from '@heroicons/react/24/solid';
|
||||
import { useState } from 'react';
|
||||
import { at } from '@stock-bot/invariants';
|
||||
import type { Run } from '../services/backtestApiV2';
|
||||
|
||||
interface RunControlsProps {
|
||||
run: Run;
|
||||
onPause: () => void;
|
||||
onResume: () => void;
|
||||
onCancel: () => void;
|
||||
onSpeedChange: (speed: number) => void;
|
||||
}
|
||||
|
||||
export function RunControls({ run, onPause, onResume, onCancel, onSpeedChange }: RunControlsProps) {
|
||||
const [speedMultiplier, setSpeedMultiplier] = useState(run.speedMultiplier ?? 1000);
|
||||
|
||||
const handleSpeedChange = (speed: number) => {
|
||||
setSpeedMultiplier(speed);
|
||||
onSpeedChange(speed);
|
||||
};
|
||||
|
||||
const speedOptions = [
|
||||
{ value: 0.1, label: '0.1x' },
|
||||
{ value: 0.5, label: '0.5x' },
|
||||
{ value: 1, label: '1x' },
|
||||
{ value: 2, label: '2x' },
|
||||
{ value: 5, label: '5x' },
|
||||
{ value: 10, label: '10x' },
|
||||
{ value: 50, label: '50x' },
|
||||
{ value: 100, label: '100x' },
|
||||
{ value: 1000, label: 'Max' },
|
||||
];
|
||||
|
||||
const formatDate = (date?: string) => {
|
||||
if (!date) {
|
||||
return '-';
|
||||
}
|
||||
return new Date(date).toLocaleString();
|
||||
};
|
||||
|
||||
const formatDuration = () => {
|
||||
if (!run.startedAt) {
|
||||
return '00:00';
|
||||
}
|
||||
const start = new Date(run.startedAt).getTime();
|
||||
const current = Date.now();
|
||||
const duration = current - start;
|
||||
|
||||
const seconds = Math.floor(duration / 1000);
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const hours = Math.floor(minutes / 60);
|
||||
|
||||
if (hours > 0) {
|
||||
return `${hours.toString().padStart(2, '0')}:${(minutes % 60).toString().padStart(2, '0')}:${(seconds % 60).toString().padStart(2, '0')}`;
|
||||
} else {
|
||||
return `${minutes.toString().padStart(2, '0')}:${(seconds % 60).toString().padStart(2, '0')}`;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="bg-surface-secondary rounded-lg border border-border p-4">
|
||||
<h3 className="text-base font-medium text-text-primary mb-4">Run Control</h3>
|
||||
|
||||
<div className="space-y-4">
|
||||
{/* Progress Bar */}
|
||||
<div>
|
||||
<div className="flex justify-between text-sm text-text-secondary mb-1">
|
||||
<span>Progress</span>
|
||||
<span>{run.progress.toFixed(1)}%</span>
|
||||
</div>
|
||||
<div className="w-full bg-background rounded-full h-3 overflow-hidden">
|
||||
<div
|
||||
className="bg-primary-500 h-3 transition-all duration-300 relative"
|
||||
style={{ width: `${run.progress}%` }}
|
||||
>
|
||||
<div className="absolute inset-0 bg-gradient-to-r from-primary-500 to-primary-400 opacity-50"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Control Buttons */}
|
||||
<div className="flex items-center space-x-2">
|
||||
{run.status === 'running' ? (
|
||||
<button
|
||||
onClick={onPause}
|
||||
className="flex-1 inline-flex items-center justify-center gap-2 px-4 py-2 bg-warning text-white rounded-md text-sm font-medium hover:bg-warning/90 transition-colors"
|
||||
>
|
||||
<PauseIcon className="w-4 h-4" />
|
||||
Pause
|
||||
</button>
|
||||
) : run.status === 'paused' ? (
|
||||
<button
|
||||
onClick={onResume}
|
||||
className="flex-1 inline-flex items-center justify-center gap-2 px-4 py-2 bg-success text-white rounded-md text-sm font-medium hover:bg-success/90 transition-colors"
|
||||
>
|
||||
<PlayIcon className="w-4 h-4" />
|
||||
Resume
|
||||
</button>
|
||||
) : null}
|
||||
|
||||
{(run.status === 'running' || run.status === 'paused') && (
|
||||
<button
|
||||
onClick={onCancel}
|
||||
className="flex-1 inline-flex items-center justify-center gap-2 px-4 py-2 bg-error text-white rounded-md text-sm font-medium hover:bg-error/90 transition-colors"
|
||||
>
|
||||
<StopIcon className="w-4 h-4" />
|
||||
Cancel
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Speed Control */}
|
||||
{run.status === 'running' && (
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-text-secondary mb-2">
|
||||
Playback Speed
|
||||
</label>
|
||||
<div className="flex items-center space-x-2">
|
||||
<button
|
||||
onClick={() => {
|
||||
const currentIndex = speedOptions.findIndex(s => s.value === speedMultiplier);
|
||||
if (currentIndex > 0) {
|
||||
handleSpeedChange(at(speedOptions, currentIndex - 1).value);
|
||||
}
|
||||
}}
|
||||
className="p-1 rounded hover:bg-surface-tertiary transition-colors"
|
||||
disabled={speedMultiplier <= 0.1}
|
||||
>
|
||||
<BackwardIcon className="w-4 h-4 text-text-secondary" />
|
||||
</button>
|
||||
|
||||
<select
|
||||
value={speedMultiplier}
|
||||
onChange={e => handleSpeedChange(parseFloat(e.target.value))}
|
||||
className="flex-1 px-3 py-1.5 bg-background border border-border rounded-md text-sm text-text-primary focus:outline-none focus:ring-1 focus:ring-primary-500"
|
||||
>
|
||||
{speedOptions.map(option => (
|
||||
<option key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
||||
<button
|
||||
onClick={() => {
|
||||
const currentIndex = speedOptions.findIndex(s => s.value === speedMultiplier);
|
||||
if (currentIndex < speedOptions.length - 1) {
|
||||
handleSpeedChange(at(speedOptions, currentIndex + 1).value);
|
||||
}
|
||||
}}
|
||||
className="p-1 rounded hover:bg-surface-tertiary transition-colors"
|
||||
disabled={speedMultiplier >= 1000}
|
||||
>
|
||||
<ForwardIcon className="w-4 h-4 text-text-secondary" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Run Info */}
|
||||
<div className="grid grid-cols-2 gap-4 text-sm">
|
||||
<div>
|
||||
<span className="text-text-secondary">Status:</span>
|
||||
<span className="ml-2 text-text-primary font-medium">
|
||||
{run.status.charAt(0).toUpperCase() + run.status.slice(1)}
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-text-secondary">Duration:</span>
|
||||
<span className="ml-2 text-text-primary font-medium">{formatDuration()}</span>
|
||||
</div>
|
||||
{run.currentDate && (
|
||||
<div className="col-span-2">
|
||||
<span className="text-text-secondary">Current Date:</span>
|
||||
<span className="ml-2 text-text-primary font-medium">
|
||||
{formatDate(run.currentDate)}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{run.error && (
|
||||
<div className="col-span-2">
|
||||
<span className="text-text-secondary">Error:</span>
|
||||
<span className="ml-2 text-error text-xs">{run.error}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
export { BacktestConfiguration } from './BacktestConfiguration';
|
||||
export { MetricsCard } from './MetricsCard';
|
||||
export { RunsListWithMetrics } from './RunsListWithMetrics';
|
||||
export { CompactPerformanceMetrics } from './CompactPerformanceMetrics';
|
||||
export { PositionsSummary } from './PositionsSummary';
|
||||
export { ChartContainer } from './ChartContainer';
|
||||
export { BacktestChart } from './BacktestChart';
|
||||
export { BacktestMetrics } from './BacktestMetrics';
|
||||
export { BacktestPlayback } from './BacktestPlayback';
|
||||
export { BacktestTrades } from './BacktestTrades';
|
||||
export { RunControlsCompact } from './RunControlsCompact';
|
||||
Loading…
Add table
Add a link
Reference in a new issue