Spaces:
Paused
Paused
Update governance_engine.py
Browse files- governance_engine.py +52 -17
governance_engine.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
# ============================================================
|
| 2 |
-
# ๐๏ธ governance_engine.py (
|
| 3 |
# ============================================================
|
| 4 |
# Description:
|
| 5 |
# Evaluates trade quality using 156 INDICATORS.
|
| 6 |
-
# Update
|
| 7 |
# ============================================================
|
| 8 |
|
| 9 |
import numpy as np
|
|
@@ -16,8 +16,8 @@ from typing import Dict, Any, List
|
|
| 16 |
|
| 17 |
class GovernanceEngine:
|
| 18 |
def __init__(self):
|
| 19 |
-
# โ๏ธ Strategic Weights
|
| 20 |
-
self.
|
| 21 |
"order_book": 0.25, # 25%
|
| 22 |
"market_structure": 0.20, # 20%
|
| 23 |
"trend": 0.15, # 15%
|
|
@@ -26,7 +26,7 @@ class GovernanceEngine:
|
|
| 26 |
"volatility": 0.05, # 5%
|
| 27 |
"cycle_math": 0.10 # 10%
|
| 28 |
}
|
| 29 |
-
print("๐๏ธ [Governance Engine
|
| 30 |
|
| 31 |
|
| 32 |
async def evaluate_trade(
|
|
@@ -34,13 +34,14 @@ class GovernanceEngine:
|
|
| 34 |
symbol: str,
|
| 35 |
ohlcv_data: Dict[str, Any],
|
| 36 |
order_book: Dict[str, Any],
|
|
|
|
| 37 |
verbose: bool = True,
|
| 38 |
include_details: bool = False,
|
| 39 |
use_multi_timeframes: bool = False
|
| 40 |
) -> Dict[str, Any]:
|
| 41 |
"""
|
| 42 |
Main Execution Entry.
|
| 43 |
-
Now
|
| 44 |
"""
|
| 45 |
try:
|
| 46 |
if ta is None:
|
|
@@ -71,7 +72,7 @@ class GovernanceEngine:
|
|
| 71 |
df_map[tf] = d
|
| 72 |
|
| 73 |
if verbose:
|
| 74 |
-
print(f"\n๐ [Gov Audit] Opening Session for {symbol}...")
|
| 75 |
print("-" * 80)
|
| 76 |
|
| 77 |
# 2) Calculate Domains
|
|
@@ -117,9 +118,38 @@ class GovernanceEngine:
|
|
| 117 |
if verbose:
|
| 118 |
print("-" * 80)
|
| 119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
# ============================================================
|
| 121 |
# ๐ 1. STRICT CONSENSUS CHECK (Veto Power)
|
| 122 |
# All domains must be non-negative (>= 0).
|
|
|
|
| 123 |
# ============================================================
|
| 124 |
domain_scores = {
|
| 125 |
"Trend": s_trend,
|
|
@@ -131,8 +161,13 @@ class GovernanceEngine:
|
|
| 131 |
"OrderBook": s_ob
|
| 132 |
}
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
if veto_domains:
|
| 138 |
reason = f"Vetoed by negative domains: {', '.join(veto_domains)}"
|
|
@@ -140,15 +175,15 @@ class GovernanceEngine:
|
|
| 140 |
print(f"โ [Governance VETO] {reason}")
|
| 141 |
return self._create_rejection(reason)
|
| 142 |
|
| 143 |
-
# 3) Weighted Aggregation
|
| 144 |
raw_weighted_score = (
|
| 145 |
-
(s_trend *
|
| 146 |
-
(s_mom *
|
| 147 |
-
(s_vol *
|
| 148 |
-
(s_volu *
|
| 149 |
-
(s_cycle *
|
| 150 |
-
(s_struct *
|
| 151 |
-
(s_ob *
|
| 152 |
)
|
| 153 |
|
| 154 |
# 4) Final Scoring & Grading
|
|
|
|
| 1 |
# ============================================================
|
| 2 |
+
# ๐๏ธ governance_engine.py (V38.0 - GEM-Architect: Context-Aware Weights)
|
| 3 |
# ============================================================
|
| 4 |
# Description:
|
| 5 |
# Evaluates trade quality using 156 INDICATORS.
|
| 6 |
+
# Update V38.0: Dynamic Weighting based on Strategy Type (Bottom vs Momentum).
|
| 7 |
# ============================================================
|
| 8 |
|
| 9 |
import numpy as np
|
|
|
|
| 16 |
|
| 17 |
class GovernanceEngine:
|
| 18 |
def __init__(self):
|
| 19 |
+
# โ๏ธ Default Strategic Weights (For Normal/Range Operations)
|
| 20 |
+
self.DEFAULT_WEIGHTS = {
|
| 21 |
"order_book": 0.25, # 25%
|
| 22 |
"market_structure": 0.20, # 20%
|
| 23 |
"trend": 0.15, # 15%
|
|
|
|
| 26 |
"volatility": 0.05, # 5%
|
| 27 |
"cycle_math": 0.10 # 10%
|
| 28 |
}
|
| 29 |
+
print("๐๏ธ [Governance Engine V38.0] Context-Aware Protocols Active.")
|
| 30 |
|
| 31 |
|
| 32 |
async def evaluate_trade(
|
|
|
|
| 34 |
symbol: str,
|
| 35 |
ohlcv_data: Dict[str, Any],
|
| 36 |
order_book: Dict[str, Any],
|
| 37 |
+
strategy_type: str = "NORMAL", # โ
New Parameter
|
| 38 |
verbose: bool = True,
|
| 39 |
include_details: bool = False,
|
| 40 |
use_multi_timeframes: bool = False
|
| 41 |
) -> Dict[str, Any]:
|
| 42 |
"""
|
| 43 |
Main Execution Entry.
|
| 44 |
+
Now adapts weights based on 'strategy_type' (SAFE_BOTTOM vs MOMENTUM_LAUNCH).
|
| 45 |
"""
|
| 46 |
try:
|
| 47 |
if ta is None:
|
|
|
|
| 72 |
df_map[tf] = d
|
| 73 |
|
| 74 |
if verbose:
|
| 75 |
+
print(f"\n๐ [Gov Audit] Opening Session for {symbol} ({strategy_type})...")
|
| 76 |
print("-" * 80)
|
| 77 |
|
| 78 |
# 2) Calculate Domains
|
|
|
|
| 118 |
if verbose:
|
| 119 |
print("-" * 80)
|
| 120 |
|
| 121 |
+
# ============================================================
|
| 122 |
+
# โ๏ธ DYNAMIC WEIGHT SELECTION
|
| 123 |
+
# ============================================================
|
| 124 |
+
current_weights = self.DEFAULT_WEIGHTS.copy()
|
| 125 |
+
|
| 126 |
+
if strategy_type == 'SAFE_BOTTOM':
|
| 127 |
+
# ูููุงุน: ูุบูุฑ ุถุนู ุงูุชุฑูุฏุ ููุฑูุฒ ุนูู ุงูุฑูุงุถูุงุช (ุงูุงูุญุฑุงู) ูุงูุชููุจุงุช ูุงูุจููุฉ
|
| 128 |
+
current_weights = {
|
| 129 |
+
"order_book": 0.20,
|
| 130 |
+
"market_structure": 0.20, # Hammer/Support important
|
| 131 |
+
"trend": 0.05, # Trend is likely negative, ignore it mostly
|
| 132 |
+
"momentum": 0.15, # Divergence matters
|
| 133 |
+
"volume": 0.10,
|
| 134 |
+
"volatility": 0.15, # Exhaustion/BB Squeeze
|
| 135 |
+
"cycle_math": 0.15 # Mean Reversion / Z-Score
|
| 136 |
+
}
|
| 137 |
+
elif strategy_type == 'MOMENTUM_LAUNCH':
|
| 138 |
+
# ููุงูุทูุงู: ุงูุชุฑูุฏ ูุงูุฒุฎู
ูุฏูุชุฑ ุงูุทูุจุงุช ูู
ุงูู
ููู
|
| 139 |
+
current_weights = {
|
| 140 |
+
"order_book": 0.25, # Walls needed to push
|
| 141 |
+
"market_structure": 0.15,
|
| 142 |
+
"trend": 0.25, # MUST be uptrending
|
| 143 |
+
"momentum": 0.20, # High RSI is good here
|
| 144 |
+
"volume": 0.10, # Volume backing the move
|
| 145 |
+
"volatility": 0.05,
|
| 146 |
+
"cycle_math": 0.00 # Less relevant for breakout
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
# ============================================================
|
| 150 |
# ๐ 1. STRICT CONSENSUS CHECK (Veto Power)
|
| 151 |
# All domains must be non-negative (>= 0).
|
| 152 |
+
# Exception: For SAFE_BOTTOM, we tolerate negative Trend if other metrics are strong.
|
| 153 |
# ============================================================
|
| 154 |
domain_scores = {
|
| 155 |
"Trend": s_trend,
|
|
|
|
| 161 |
"OrderBook": s_ob
|
| 162 |
}
|
| 163 |
|
| 164 |
+
veto_domains = []
|
| 165 |
+
for name, score in domain_scores.items():
|
| 166 |
+
if score < 0:
|
| 167 |
+
# Special Exemption for Bottom Fishing
|
| 168 |
+
if strategy_type == 'SAFE_BOTTOM' and name == 'Trend':
|
| 169 |
+
continue
|
| 170 |
+
veto_domains.append(name)
|
| 171 |
|
| 172 |
if veto_domains:
|
| 173 |
reason = f"Vetoed by negative domains: {', '.join(veto_domains)}"
|
|
|
|
| 175 |
print(f"โ [Governance VETO] {reason}")
|
| 176 |
return self._create_rejection(reason)
|
| 177 |
|
| 178 |
+
# 3) Weighted Aggregation using DYNAMIC weights
|
| 179 |
raw_weighted_score = (
|
| 180 |
+
(s_trend * current_weights['trend']) +
|
| 181 |
+
(s_mom * current_weights['momentum']) +
|
| 182 |
+
(s_vol * current_weights['volatility']) +
|
| 183 |
+
(s_volu * current_weights['volume']) +
|
| 184 |
+
(s_cycle * current_weights['cycle_math']) +
|
| 185 |
+
(s_struct * current_weights['market_structure']) +
|
| 186 |
+
(s_ob * current_weights['order_book'])
|
| 187 |
)
|
| 188 |
|
| 189 |
# 4) Final Scoring & Grading
|