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