Spaces:
Sleeping
Sleeping
Update economic_service.py
Browse files- economic_service.py +15 -12
economic_service.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
# economic_service.py
|
| 2 |
|
| 3 |
from typing import Dict
|
| 4 |
-
import math
|
| 5 |
|
| 6 |
def harmonize(
|
| 7 |
commodity: str,
|
|
@@ -9,21 +8,25 @@ def harmonize(
|
|
| 9 |
reporting_lag: int,
|
| 10 |
) -> Dict:
|
| 11 |
"""
|
| 12 |
-
Deterministic economic harmonization
|
| 13 |
"""
|
| 14 |
-
|
|
|
|
| 15 |
synthetic_index = physical_anchor / lag_factor
|
| 16 |
|
| 17 |
confidence = max(
|
| 18 |
0.0,
|
| 19 |
-
min(
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
"commodity": commodity,
|
| 24 |
-
"
|
| 25 |
-
"
|
| 26 |
-
"
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
return result
|
|
|
|
| 1 |
# economic_service.py
|
| 2 |
|
| 3 |
from typing import Dict
|
|
|
|
| 4 |
|
| 5 |
def harmonize(
|
| 6 |
commodity: str,
|
|
|
|
| 8 |
reporting_lag: int,
|
| 9 |
) -> Dict:
|
| 10 |
"""
|
| 11 |
+
Deterministic economic harmonization function.
|
| 12 |
"""
|
| 13 |
+
|
| 14 |
+
lag_factor = 1.0 + (reporting_lag * 0.005)
|
| 15 |
synthetic_index = physical_anchor / lag_factor
|
| 16 |
|
| 17 |
confidence = max(
|
| 18 |
0.0,
|
| 19 |
+
min(
|
| 20 |
+
1.0,
|
| 21 |
+
1.0 - abs(physical_anchor - synthetic_index)
|
| 22 |
+
/ (physical_anchor + 1e-9),
|
| 23 |
+
),
|
| 24 |
+
)
|
| 25 |
|
| 26 |
+
return {
|
| 27 |
"commodity": commodity,
|
| 28 |
+
"physical_anchor": physical_anchor,
|
| 29 |
+
"reporting_lag_days": reporting_lag,
|
| 30 |
+
"synthetic_index": round(synthetic_index, 4),
|
| 31 |
+
"confidence": round(confidence, 4),
|
| 32 |
+
}
|
|
|