feat: add Fear & Greed filter to entry logic

- core/fng.py: F&G API wrapper with 1h cache (alternative.me)
  - FNG_MIN_ENTRY=41 (env-configurable), blocks entry below threshold
- core/strategy.py: call is_entry_allowed() before volume/regime checks
- daemon/runner.py: log F&G status on every scan cycle
- core/notify.py: include F&G value in buy/signal/status notifications
- core/trader.py: pass current F&G value to notify_buy

Backtest evidence (1y / 18 tickers / 1h candles):
  - No filter:   820 trades, 32.7% WR, avg +0.012%, KRW +95k
  - F&G >= 41:   372 trades, 39.5% WR, avg +0.462%, KRW +1.72M
  - Blocked 452 trades (avg -0.372%, saved ~1.68M KRW loss)

Also add:
- backtest_db.py: Oracle DB storage for backtest runs/results/trades
- fng_1y_backtest.py, fng_adaptive_backtest.py, fng_sim_comparison.py

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
joungmin
2026-03-03 15:56:17 +09:00
parent 673ce08d84
commit 27189b1ad9
9 changed files with 1402 additions and 8 deletions

View File

@@ -23,6 +23,7 @@ import time
import pyupbit
from .fng import FNG_MIN_ENTRY, is_entry_allowed
from .market import get_current_price
from .market_regime import get_regime
from .notify import notify_signal
@@ -122,9 +123,14 @@ def _check_vol_spike(ticker: str, vol_mult: float) -> bool:
def should_buy(ticker: str) -> bool:
"""Volume Lead 전략.
1단계: 거래량 급증 + 2h 횡보 → 신호가 기록
2단계: 신호가 대비 +TREND_AFTER_VOL% 상승 확인 시 진입
1단계: F&G 필터 — 공포탐욕지수 < FNG_MIN_ENTRY(41)이면 즉시 차단
2단계: 거래량 급증 + 2h 횡보 → 신호가 기록
3단계: 신호가 대비 +TREND_AFTER_VOL% 상승 확인 시 진입
"""
# ── F&G 진입 필터 ─────────────────────────────────────
if not is_entry_allowed():
return False
regime = get_regime()
vol_mult = regime["vol_mult"]
@@ -177,11 +183,13 @@ def should_buy(ticker: str) -> bool:
entry_thr = _calc_entry_threshold(ratio)
_accum_signals[ticker] = {"price": current, "time": now, "vol_ratio": ratio}
from .fng import get_fng
fng_now = get_fng()
logger.info(
f"[축적감지] {ticker} 거래량 급증 + 2h 횡보 → 신호가={current:,.2f}"
f"(거래량 {ratio:.2f}x → 진입임계={entry_thr:.1f}%)"
f"(거래량 {ratio:.2f}x → 진입임계={entry_thr:.1f}% | F&G={fng_now})"
)
notify_signal(ticker, current, ratio)
notify_signal(ticker, current, ratio, fng=fng_now)
return False # 신호 첫 발생 시는 진입 안 함
# ── 신호 있음: 상승 확인 → 진입 ─────────────────────────