Backtest Entry Amounts, Tool Data Access, and Metrics/UI Parity
Summary
Implemented and released a full backtest consistency update so backtests expose realistic trade sizing, preserve entry notional metadata, reuse the same order-style UI components as positions, and align backtest metrics with Overview calculations.
What Changed
1) Backtest sizing and trade metadata persistence
- Updated backtest position sizing to be stop-loss aware:
riskAmount = balance * riskPerTrade%positionSize = riskAmount / (entryPrice * stopLossPct)
- Persisted
entryNotionalwhen opening positions in backtests (signals.position.entryNotional).
Files:
services/backend/src/lib/backtest-engine/runner.tsshared/types.ts
const positionSize = riskAmount / (price * stopLossThreshold);
entryNotional: positionSize * currentCandle.close,
2) Backtest API and chat tools now expose quantity + entry notional
- Enriched backtest trades with:
quantityentry_notional
- Added robust fallback resolution from persisted signals when explicit DB fields are absent.
- Updated AI tool outputs (
get_backtest_result,get_backtest_trades, backtest-scoped recent trades) so chat has direct access to per-trade entry sizing data.
Files:
services/backend/src/routes/backtests/backtests-service.tsservices/backend/src/routes/backtests/backtests-types.tsservices/backend/src/routes/bots/bots-chat-handlers.ts
3) Backtest metrics parity with Overview metric model
- Expanded persisted backtest performance object to include Overview-style metrics:
averageWin,averageLoss,riskReward,expectedPayoffpeakDrawdown,tradesPerDay,distinctTradeDays,avgTradeLengthMs
- Kept existing metrics while extending compatibility for frontend/tool consumers.
Files:
services/backend/src/routes/backtests/backtests-repository.tsshared/types.ts
4) UI reuse for Trade History + clickable metric cards and chart switching
- Created reusable order-style history card component.
- Refactored bot orders panel to use the shared card.
- Refactored backtest trade history to use the same shared card and preserve signal detail rendering.
- Added clickable metric cards in backtest overview and hooked chart series switching to the selected metric (matching Overview behavior/style expectations).
Files:
services/frontend/src/components/orders/OrderHistoryCard.tsxservices/frontend/src/routes/bots/BotOrdersPanel.tsxservices/frontend/src/routes/backtests/BacktestDetailPage.tsxservices/frontend/src/lib/api-client/index.ts
Validation
- Typecheck passed (
pnpm typecheckat quantago root). - Lint passed with only pre-existing warnings (
pnpm lint). - Fixed TS target compatibility issue by removing
Array.atusage in backtest detail page.
Release
Backend
- Dev Worker version:
cb2b216d-85d6-43b2-b2b8-b7c2680f667e - Production Worker version:
10be8185-7125-4af6-bc33-822ea636eccf
Frontend
- Dev Pages deployment:
https://8c632518.quantago-dev-app.pages.dev - Production Pages deployment:
https://fa2c3dfe.quantago-app.pages.dev
Reasoning
- Entry amount confusion required explicit size and notional in both persisted trade data and tool outputs.
- Reusing one order-history component avoids visual drift between positions and backtests.
- Metric parity ensures users can trust backtest analytics against the same logic used in Overview.
- Annotation filtering for tool-heavy sources prevents noisy encoded output from leaking into final AI responses.