투자분석 레포트 로직 수정

This commit is contained in:
Macbook
2026-06-08 09:10:17 +09:00
parent bb3c14bd59
commit d4f0105b5a
7 changed files with 367 additions and 101 deletions
@@ -57,6 +57,7 @@ export default function BacktestSignalTable({ signals, expanded = false, classNa
<th></th>
<th></th>
<th style={{ textAlign: 'right' }}></th>
<th style={{ textAlign: 'right' }}></th>
<th style={{ textAlign: 'center', width: 50 }}>#</th>
</tr>
</thead>
@@ -73,6 +74,11 @@ export default function BacktestSignalTable({ signals, expanded = false, classNa
<td style={{ textAlign: 'right', fontVariantNumeric: 'tabular-nums', fontWeight: 600 }}>
{Math.round(s.price).toLocaleString()}
</td>
<td style={{ textAlign: 'right', fontVariantNumeric: 'tabular-nums', color: 'var(--text2)' }}>
{s.quantity != null && s.quantity > 0
? s.quantity.toFixed(6).replace(/\.?0+$/, '')
: ''}
</td>
<td style={{ textAlign: 'center', color: 'var(--text3)' }}>{s.barIndex}</td>
</tr>
))}
+2
View File
@@ -1141,6 +1141,8 @@ export interface BacktestSignal {
type: 'BUY' | 'SELL' | 'SHORT_ENTRY' | 'SHORT_EXIT' | 'PARTIAL_SELL';
price: number;
barIndex: number;
/** 체결 수량 (코인/주식 단위) */
quantity?: number;
}
export interface BacktestStats {
+5 -3
View File
@@ -61,8 +61,9 @@ export function buildEquityFromSignals(
pushCurve(sorted[0].time, sorted[0].price);
for (const s of sorted) {
const qtyHint = s.quantity != null && s.quantity > 0 ? s.quantity : undefined;
if (BUY_TYPES.has(s.type) && qty === 0 && cash > 0) {
qty = cash / s.price;
qty = qtyHint ?? cash / s.price;
entryPrice = s.price;
cash = 0;
tradeId += 1;
@@ -78,8 +79,9 @@ export function buildEquityFromSignals(
markers.push({ time: s.time, equity: eq, type: 'buy', price: s.price });
pushCurve(s.time, s.price);
} else if (SELL_TYPES.has(s.type) && qty > 0) {
const sellQty = qtyHint ?? qty;
const pnlPct = entryPrice > 0 ? (s.price - entryPrice) / entryPrice : 0;
cash = qty * s.price;
cash = sellQty * s.price;
tradeId += 1;
trades.push({
id: tradeId,
@@ -87,7 +89,7 @@ export function buildEquityFromSignals(
symbol,
side: 'sell',
price: s.price,
quantity: qty,
quantity: sellQty,
pnlPct,
});
markers.push({ time: s.time, equity: cash, type: 'sell', price: s.price, pnlPct });