분석레포트 로직 수정
This commit is contained in:
@@ -96,7 +96,7 @@ public class BacktestingService {
|
||||
: new BooleanRule(false);
|
||||
Rule exitRule = buildExitRule(baseExitRule, series, cfg);
|
||||
|
||||
return runBacktest(series, entryRule, exitRule, req, cfg, strategyName);
|
||||
return runBacktest(series, entryRule, exitRule, req, cfg, strategyName, buyDsl, sellDsl, params);
|
||||
}
|
||||
|
||||
// ── 청산 규칙 합성 ────────────────────────────────────────────────────────
|
||||
@@ -124,7 +124,9 @@ public class BacktestingService {
|
||||
|
||||
private BacktestResponse runBacktest(BarSeries series, Rule entryRule, Rule exitRule,
|
||||
BacktestRequest req, BacktestSettingsDto cfg,
|
||||
String strategyName) {
|
||||
String strategyName,
|
||||
JsonNode execBuyDsl, JsonNode execSellDsl,
|
||||
Map<String, Map<String, Object>> execParams) {
|
||||
|
||||
BaseTradingRecord record = new BaseTradingRecord();
|
||||
|
||||
@@ -295,7 +297,8 @@ public class BacktestingService {
|
||||
Stats stats = toStats(analysis, signals);
|
||||
|
||||
// ── DB 저장 ───────────────────────────────────────────────────────────
|
||||
Long resultId = saveResult(req, cfg, signals, analysis, series, strategyName);
|
||||
Long resultId = saveResult(req, cfg, signals, analysis, series, strategyName,
|
||||
execBuyDsl, execSellDsl, execParams);
|
||||
|
||||
return BacktestResponse.builder()
|
||||
.signals(signals)
|
||||
@@ -601,12 +604,24 @@ public class BacktestingService {
|
||||
|
||||
private Long saveResult(BacktestRequest req, BacktestSettingsDto cfg,
|
||||
List<Signal> signals, BacktestAnalysisDto analysis,
|
||||
BarSeries series, String strategyName) {
|
||||
BarSeries series, String strategyName,
|
||||
JsonNode execBuyDsl, JsonNode execSellDsl,
|
||||
Map<String, Map<String, Object>> execParams) {
|
||||
try {
|
||||
List<OhlcvBar> bars = req.getBars();
|
||||
long fromTime = bars.isEmpty() ? 0 : bars.get(0).getTime();
|
||||
long toTime = bars.isEmpty() ? 0 : bars.get(bars.size() - 1).getTime();
|
||||
|
||||
Map<String, Object> snapshot = new LinkedHashMap<>();
|
||||
snapshot.put("strategyId", req.getStrategyId());
|
||||
snapshot.put("strategyName", strategyName);
|
||||
snapshot.put("symbol", req.getSymbol() != null ? req.getSymbol() : "UNKNOWN");
|
||||
snapshot.put("timeframe", req.getTimeframe());
|
||||
snapshot.put("barCount", bars.size());
|
||||
if (execParams != null && !execParams.isEmpty()) snapshot.put("indicatorParams", execParams);
|
||||
if (execBuyDsl != null && !execBuyDsl.isNull()) snapshot.put("buyCondition", execBuyDsl);
|
||||
if (execSellDsl != null && !execSellDsl.isNull()) snapshot.put("sellCondition", execSellDsl);
|
||||
|
||||
GcBacktestResult entity = GcBacktestResult.builder()
|
||||
.deviceId(req.getDeviceId())
|
||||
.strategyId(req.getStrategyId())
|
||||
@@ -617,6 +632,7 @@ public class BacktestingService {
|
||||
.fromTime(fromTime)
|
||||
.toTime(toTime)
|
||||
.settingsJson(objectMapper.writeValueAsString(cfg))
|
||||
.executionSnapshotJson(objectMapper.writeValueAsString(snapshot))
|
||||
.signalsJson(objectMapper.writeValueAsString(signals))
|
||||
.analysisJson(objectMapper.writeValueAsString(analysis))
|
||||
.totalReturn(BigDecimal.valueOf(analysis.getTotalReturnPct()))
|
||||
|
||||
Reference in New Issue
Block a user