- 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
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
import { expect, test } from 'bun:test';
|
|
import { createElement } from 'react';
|
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
import type { BacktestRunResult } from '@stock-bot/types';
|
|
import { CompactPerformanceMetrics } from '../../apps/stock/web-app/src/features/backtest/components/CompactPerformanceMetrics';
|
|
|
|
const metrics = {
|
|
totalReturn: 0,
|
|
sharpeRatio: null,
|
|
maxDrawdown: 0,
|
|
winRate: 0,
|
|
totalTrades: 0,
|
|
profitableTrades: 0,
|
|
profitFactor: null,
|
|
calmarRatio: null,
|
|
sortinoRatio: null,
|
|
avgWin: 0,
|
|
avgLoss: 0,
|
|
};
|
|
const text = (html: string) => html.replace(/<[^>]*>/g, '');
|
|
|
|
test('compact metrics preserve null ratios and render a genuine zero profit', () => {
|
|
const result: BacktestRunResult = {
|
|
runId: 'fixture',
|
|
backtestId: 'fixture',
|
|
engine: 'typescript',
|
|
status: 'completed',
|
|
completedAt: '2024-02-01T00:00:00Z',
|
|
config: {
|
|
name: 'fixture',
|
|
strategy: 'sma',
|
|
symbols: ['A.US'],
|
|
startDate: '2024-01-01T00:00:00Z',
|
|
endDate: '2024-02-01T00:00:00Z',
|
|
initialCapital: 1000,
|
|
commission: 0,
|
|
slippage: 0,
|
|
dataFrequency: '1d',
|
|
parameters: {},
|
|
},
|
|
metrics: { ...metrics, totalProfit: 0 },
|
|
equity: [],
|
|
ohlcData: {},
|
|
positions: [],
|
|
trades: [],
|
|
analytics: { exposureTime: 0 },
|
|
executionTime: 0,
|
|
};
|
|
const rendered = text(
|
|
renderToStaticMarkup(createElement(CompactPerformanceMetrics, { result, isLoading: false }))
|
|
);
|
|
expect(rendered).toContain('Sharpe Ratio-');
|
|
expect(rendered).toContain('Profit Factor-');
|
|
expect(rendered).toContain('$0.00');
|
|
expect(rendered).not.toMatch(/Infinity|NaN/);
|
|
});
|