GoshawkVortexAI commited on
Commit
bd01515
·
verified ·
1 Parent(s): 5b5d74d

Update scorer.py

Browse files
Files changed (1) hide show
  1. scorer.py +35 -19
scorer.py CHANGED
@@ -1,26 +1,37 @@
 
 
1
  import numpy as np
2
- from typing import Dict, Any
 
3
 
4
 
5
  def compute_structure_score(regime_data: Dict[str, Any]) -> float:
6
  trend = regime_data.get("trend", "ranging")
7
  structure = regime_data.get("structure", 0)
8
- vol_expanding = regime_data.get("volatility_expanding", False)
 
 
9
 
10
  if trend == "bullish":
11
- base = 1.0
12
  elif trend == "ranging":
13
  base = 0.4
14
  else:
15
  base = 0.1
16
 
17
  if structure == 1:
18
- base = min(1.0, base + 0.2)
19
  elif structure == -1:
20
- base = max(0.0, base - 0.2)
21
 
22
  if vol_expanding:
23
- base = max(0.0, base - 0.15)
 
 
 
 
 
 
24
 
25
  return float(np.clip(base, 0.0, 1.0))
26
 
@@ -42,28 +53,33 @@ def score_token(
42
  volume_score = float(np.clip(volume_data.get("volume_score", 0.0), 0.0, 1.0))
43
  structure_score = compute_structure_score(regime_data)
44
 
45
- regime_weight = 0.40
46
- volume_weight = 0.35
47
- structure_weight = 0.25
48
-
49
  total_score = (
50
- regime_score * regime_weight
51
- + volume_score * volume_weight
52
- + structure_score * structure_weight
53
  )
54
 
 
 
 
55
  return {
56
  "regime_score": round(regime_score, 4),
57
  "volume_score": round(volume_score, 4),
58
  "structure_score": round(structure_score, 4),
59
- "total_score": round(float(total_score), 4),
60
  }
61
 
62
 
63
- def rank_tokens(scored_tokens: Dict[str, Dict[str, Any]]) -> list:
64
- ranked = sorted(
65
- scored_tokens.items(),
66
- key=lambda x: x[1].get("total_score", 0.0),
 
 
67
  reverse=True,
68
  )
69
- return ranked
 
 
 
 
 
1
+ from typing import Dict, Any, List, Tuple
2
+
3
  import numpy as np
4
+
5
+ from config import WEIGHT_REGIME, WEIGHT_VOLUME, WEIGHT_STRUCTURE
6
 
7
 
8
  def compute_structure_score(regime_data: Dict[str, Any]) -> float:
9
  trend = regime_data.get("trend", "ranging")
10
  structure = regime_data.get("structure", 0)
11
+ vol_expanding = regime_data.get("vol_expanding", False)
12
+ vol_contracting = regime_data.get("vol_contracting", False)
13
+ atr_trend = regime_data.get("atr_trend", "falling")
14
 
15
  if trend == "bullish":
16
+ base = 0.8
17
  elif trend == "ranging":
18
  base = 0.4
19
  else:
20
  base = 0.1
21
 
22
  if structure == 1:
23
+ base = min(1.0, base + 0.15)
24
  elif structure == -1:
25
+ base = max(0.0, base - 0.15)
26
 
27
  if vol_expanding:
28
+ base = max(0.0, base - 0.1)
29
+
30
+ if vol_contracting and trend == "bullish":
31
+ base = max(0.0, base - 0.05)
32
+
33
+ if atr_trend == "rising" and trend == "bullish":
34
+ base = min(1.0, base + 0.05)
35
 
36
  return float(np.clip(base, 0.0, 1.0))
37
 
 
53
  volume_score = float(np.clip(volume_data.get("volume_score", 0.0), 0.0, 1.0))
54
  structure_score = compute_structure_score(regime_data)
55
 
 
 
 
 
56
  total_score = (
57
+ regime_score * WEIGHT_REGIME
58
+ + volume_score * WEIGHT_VOLUME
59
+ + structure_score * WEIGHT_STRUCTURE
60
  )
61
 
62
+ climax_penalty = 0.15 if volume_data.get("climax", False) else 0.0
63
+ total_score = float(np.clip(total_score - climax_penalty, 0.0, 1.0))
64
+
65
  return {
66
  "regime_score": round(regime_score, 4),
67
  "volume_score": round(volume_score, 4),
68
  "structure_score": round(structure_score, 4),
69
+ "total_score": round(total_score, 4),
70
  }
71
 
72
 
73
+ def rank_tokens(
74
+ scored_map: Dict[str, Dict[str, Any]],
75
+ ) -> List[Tuple[str, Dict[str, Any]]]:
76
+ return sorted(
77
+ scored_map.items(),
78
+ key=lambda item: item[1].get("total_score", 0.0),
79
  reverse=True,
80
  )
81
+
82
+
83
+ def format_score_bar(score: float, width: int = 20) -> str:
84
+ filled = int(round(score * width))
85
+ return "[" + "█" * filled + "░" * (width - filled) + f"] {score:.2f}"