Update scorer.py
Browse files
scorer.py
CHANGED
|
@@ -1,26 +1,37 @@
|
|
|
|
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
-
|
|
|
|
| 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("
|
|
|
|
|
|
|
| 9 |
|
| 10 |
if trend == "bullish":
|
| 11 |
-
base =
|
| 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.
|
| 19 |
elif structure == -1:
|
| 20 |
-
base = max(0.0, base - 0.
|
| 21 |
|
| 22 |
if vol_expanding:
|
| 23 |
-
base = max(0.0, base - 0.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 *
|
| 51 |
-
+ volume_score *
|
| 52 |
-
+ structure_score *
|
| 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(
|
| 60 |
}
|
| 61 |
|
| 62 |
|
| 63 |
-
def rank_tokens(
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
| 67 |
reverse=True,
|
| 68 |
)
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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}"
|