Riy777 commited on
Commit
fd663b2
ยท
verified ยท
1 Parent(s): 0ffe2c1

Update governance_engine.py

Browse files
Files changed (1) hide show
  1. governance_engine.py +52 -17
governance_engine.py CHANGED
@@ -1,9 +1,9 @@
1
  # ============================================================
2
- # ๐Ÿ›๏ธ governance_engine.py (V37.1 - GEM-Architect: Consensus Mod)
3
  # ============================================================
4
  # Description:
5
  # Evaluates trade quality using 156 INDICATORS.
6
- # Update V37.1: Enforced strict unanimity (No Negatives) & >50% Score.
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.WEIGHTS = {
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 V37.1] Consensus Mode: All Domains Must be Positive (>0) & Score > 50%.")
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 enforces strict checks: No negative domains allowed.
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
- # Find any domain with a negative score
135
- veto_domains = [name for name, score in domain_scores.items() if score < 0]
 
 
 
 
 
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 (domain scores are in [-1, +1])
144
  raw_weighted_score = (
145
- (s_trend * self.WEIGHTS['trend']) +
146
- (s_mom * self.WEIGHTS['momentum']) +
147
- (s_vol * self.WEIGHTS['volatility']) +
148
- (s_volu * self.WEIGHTS['volume']) +
149
- (s_cycle * self.WEIGHTS['cycle_math']) +
150
- (s_struct * self.WEIGHTS['market_structure']) +
151
- (s_ob * self.WEIGHTS['order_book'])
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