feat(spot): fractal_swing live 운영 — 슬리피지·증분 sync·신호 tail 갱신

운영 백테스트(+1,873,140%)과 live/paper 체결 규칙을 맞추고, 캔들 증분 sync·
tail 신호 갱신·일일 체결 상한·슬리피지를 반영한다. docs/live 차트 생성 스크립트와
.env.example·README를 갱신한다.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
xavis
2026-06-13 08:26:11 +09:00
parent 58802bdc5f
commit 2783826a03
20 changed files with 954 additions and 67 deletions

View File

@@ -51,19 +51,21 @@ DeepCoin/
│ ├── spot/ # 현물 전용 데이터
│ │ ├── ground_truth/ # 0단계 GT JSON
│ │ ├── techniques/ # 2단계 기법 결과
│ │ ── mtf/ # 2단계 MTF 규칙
│ │ ── mtf/ # 2단계 MTF 규칙
│ │ └── operations/ # 3단계 운영 상태
│ └── futures/ # 선물 전용 데이터
│ ├── ground_truth/ # 0단계 선물 GT JSON
│ ├── techniques/ # (예정) 2단계
│ └── mtf/ # (예정) 2단계
└── docs/
├── live/ # live 운영 백테스트 매매 차트
├── common/ # 공통 문서 (예정)
├── spot/ # 현물 리포트·차트
│ ├── 0_ground_truth/ # 0단계 GT 차트
│ ├── 1_simulation/ # 1단계 sim 차트
│ ├── 2_analysis/ # 2단계 분석 리포트
│ └── 3_operations/ # 3단계 운영 (예정)
│ └── 3_operations/ # 3단계 운영 리포트·백테스트
└── futures/ # 선물 리포트·차트
├── 0_ground_truth/ # 0단계 선물 GT 차트
├── 1_simulation/ # (예정) 1단계
@@ -125,10 +127,11 @@ bash scripts/2_run_stage2_all.sh
# ── futures 0단계: 선물 GT (현물 GT 기반) ───────────────────
python scripts/0_ground_truth_futures.py --tier all
# ── spot 3단계: 운영 (기본 paper) ─────────────────────────────
bash scripts/3_run_stage3_all.sh
# python scripts/3_run_operations.py --mode paper
# python scripts/3_run_operations.py --mode live # API 키 필요
# ── spot 3단계: fractal_swing 운영 ───────────────────────────
bash scripts/3_run_fractal_ops.sh # 백테스트 + paper loop
python scripts/3_run_fractal_realistic_backtest.py
python scripts/3_run_filtered_backtest.py # 운영 조건 3년 sim
python scripts/3_run_operations.py --loop 180 --mode live # live (API 키 필요)
```
---
@@ -178,22 +181,62 @@ GT 타점 완벽 추종 시 수익 상한선. 최근 3년·초기 20만 원.
| 2-3 | `2_run_signal_type_align.py` | `docs/spot/2_analysis/signal_type_report.html` |
| 2-4 | `2_run_mtf_analysis.py` | `data/spot/mtf/mtf_rules_v3.json`, `docs/spot/2_analysis/mtf_correlation_report.html` |
### spot 3단계 — 실거래 운영
### spot 3단계 — fractal_swing live 운영
설계·운영 가이드: [`docs/spot/3_operations/stage3_design_guide.md`](docs/spot/3_operations/stage3_design_guide.md)
설계 가이드: [`docs/spot/3_operations/stage3_design_guide.md`](docs/spot/3_operations/stage3_design_guide.md)
`composite_v3` + MTF 필터 + 고TF 게이트. **기본 `OPS_MODE=paper`**.
**운영 전략:** `fractal_swing` + MTF off. 백테스트(운영 조건) **3년 +1,873,140%** (초기 20만원 → 약 37.5억, 슬리피지 0.05%·일 100회 상한 반영).
| 순서 | 스크립트 | 산출물 |
|------|----------|--------|
| 3-1 | `3_run_filtered_backtest.py` | `filtered_backtest_report.json` |
| 3-2 | `3_run_operations.py` | `ops_report.json`, `ops_state.json` |
| 일괄 | `3_run_stage3_all.sh` | 위 전체 |
| 백테스트 | `3_run_filtered_backtest.py` | `fractal_filtered_backtest_report.json` |
| **매매 차트** | `3_render_live_chart.py` | `docs/live/index.html`, `fractal_swing_ops_chart.html` |
| 시나리오 | `3_run_fractal_realistic_backtest.py` | `fractal_realistic_backtest.json` |
| 운영 | `3_run_operations.py --loop 180` | `fractal_ops_report.json`, `fractal_ops_state.json` |
| 일괄 | `3_run_fractal_ops.sh` | 백테스트 + paper loop |
| 모드 | 설명 |
|------|------|
| `paper` | 모의 체결 (권장) |
| `live` | 빗썸 시장가 주문 (`BITHUMB_ACCESS_KEY` 필요) |
#### 백테스트 vs live 코드 정합 (라이브 직전 확인)
| 항목 | 백테스트 | live/paper 코드 | 상태 |
|------|----------|-----------------|------|
| 기법 | `fractal_swing` | `OPS_TECHNIQUE_ID` | 일치 |
| MTF | off | `OPS_MTF_ENABLED=false` | 일치 |
| 슬리피지 0.05% | `simulate_gt_signals_pnl` | `fill_price``executor` | 일치 |
| 수수료 0.05% | `GT_TRADING_FEE_RATE` | 동일 | 일치 |
| 최소 주문 5,000원 | `OPS_MIN_ORDER_KRW` | `trade_engine` | 일치 |
| 일 체결 100회 | `daily_max_trades` in sim | `runner` `trades_today_count` | 일치 |
| 매수 상한 | `max_buy_from_cash` | `compute_buy_order` | 일치 |
| 신호 | 캐시 JSON 전기간 | tail 800봉 갱신 + tick 체결 | 일치 (갱신 로직 추가) |
| 캔들 DB | 로컬 DB | `sync_ops_candles` 전 TF 증분 INSERT | 일치 |
**live 전환 전 체크**
1. `.env`: `OPS_MODE=live`, API 키 설정
2. `python scripts/3_run_filtered_backtest.py` → 필터 sim **약 +1,873,140%** 확인
3. `python scripts/3_run_operations.py --loop 180` (paper로 1~2일 모니터링 권장)
4. `fractal_ops_report.json`에서 `candle_sync`, `signal_refresh`, 체결 건수 확인
**주의:** 백테스트는 **3년 전기간 재생** sim이고, live는 **시간에 따라 누적**합니다. 2단계 ideal **+7,560,826%**(슬리피지 0)와는 다릅니다. 실거래 체결가는 모델 슬리피지보다 불리할 수 있습니다.
#### 운영 환경 변수 (fractal 기본)
| 변수 | 설명 | 기본값 |
|------|------|--------|
| `OPS_MODE` | `paper` / `live` | `paper` |
| `OPS_TECHNIQUE_ID` | 운영 기법 | `fractal_swing` |
| `OPS_MTF_ENABLED` | MTF 필터 | `false` |
| `OPS_DAILY_MAX_TRADES` | 일일 체결 상한 | `100` |
| `OPS_SLIPPAGE_RATE` | 편도 슬리피지 | `0.0005` (0.05%) |
| `OPS_MIN_ORDER_KRW` | 최소 주문 | `5000` |
| `OPS_ORDER_INTERVAL_SEC` | live 주문 간격(초) | `0.35` |
| `OPS_SYNC_CANDLES` | tick마다 캔들 증분 sync | `true` |
| `OPS_SYNC_INTERVALS` | sync TF (비우면 `DOWNLOAD_INTERVALS` 전체) | 전체 |
| `OPS_SIGNAL_TAIL_BARS` | 신호 tail 재계산 봉 수 | `800` |
| `OPS_PERSIST_SIGNAL_CACHE` | tail 갱신 후 JSON 저장 | `false` |
| `OPS_STATE_JSON` | 운영 상태 | `fractal_ops_state.json` |
| `OPS_REPORT_JSON` | 운영 리포트 | `fractal_ops_report.json` |
`composite_v3` + MTF 운영은 `.env.example` 주석 참고.
### futures 0단계 — 선물 GT
@@ -224,6 +267,11 @@ GT 타점 완벽 추종 시 수익 상한선. 최근 3년·초기 20만 원.
| `GT_LOOKBACK_DAYS` | GT 타점 기간(일) | `3650` |
| `GT_SIM_LOOKBACK_DAYS` | sim 거래 기간(일) | `1095` |
| `GT_INITIAL_CASH_KRW` | sim 초기 자본(원) | `200000` |
| `OPS_MODE` | 운영 모드 | `paper` |
| `OPS_TECHNIQUE_ID` | 운영 기법 | `fractal_swing` |
| `OPS_SLIPPAGE_RATE` | 편도 슬리피지 | `0.0005` |
| `OPS_DAILY_MAX_TRADES` | 일일 체결 상한 | `100` |
| `OPS_SYNC_CANDLES` | tick 캔들 sync | `true` |
### 경로 변수 요약
@@ -233,6 +281,8 @@ GT 타점 완벽 추종 시 수익 상한선. 최근 3년·초기 20만 원.
| spot GT 차트 | `GROUND_TRUTH_CHART_V3_FILE` | `docs/spot/0_ground_truth/...` |
| spot sim 차트 | `GROUND_TRUTH_CHART_SIM_V3_FILE` | `docs/spot/1_simulation/...` |
| spot 2단계 | `TECHNIQUES_DIR` | `data/spot/techniques/` |
| spot 3단계 운영 | `OPS_STATE_JSON` | `data/spot/operations/fractal_ops_state.json` |
| spot 3단계 리포트 | `OPS_REPORT_JSON` | `docs/spot/3_operations/fractal_ops_report.json` |
| futures GT JSON | `GROUND_TRUTH_FUTURES_FILE` | `data/futures/ground_truth/...` |
| futures GT 차트 | `GROUND_TRUTH_FUTURES_CHART_V3_FILE` | `docs/futures/0_ground_truth/...` |
@@ -295,7 +345,7 @@ GT 타점 완벽 추종 시 수익 상한선. 최근 3년·초기 20만 원.
| 유형 | 단계 | 상태 |
|------|------|------|
| common | 사전 (캔들) | 구현됨 |
| spot | 0~3단계 | 구현됨 (3단계 기본 paper) |
| spot | 0~3단계 | 구현됨 (3단계 fractal_swing live 준비) |
| futures | 0단계 | 구현됨 |
| futures | 1~3단계 | 예정 |
@@ -303,6 +353,8 @@ GT 타점 완벽 추종 시 수익 상한선. 최근 3년·초기 20만 원.
## 변경 이력
- 2026-06-13: `docs/live/` — 운영 백테스트 매수·매도 타점 HTML 차트 (`3_render_live_chart.py`)
- 2026-06-13: 운영 백테스트 **+1,873,140%** (3년, 슬리피지 0.05%, 일 100회) 검증
- 2026-06-12: `data/`·`docs/`**common / spot / futures** 3유형 구조로 재편, `coins.db``data/common/`, 0단계 차트 → `docs/{spot,futures}/0_ground_truth/`
- 2026-06-12: `0_ground_truth_futures.py` — 현물 GT → 선물 JSON·차트 변환 로직 보완
- 2026-06-12: README 현물 파이프라인 전체 순서 갱신