백테스팅 분석결과 레포트 출력

This commit is contained in:
Macbook
2026-06-03 12:14:08 +09:00
parent c228f18c25
commit ee7b1a6123
11 changed files with 1207 additions and 15 deletions
+41
View File
@@ -0,0 +1,41 @@
import type { TradeHistoryRow } from './backtestEquity';
export type TradeHistorySortKey = 'time' | 'side' | 'price' | 'pnlPct';
export type TradeHistorySortDir = 'asc' | 'desc';
export function sortTradeHistoryRows(
rows: readonly TradeHistoryRow[],
key: TradeHistorySortKey,
dir: TradeHistorySortDir,
): TradeHistoryRow[] {
const mul = dir === 'asc' ? 1 : -1;
return [...rows].sort((a, b) => {
let cmp = 0;
switch (key) {
case 'time':
cmp = a.time - b.time;
break;
case 'side':
cmp = a.side.localeCompare(b.side);
break;
case 'price':
cmp = a.price - b.price;
break;
case 'pnlPct':
cmp = compareNullableNumber(a.pnlPct, b.pnlPct);
break;
default:
cmp = 0;
}
if (cmp !== 0) return cmp * mul;
return a.id - b.id;
});
}
/** 손익 없음(매수)은 항상 목록 끝 */
function compareNullableNumber(a: number | undefined, b: number | undefined): number {
if (a == null && b == null) return 0;
if (a == null) return 1;
if (b == null) return -1;
return a - b;
}