매매실행 방식 설정 추가
This commit is contained in:
@@ -15,6 +15,11 @@ interface FieldMeta {
|
||||
}
|
||||
|
||||
const FIELD_META: Partial<Record<keyof BacktestSettingsDto, FieldMeta>> = {
|
||||
tradeExecutionMode: {
|
||||
label: '매매 체결 방식',
|
||||
description:
|
||||
'시그널·체결가 산출 방식입니다.\n• 백테스트 엔진: 슬리피지, 손절/익절, 진입/청산가 반영. 실제 수익률 분석에 가깝습니다.\n• 조건 스캔: 봉 종가·DSL 충족 기준. 차트 마커·조건 패널과 동일합니다.',
|
||||
},
|
||||
positionMode: {
|
||||
label: '시그널 생성 방식',
|
||||
description:
|
||||
@@ -139,6 +144,18 @@ interface SettingSection {
|
||||
}
|
||||
|
||||
const SECTIONS: SettingSection[] = [
|
||||
{
|
||||
title: '⚡ 매매 체결 방식',
|
||||
fields: [
|
||||
{
|
||||
key: 'tradeExecutionMode', type: 'select',
|
||||
opts: [
|
||||
{ value: 'BACKTEST_ENGINE', label: '백테스트 엔진 (슬리피지·리스크 반영)' },
|
||||
{ value: 'SCAN_SIGNALS', label: '조건 스캔 (봉 종가·DSL 충족)' },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: '🎯 시그널 생성 방식',
|
||||
fields: [
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
saveBacktestSettings,
|
||||
} from '../utils/backendApi';
|
||||
import { ANALYSIS_METHOD_OPTIONS } from '../utils/analysisMethodLabels';
|
||||
import { TRADE_EXECUTION_MODE_OPTIONS } from '../utils/tradeExecutionMode';
|
||||
|
||||
// ── 백테스팅 전용 UI 컴포넌트 ───────────────────────────────────────────────
|
||||
|
||||
@@ -107,6 +108,36 @@ export const BacktestSettingsPanel: React.FC<BacktestSettingsPanelProps> = ({
|
||||
</BtGrid>
|
||||
</BtSection>
|
||||
|
||||
<BtSection title="매매 체결 방식">
|
||||
<BtGrid>
|
||||
<BtField
|
||||
label="시그널 · 체결가 산출"
|
||||
desc="전략평가·백테스팅·분석 레포트에 공통 적용됩니다."
|
||||
full
|
||||
>
|
||||
<select
|
||||
className="stg-select stg-select--wide"
|
||||
value={cfg.tradeExecutionMode ?? 'BACKTEST_ENGINE'}
|
||||
onChange={e => field('tradeExecutionMode', e.target.value as 'SCAN_SIGNALS' | 'BACKTEST_ENGINE')}
|
||||
>
|
||||
{TRADE_EXECUTION_MODE_OPTIONS.map(o => (
|
||||
<option key={o.value} value={o.value}>{o.label}</option>
|
||||
))}
|
||||
</select>
|
||||
</BtField>
|
||||
</BtGrid>
|
||||
<p className="stg-bt-hint">
|
||||
{(cfg.tradeExecutionMode ?? 'BACKTEST_ENGINE') === 'SCAN_SIGNALS'
|
||||
? TRADE_EXECUTION_MODE_OPTIONS[1].desc
|
||||
: TRADE_EXECUTION_MODE_OPTIONS[0].desc}
|
||||
</p>
|
||||
{(cfg.tradeExecutionMode ?? 'BACKTEST_ENGINE') === 'SCAN_SIGNALS' && (
|
||||
<p className="stg-bt-hint stg-bt-hint--warn">
|
||||
조건 스캔 모드: 슬리피지·손절/익절·트레일링스탑·진입/청산가(NEXT_OPEN) 설정은 시그널 생성에 적용되지 않습니다. 수수료만 시뮬레이션에 반영됩니다.
|
||||
</p>
|
||||
)}
|
||||
</BtSection>
|
||||
|
||||
<BtSection title="투자분석 방식">
|
||||
<BtGrid>
|
||||
<BtField
|
||||
|
||||
@@ -56,6 +56,7 @@ import {
|
||||
padEvaluationSignalCount,
|
||||
} from '../utils/strategyEvaluationReport';
|
||||
import { resolveEvaluationCommissionRate } from '../utils/strategyEvaluationSignals';
|
||||
import { normalizeTradeExecutionMode, tradeExecutionModeLabel } from '../utils/tradeExecutionMode';
|
||||
import { BACKTEST_DISPLAY_BAR_COUNT, resolveEvaluationBarSlice } from '../utils/backtestWarmup';
|
||||
import type { StrategyEvaluationWindowMeta } from './strategyEvaluation/StrategyEvaluationChart';
|
||||
import StrategyEvaluationAiVerifyPanel from './strategyEvaluation/StrategyEvaluationAiVerifyPanel';
|
||||
@@ -452,6 +453,11 @@ function StrategyEvaluationPageInner({ theme = 'dark' }: Props) {
|
||||
[backtestSettings],
|
||||
);
|
||||
|
||||
const tradeExecutionMode = useMemo(
|
||||
() => normalizeTradeExecutionMode(backtestSettings?.tradeExecutionMode),
|
||||
[backtestSettings],
|
||||
);
|
||||
|
||||
const analysisSummary = useMemo(() => {
|
||||
if (!selectedStrategy) return null;
|
||||
return buildStrategyEvaluationToolbarSummary(backtestSignals, {
|
||||
@@ -749,6 +755,7 @@ function StrategyEvaluationPageInner({ theme = 'dark' }: Props) {
|
||||
firstBarClose: evalBars[0]?.close,
|
||||
lastBarClose: evalBars[evalBars.length - 1]?.close,
|
||||
commissionRate: evaluationCommissionRate,
|
||||
tradeExecutionMode,
|
||||
});
|
||||
if (gen !== reportGenRef.current) return;
|
||||
if (!model) {
|
||||
@@ -779,6 +786,7 @@ function StrategyEvaluationPageInner({ theme = 'dark' }: Props) {
|
||||
bars,
|
||||
evalWindowMeta.evaluationBarCount,
|
||||
evaluationCommissionRate,
|
||||
tradeExecutionMode,
|
||||
]);
|
||||
|
||||
return (
|
||||
@@ -819,7 +827,7 @@ function StrategyEvaluationPageInner({ theme = 'dark' }: Props) {
|
||||
{selectedStrategy && analysisSummary && !signalScanRunning && (
|
||||
<span
|
||||
className="seval-analysis-summary"
|
||||
title="일괄매수(최초 전액) · 분할매수(40/30/잔여) · 레포트와 동일 필터 기준"
|
||||
title={`${tradeExecutionModeLabel(tradeExecutionMode)} · 일괄매수(최초 전액) · 분할매수(40/30/잔여) · 레포트와 동일 필터 기준`}
|
||||
>
|
||||
<span className="seval-analysis-item">
|
||||
매수:<strong>{padEvaluationSignalCount(analysisSummary.buyCount)}</strong>건
|
||||
|
||||
@@ -1436,6 +1436,8 @@ export interface BacktestSettingsDto {
|
||||
positionMode?: 'LONG_ONLY' | 'SIGNAL_ONLY';
|
||||
/** MARK_TO_MARKET | REALIZED_ONLY — 투자분석 방식 */
|
||||
analysisMethod?: 'MARK_TO_MARKET' | 'REALIZED_ONLY';
|
||||
/** SCAN_SIGNALS | BACKTEST_ENGINE — 매매 체결·시그널 생성 방식 */
|
||||
tradeExecutionMode?: 'SCAN_SIGNALS' | 'BACKTEST_ENGINE';
|
||||
}
|
||||
|
||||
export const DEFAULT_BACKTEST_SETTINGS: BacktestSettingsDto = {
|
||||
@@ -1460,6 +1462,7 @@ export const DEFAULT_BACKTEST_SETTINGS: BacktestSettingsDto = {
|
||||
partialExitPct: 50,
|
||||
positionMode: 'LONG_ONLY',
|
||||
analysisMethod: 'MARK_TO_MARKET',
|
||||
tradeExecutionMode: 'BACKTEST_ENGINE',
|
||||
};
|
||||
|
||||
/** 백테스팅 설정 로드 */
|
||||
|
||||
@@ -7,6 +7,7 @@ import type { EquityPoint, TradeHistoryRow } from './backtestEquity';
|
||||
import { repairUtf8Mojibake } from './textEncoding';
|
||||
import { getKoreanName } from './marketNameCache';
|
||||
import { toUpbitMarket } from './backtestUiUtils';
|
||||
import type { TradeExecutionMode } from './tradeExecutionMode';
|
||||
|
||||
export type BuyAllocationMode = 'full' | 'split';
|
||||
|
||||
@@ -357,6 +358,7 @@ export function buildStrategyEvaluationReportModel(opts: {
|
||||
firstBarClose?: number;
|
||||
lastBarClose?: number;
|
||||
commissionRate?: number;
|
||||
tradeExecutionMode?: TradeExecutionMode;
|
||||
}): BacktestAnalysisReportModel | null {
|
||||
const filtered = filterSignalsForEvaluationReport(opts.signals);
|
||||
const stillHolding = isStillHolding(filtered);
|
||||
@@ -396,6 +398,8 @@ export function buildStrategyEvaluationReportModel(opts: {
|
||||
reportSignalFilterNote:
|
||||
'분석 기간 전체 캔들 기준으로, 최초 매수 이전 매도·최종 매도 이후 매수 시그널은 제외했습니다. '
|
||||
+ '매도는 보유 물량 전량 매도로 가정합니다. '
|
||||
+ '체결가·청산 Rule은 백테스트 설정(슬리피지·손절/익절·진입/청산가)과 동일합니다.',
|
||||
+ (opts.tradeExecutionMode === 'SCAN_SIGNALS'
|
||||
? '체결가: 조건 스캔(봉 종가·DSL 충족).'
|
||||
: '체결가: 백테스트 설정(슬리피지·손절/익절·진입/청산가) 반영.'),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
/**
|
||||
* 전략평가 — 차트·상단 요약·분석 레포트·일괄평가 공통 시그널 소스
|
||||
*
|
||||
* runBacktest(SIGNAL_ONLY) + 백테스트 설정(슬리피지·손절/익절·진입/청산가) 기준.
|
||||
* scan-signals(종가·이상적 체결)와 달리 실제 백테스트 엔진과 동일한 Rule·체결가를 사용한다.
|
||||
* 전략평가·일괄평가 — 백테스트 설정의 매매 체결 방식에 따라 시그널 조회
|
||||
*/
|
||||
import type { OHLCVBar } from '../types';
|
||||
import {
|
||||
fetchLiveConditionScanSignals,
|
||||
loadBacktestSettings,
|
||||
runBacktest,
|
||||
type BacktestSettingsDto,
|
||||
@@ -13,12 +11,14 @@ import {
|
||||
type StrategyDto,
|
||||
} from './backendApi';
|
||||
import { buildEvalParamsFromStrategy } from './strategyEvaluationParams';
|
||||
import { isScanSignalsExecutionMode, normalizeTradeExecutionMode } from './tradeExecutionMode';
|
||||
|
||||
export interface StrategyEvaluationSignalsResult {
|
||||
signals: BacktestSignal[];
|
||||
initialCapital: number;
|
||||
settings: BacktestSettingsDto;
|
||||
commissionRate: number;
|
||||
tradeExecutionMode: ReturnType<typeof normalizeTradeExecutionMode>;
|
||||
}
|
||||
|
||||
export function resolveEvaluationCommissionRate(settings: BacktestSettingsDto): number {
|
||||
@@ -26,6 +26,17 @@ export function resolveEvaluationCommissionRate(settings: BacktestSettingsDto):
|
||||
return settings.commissionRate ?? 0.0015;
|
||||
}
|
||||
|
||||
function mapBarsForRequest(bars: OHLCVBar[]) {
|
||||
return bars.map(b => ({
|
||||
time: b.time,
|
||||
open: b.open,
|
||||
high: b.high,
|
||||
low: b.low,
|
||||
close: b.close,
|
||||
volume: b.volume,
|
||||
}));
|
||||
}
|
||||
|
||||
export async function fetchStrategyEvaluationSignals(opts: {
|
||||
strategyId: number;
|
||||
strategy: StrategyDto;
|
||||
@@ -37,19 +48,38 @@ export async function fetchStrategyEvaluationSignals(opts: {
|
||||
backtestSettings?: BacktestSettingsDto | null;
|
||||
}): Promise<StrategyEvaluationSignalsResult> {
|
||||
const btSettings = opts.backtestSettings ?? await loadBacktestSettings();
|
||||
const settings: BacktestSettingsDto = { ...btSettings, positionMode: 'SIGNAL_ONLY' };
|
||||
const tradeExecutionMode = normalizeTradeExecutionMode(btSettings.tradeExecutionMode);
|
||||
const indicatorParams = buildEvalParamsFromStrategy(opts.strategy, opts.getParams);
|
||||
const initialCapital = btSettings.initialCapital ?? 10_000_000;
|
||||
const commissionRate = resolveEvaluationCommissionRate(btSettings);
|
||||
|
||||
if (isScanSignalsExecutionMode(btSettings)) {
|
||||
const signals = await fetchLiveConditionScanSignals(
|
||||
opts.market,
|
||||
opts.strategyId,
|
||||
mapBarsForRequest(opts.bars),
|
||||
opts.timeframe,
|
||||
indicatorParams,
|
||||
opts.evaluationBarCount,
|
||||
);
|
||||
return {
|
||||
signals,
|
||||
initialCapital,
|
||||
settings: { ...btSettings, positionMode: 'SIGNAL_ONLY', tradeExecutionMode },
|
||||
commissionRate,
|
||||
tradeExecutionMode,
|
||||
};
|
||||
}
|
||||
|
||||
const settings: BacktestSettingsDto = {
|
||||
...btSettings,
|
||||
positionMode: 'SIGNAL_ONLY',
|
||||
tradeExecutionMode: 'BACKTEST_ENGINE',
|
||||
};
|
||||
|
||||
const res = await runBacktest({
|
||||
strategyId: opts.strategyId,
|
||||
bars: opts.bars.map(b => ({
|
||||
time: b.time,
|
||||
open: b.open,
|
||||
high: b.high,
|
||||
low: b.low,
|
||||
close: b.close,
|
||||
volume: b.volume,
|
||||
})),
|
||||
bars: mapBarsForRequest(opts.bars),
|
||||
timeframe: opts.timeframe,
|
||||
symbol: opts.market,
|
||||
strategyName: opts.strategy.name,
|
||||
@@ -62,11 +92,11 @@ export async function fetchStrategyEvaluationSignals(opts: {
|
||||
throw new Error('시그널 계산 실패');
|
||||
}
|
||||
|
||||
const initialCapital = btSettings.initialCapital ?? res.analysis?.initialCapital ?? 10_000_000;
|
||||
return {
|
||||
signals: res.signals,
|
||||
initialCapital,
|
||||
initialCapital: btSettings.initialCapital ?? res.analysis?.initialCapital ?? initialCapital,
|
||||
settings,
|
||||
commissionRate: resolveEvaluationCommissionRate(settings),
|
||||
commissionRate,
|
||||
tradeExecutionMode: 'BACKTEST_ENGINE',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import type { BacktestSettingsDto } from './backendApi';
|
||||
|
||||
export type TradeExecutionMode = 'SCAN_SIGNALS' | 'BACKTEST_ENGINE';
|
||||
|
||||
export const TRADE_EXECUTION_MODE_OPTIONS: {
|
||||
value: TradeExecutionMode;
|
||||
label: string;
|
||||
desc: string;
|
||||
}[] = [
|
||||
{
|
||||
value: 'BACKTEST_ENGINE',
|
||||
label: '백테스트 엔진 (슬리피지·리스크 반영)',
|
||||
desc: '슬리피지, 손절/익절, 진입/청산가 기준. 실제 수익률 분석에 가깝습니다.',
|
||||
},
|
||||
{
|
||||
value: 'SCAN_SIGNALS',
|
||||
label: '조건 스캔 (봉 종가·DSL 충족)',
|
||||
desc: '차트 마커·조건 패널과 동일. 봉 종가 기준 이상적 체결.',
|
||||
},
|
||||
];
|
||||
|
||||
export function normalizeTradeExecutionMode(
|
||||
value?: string | null,
|
||||
): TradeExecutionMode {
|
||||
return value === 'SCAN_SIGNALS' ? 'SCAN_SIGNALS' : 'BACKTEST_ENGINE';
|
||||
}
|
||||
|
||||
export function isScanSignalsExecutionMode(
|
||||
settings?: Pick<BacktestSettingsDto, 'tradeExecutionMode'> | null,
|
||||
): boolean {
|
||||
return normalizeTradeExecutionMode(settings?.tradeExecutionMode) === 'SCAN_SIGNALS';
|
||||
}
|
||||
|
||||
export function tradeExecutionModeLabel(mode?: string | null): string {
|
||||
const normalized = normalizeTradeExecutionMode(mode);
|
||||
return TRADE_EXECUTION_MODE_OPTIONS.find(o => o.value === normalized)?.label
|
||||
?? TRADE_EXECUTION_MODE_OPTIONS[0].label;
|
||||
}
|
||||
Reference in New Issue
Block a user