import { useState } from 'react'; import { Line, LineChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts'; import type { CanonicalRunResult } from '@stock-bot/stock-config/canonical-research'; import type { CanonicalMetrics } from '@stock-bot/types'; import { actionClass } from '@/components/ui/formStyles'; import { downloadJsonText } from '@/utils/downloadJsonText'; import { DatasetDownload } from './DatasetDownload'; const tableClass = 'w-full text-sm text-left border-collapse'; const cell = 'p-2 border-b border-border align-top'; export function canonicalTime(timestamp: number): string { const date = new Date(timestamp); return Number.isFinite(date.getTime()) ? date.toISOString() : `${timestamp} ms since Unix epoch`; } function calendarDuration(milliseconds: string): string { let remaining = BigInt(milliseconds); const parts: string[] = []; for (const [size, unit] of [ [86_400_000n, 'day'], [3_600_000n, 'hour'], [60_000n, 'minute'], [1000n, 'second'], [1n, 'millisecond'], ] as const) { const count = remaining / size; remaining %= size; if (count > 0n) { parts.push(`${count} ${unit}${count === 1n ? '' : 's'}`); } } return parts.join(', ') || '0 seconds'; } const reasonText = (reason: string | undefined) => reason?.replace(/-/g, ' ') ?? 'not reported'; function RunResultDownload({ result }: { result: CanonicalRunResult }) { const [error, setError] = useState(''); const download = () => { setError(''); try { downloadJsonText(JSON.stringify(result), `run-${result.runId}.json`); } catch (cause) { setError(cause instanceof Error ? cause.message : 'Could not download run result'); } }; return (
{error}
)}Rust financial simulation ·{' '} {request.strategy.origin === 'candidate' ? 'isolated TypeScript candidate' : 'retained TypeScript built-in'} . Completion does not establish strategy profitability or authorize trading.
{request.strategy.origin === 'candidate' && (Sandbox {request.strategy.execution.imageId} · Author-declared warmup{' '} {request.strategy.package.execution?.warmupBars} bars. Candidate code is unverified; retained seeds and inputs support an actual reproduction comparison.
)}
{JSON.stringify(
{
name: request.name,
strategy: {
familyId: request.strategy.familyId,
versionId: request.strategy.versionId,
origin: request.strategy.origin,
reviewId: request.strategy.reviewId,
program: request.strategy.package.program,
selection: request.strategy.selection,
source: request.strategy.package.source,
dependencyLockSha256: request.strategy.package.dependencyLock.sha256,
},
datasetHash: request.datasetHash,
policy: request.policy,
analyticsPolicy: analytics.policy,
build: request.build,
modelArtifacts: request.modelArtifacts,
},
null,
2
)}
Decimal amounts come directly from Rust. Gross realized P&L excludes separately reported fees. Holdings are valued using the last available marks.
Amounts are in {currency} and come from the retained Rust state and policy. An active halt blocks risk-increasing orders; exposure-reducing orders remain permitted subject to other checks. Inactive at end describes only this snapshot, not whether earlier halts or other rejections occurred.
Daily-loss state can reset at an account risk-session boundary. Price recovery alone does not clear a latched drawdown halt. The last processed risk event is not the first halt time; this report does not contain halt history or rejection counts.
{analytics.fillCount} fills · {analytics.completePeriodCount} complete periods ·{' '} {analytics.periodicSampleCount} statistical samples. Returns use fractions, displayed as percentages. Drawdown is sampled at period ends and the terminal boundary, not every intraday price. Exposure uses elapsed calendar time.
Period calendar: {analytics.policy.calendarId}, revision{' '} {analytics.policy.calendarRevision}. Annualization for periodic statistics:{' '} {analytics.policy.periodsPerYear} periods/year. Risk-free rate:{' '} {analytics.policy.annualRiskFreeRate === null ? 'unknown' : `${(analytics.policy.annualRiskFreeRate * 100).toFixed(2)}%`} . Partial periods are visible but excluded from periodic statistics. Per-period mark freshness is not certified.
The plot uses approximate numbers; exact sampled equity remains in the table.
| Timestamp (UTC) | Sample | Equity ({currency}) | Period |
|---|---|---|---|
| {canonicalTime(sample.timestamp)} | {sample.label} | {sample.equity} | {index === 0 ? 'Initial' : sample.partial ? 'Partial' : 'Complete'} |
These are owner books, not reconstructed round trips. Per-position marks, average prices and unrealized P&L are unavailable in this report.
{!financial.view.portfolio.positions.length ? (No owner positions recorded.
) : (| {label} | ))}||||
|---|---|---|---|---|
| {position.ownerId} | {position.instrumentId} | {position.quantity} | {position.remainingCost} | {position.realizedGrossPnl} |
| {label} | ))}|
|---|---|
| {owner.ownerId} | {( [ 'initialCapital', 'markedHoldings', 'remainingCost', 'realizedGrossPnl', 'unrealizedPnl', 'fees', 'equityContribution', ] as const ).map(key => ({owner[key]} | ))}
Actual Rust fill postings. A fill is not a completed round trip; gross realized P&L and fees are separate. Win rate and round-trip statistics are unavailable.
{!fills.length ? (No fills were executed in this completed run.
) : (| {label} | ))}|||||||||
|---|---|---|---|---|---|---|---|---|---|
| {canonicalTime(fill.eventTime)} | {fill.ownerId} | {fill.instrumentId} | {fill.side} | {fill.quantity} | {fill.price} | {fill.fee.amount} | {fill.releasedBasis} | {fill.realizedGrossPnl} |
{fill.orderId}
{fill.fillId} {fill.decision.decisionId} |