feat: confidence filter ≥ 1.5, убрать DOT, exp21-22 эксперименты

- Confidence filter |corr| × amplitude/ATR ≥ 1.5 (exp22: Sharpe 0.92→1.43, DD 20%→10.8%)
- Убран DOT (убыточен), 6→5 активов, веса перераспределены
- OHLCV в dataset (exp21), 4 фазы exp22 (стопы, фильтрация, таймфрейм, комбинации)
- OHLCV helper в signals.py, dataset.py поддерживает OHLCV

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
anor
2026-03-11 01:05:42 +10:00
co-authored by Claude Opus 4.6
parent aaa9dd6ecb
commit a474b3eb32
24 changed files with 8595 additions and 28 deletions
+1
View File
@@ -45,6 +45,7 @@ class RiskConfig:
stop_scale: float = 1.0 # multiplier on ATR stop distance (0.5 = tighter)
time_exit: bool = True # close after shift-K bars; False = hold until stop
safety_stop_pct: float = 0.10 # exchange hard stop: 10% below entry
min_confidence: float = 0.0 # confidence filter: |corr| × amplitude/ATR (0 = off, 1.5 = exp22)
@dataclass
+14 -1
View File
@@ -195,7 +195,6 @@ def _count_open_positions(conn: sqlite3.Connection) -> int:
# Correlated asset groups — don't take same direction in both
CORRELATED_GROUPS = [
{"BTC-USD", "ETH-USD"}, # major cryptos move together
{"ADA-USD", "DOT-USD"}, # L1/alt layer group
]
@@ -383,6 +382,20 @@ def _check_signal(conn, ticker, prices, dates, asset, asset_cfg, cfg):
details=f"thresh={corr_thresh:.2f} K={K}")
return f"corr={corr:.3f} < {corr_thresh:.2f} (adaptive) K={K} — SKIP"
# Confidence filter: |corr| × (pred_amplitude / ATR) — exp22
if cfg.risk.min_confidence > 0:
atr = risk.compute_atr(prices, len(prices) - 1)
if atr > 0:
pred_denorm = pred_new * sw["std"] + sw["mu"]
amplitude = float(np.max(pred_denorm) - np.min(pred_denorm))
confidence = abs(corr) * (amplitude / atr)
if confidence < cfg.risk.min_confidence:
log_signal(conn, ticker=ticker, date=str(dates[-1]),
correlation=corr, action="skip_confidence",
details=f"conf={confidence:.2f} < {cfg.risk.min_confidence}")
return (f"confidence={confidence:.2f} < {cfg.risk.min_confidence} "
f"(corr={corr:.3f}, amp/atr={amplitude/atr:.2f}) — SKIP")
# Direction
direction = signals.get_direction(pred_new, K)
if direction is None:
+25 -10
View File
@@ -29,15 +29,8 @@ def _get_exchange(exchange_cfg: ExchangeConfig | None = None):
return _exchange
def fetch_prices_ccxt(symbol: str, interval: str = "1d", period: str = "max",
exchange_cfg: ExchangeConfig | None = None):
"""Fetch close prices and dates from exchange via ccxt (Bybit etc).
Args:
symbol: ccxt symbol format, e.g. "BTC/USDT"
interval: timeframe, e.g. "4h", "1d"
period: "max" or "730d" etc.
"""
def _fetch_raw_ohlcv(symbol, interval, period, exchange_cfg):
"""Fetch raw OHLCV list from exchange. Returns list of [ts, O, H, L, C, V]."""
exchange = _get_exchange(exchange_cfg)
if period == "max":
@@ -55,7 +48,7 @@ def fetch_prices_ccxt(symbol: str, interval: str = "1d", period: str = "max",
ohlcv = exchange.fetch_ohlcv(symbol, interval, since=since, limit=batch_size)
except Exception as e:
log.error(f"Failed to fetch {symbol} from {exchange.id}: {e}")
return None, None
return None
if not ohlcv:
break
all_ohlcv.extend(ohlcv)
@@ -64,6 +57,13 @@ def fetch_prices_ccxt(symbol: str, interval: str = "1d", period: str = "max",
break
prev_since = since
return all_ohlcv or None
def fetch_prices_ccxt(symbol: str, interval: str = "1d", period: str = "max",
exchange_cfg: ExchangeConfig | None = None):
"""Fetch close prices and dates from exchange via ccxt (Bybit etc)."""
all_ohlcv = _fetch_raw_ohlcv(symbol, interval, period, exchange_cfg)
if not all_ohlcv:
return None, None
@@ -73,6 +73,21 @@ def fetch_prices_ccxt(symbol: str, interval: str = "1d", period: str = "max",
return closes, dates
def fetch_ohlcv_ccxt(symbol: str, interval: str = "1d", period: str = "max",
exchange_cfg: ExchangeConfig | None = None):
"""Fetch full OHLCV and dates. Returns (ohlcv_2d, dates).
ohlcv_2d shape: (N, 4) columns: [open, high, low, close]
"""
all_ohlcv = _fetch_raw_ohlcv(symbol, interval, period, exchange_cfg)
if not all_ohlcv:
return None, None
ohlcv = np.array([[c[1], c[2], c[3], c[4]] for c in all_ohlcv], dtype=np.float64)
dates = [datetime.fromtimestamp(c[0] / 1000, tz=timezone.utc).date()
for c in all_ohlcv]
return ohlcv, dates
def fetch_prices_yfinance(ticker: str, interval: str = "1d", period: str = "max"):
"""Fetch close prices and dates from yfinance.