투자분석 레포트 로직 수정
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user