전략평가 화면 수정
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { BacktestSignal } from './backendApi';
|
||||
import { normalizeEpochSecOptional } from './backtestUiUtils';
|
||||
|
||||
export interface BarSignalHighlight {
|
||||
buy: boolean;
|
||||
@@ -11,15 +12,39 @@ const isBuySignalType = (type: BacktestSignal['type']): boolean =>
|
||||
const isSellSignalType = (type: BacktestSignal['type']): boolean =>
|
||||
type === 'SELL' || type === 'SHORT_ENTRY' || type === 'PARTIAL_SELL';
|
||||
|
||||
/** 선택 봉 시각에 백테스트 매매 시그널이 있는지 (차트 마커와 동일 기준) */
|
||||
function signalMatchesBar(
|
||||
signal: BacktestSignal,
|
||||
barIndex: number,
|
||||
barTimeSec: number,
|
||||
): boolean {
|
||||
if (signal.barIndex === barIndex) return true;
|
||||
const signalTime = normalizeEpochSecOptional(signal.time);
|
||||
const barTime = normalizeEpochSecOptional(barTimeSec);
|
||||
if (signalTime > 0 && barTime > 0 && signalTime === barTime) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/** 선택 봉에 백테스트 매매 시그널이 있는지 (차트 마커와 동일 기준) */
|
||||
export function resolveBarSignalHighlight(
|
||||
signals: BacktestSignal[],
|
||||
barTimeSec: number | null | undefined,
|
||||
barIndex?: number | null,
|
||||
): BarSignalHighlight {
|
||||
if (barTimeSec == null || signals.length === 0) {
|
||||
if (signals.length === 0) {
|
||||
return { buy: false, sell: false };
|
||||
}
|
||||
const atBar = signals.filter(s => s.time === barTimeSec);
|
||||
if (barIndex == null || barIndex < 0) {
|
||||
if (barTimeSec == null) return { buy: false, sell: false };
|
||||
const t = normalizeEpochSecOptional(barTimeSec);
|
||||
const atBar = signals.filter(s => normalizeEpochSecOptional(s.time) === t);
|
||||
return {
|
||||
buy: atBar.some(s => isBuySignalType(s.type)),
|
||||
sell: atBar.some(s => isSellSignalType(s.type)),
|
||||
};
|
||||
}
|
||||
|
||||
const barTime = barTimeSec ?? 0;
|
||||
const atBar = signals.filter(s => signalMatchesBar(s, barIndex, barTime));
|
||||
return {
|
||||
buy: atBar.some(s => isBuySignalType(s.type)),
|
||||
sell: atBar.some(s => isSellSignalType(s.type)),
|
||||
|
||||
Reference in New Issue
Block a user