戦略切替ロジック
概要
StrategyManager は、市場状況に応じて最適な戦略を選択します。
切替フロー
graph TD
A[市場スキャン] --> B{UW Sweep検知?}
B -->|Yes| C{GEXレジーム?}
B -->|No| D{高IV + 反転?}
C -->|POS_GAMMA| E[Spear: Call方向]
C -->|NEG_GAMMA| F[Spear: Put方向]
D -->|Yes| G[Shield: Credit Spread]
D -->|No| H[待機]
E --> I{リスク枠OK?}
F --> I
G --> I
I -->|Yes| J[エントリー]
I -->|No| H
優先順位
| 優先度 |
戦略 |
条件 |
| 1 |
Spear |
UW Sweep + GEXマッチ |
| 2 |
Shield |
高IV + 反転シグナル |
| 3 |
待機 |
条件未達 |
実装
class StrategyManager:
def select_strategy(self, symbol: str, snapshot: MarketSnapshot) -> Strategy | None:
"""最適な戦略を選択"""
# 1. Spear条件チェック
if self._check_spear_conditions(symbol, snapshot):
return SunacchanSpear(symbol, snapshot)
# 2. Shield条件チェック
if self._check_shield_conditions(symbol, snapshot):
return BeatShield(symbol, snapshot)
# 3. 条件未達
return None
def _check_spear_conditions(self, symbol: str, snapshot: MarketSnapshot) -> bool:
"""Spear条件をチェック"""
return (
self._has_uw_sweep(symbol) and
self._gex_regime_matches(snapshot) and
self._iv_rank_in_range(snapshot, 30, 70) and
self._has_momentum_signal(snapshot) and
self._has_risk_capacity()
)
def _check_shield_conditions(self, symbol: str, snapshot: MarketSnapshot) -> bool:
"""Shield条件をチェック"""
return (
self._iv_rank_above(snapshot, 50) and
self._has_reversal_signal(snapshot) and
self._has_risk_capacity()
)
GEXレジーム判定
def classify_gex_regime(gex_value: float, ratio_98d: float) -> str:
"""GEXレジームを判定"""
if gex_value > 0:
if ratio_98d > 1.2:
return "POS_GAMMA_SAFE"
else:
return "POS_GAMMA_NEUTRAL"
else:
if ratio_98d < 0.8:
return "NEG_GAMMA_RISKY"
else:
return "NEG_GAMMA_NEUTRAL"
リスク枠管理
def has_risk_capacity(self) -> bool:
"""リスク枠に余裕があるか"""
# Spear: 15%上限
spear_risk = sum(p.risk for p in self.spear_positions)
spear_ok = spear_risk < self.capital * 0.15
# Shield: 8%上限
shield_risk = sum(p.risk for p in self.shield_positions)
shield_ok = shield_risk < self.capital * 0.08
return spear_ok and shield_ok
同時ポジション制限
| 戦略 |
同一銘柄 |
戦略全体 |
| Spear |
1 |
3 |
| Shield |
1 |
2 |
実装ファイル
strategies/strategy_manager.py