Riy777 commited on
Commit
3d9fe2b
Β·
verified Β·
1 Parent(s): bc5527d

Update governance_engine.py

Browse files
Files changed (1) hide show
  1. governance_engine.py +39 -13
governance_engine.py CHANGED
@@ -1,10 +1,9 @@
1
  # ============================================================
2
- # πŸ›οΈ governance_engine.py (V1.3.1 - TrendErr Fix)
3
  # ============================================================
4
  # Description:
5
  # Evaluates trade quality using 156 INDICATORS.
6
- # Fixes: Solved "The truth value of a Series is ambiguous" error.
7
- # Update: Enhanced error logging to show real causes.
8
  # ============================================================
9
 
10
  import numpy as np
@@ -27,7 +26,7 @@ class GovernanceEngine:
27
  "volatility": 0.05, # 5%
28
  "cycle_math": 0.10 # 10%
29
  }
30
- print("πŸ›οΈ [Governance Engine V1.3] Stability Patch Applied. Ready.")
31
 
32
 
33
  async def evaluate_trade(
@@ -41,11 +40,7 @@ class GovernanceEngine:
41
  ) -> Dict[str, Any]:
42
  """
43
  Main Execution Entry.
44
-
45
- Backwards compatible:
46
- - Requires '15m' data (same as before)
47
- - Output schema unchanged unless include_details=True
48
- - Multi-timeframe aggregation is opt-in (use_multi_timeframes=True)
49
  """
50
  try:
51
  if ta is None:
@@ -79,7 +74,7 @@ class GovernanceEngine:
79
  print(f"\nπŸ“ [Gov Audit] Opening Session for {symbol}...")
80
  print("-" * 80)
81
 
82
- # 2) Calculate Domains (single TF by default for compatibility)
83
  details_pack = {} # only filled when include_details=True
84
 
85
  if not use_multi_timeframes:
@@ -122,6 +117,29 @@ class GovernanceEngine:
122
  if verbose:
123
  print("-" * 80)
124
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  # 3) Weighted Aggregation (domain scores are in [-1, +1])
126
  raw_weighted_score = (
127
  (s_trend * self.WEIGHTS['trend']) +
@@ -135,6 +153,15 @@ class GovernanceEngine:
135
 
136
  # 4) Final Scoring & Grading
137
  final_score = max(0.0, min(100.0, ((raw_weighted_score + 1) / 2) * 100))
 
 
 
 
 
 
 
 
 
138
  grade = self._get_grade(final_score)
139
 
140
  result = {
@@ -149,7 +176,7 @@ class GovernanceEngine:
149
  "structure": round(float(s_struct), 3),
150
  "order_book": round(float(s_ob), 3),
151
  },
152
- "status": "APPROVED" if grade != "REJECT" else "REJECTED",
153
  }
154
 
155
  if include_details:
@@ -961,8 +988,7 @@ class GovernanceEngine:
961
  def _get_grade(self, score: float) -> str:
962
  if score >= 85: return "ULTRA"
963
  if score >= 70: return "STRONG"
964
- if score >= 50: return "NORMAL"
965
- if score >= 35: return "WEAK"
966
  return "REJECT"
967
 
968
  def _create_rejection(self, reason: str):
 
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
 
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(
 
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:
 
74
  print(f"\nπŸ“ [Gov Audit] Opening Session for {symbol}...")
75
  print("-" * 80)
76
 
77
+ # 2) Calculate Domains
78
  details_pack = {} # only filled when include_details=True
79
 
80
  if not use_multi_timeframes:
 
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,
126
+ "Momentum": s_mom,
127
+ "Volatility": s_vol,
128
+ "Volume": s_volu,
129
+ "Math": s_cycle,
130
+ "Structure": s_struct,
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)}"
139
+ if verbose:
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']) +
 
153
 
154
  # 4) Final Scoring & Grading
155
  final_score = max(0.0, min(100.0, ((raw_weighted_score + 1) / 2) * 100))
156
+
157
+ # ============================================================
158
+ # πŸ›‘ 2. SCORE THRESHOLD CHECK (> 50%)
159
+ # ============================================================
160
+ if final_score <= 50.0:
161
+ if verbose:
162
+ print(f"β›” [Governance FAIL] Score {final_score:.2f}% is too low (Must be > 50%).")
163
+ return self._create_rejection(f"Low Score: {final_score:.2f}% (Threshold > 50%)")
164
+
165
  grade = self._get_grade(final_score)
166
 
167
  result = {
 
176
  "structure": round(float(s_struct), 3),
177
  "order_book": round(float(s_ob), 3),
178
  },
179
+ "status": "APPROVED",
180
  }
181
 
182
  if include_details:
 
988
  def _get_grade(self, score: float) -> str:
989
  if score >= 85: return "ULTRA"
990
  if score >= 70: return "STRONG"
991
+ if score > 50: return "NORMAL"
 
992
  return "REJECT"
993
 
994
  def _create_rejection(self, reason: str):