Spaces:
Sleeping
Sleeping
| # economic_service.py | |
| from typing import Dict | |
| def harmonize( | |
| commodity: str, | |
| physical_anchor: float, | |
| reporting_lag: int, | |
| ) -> Dict: | |
| """ | |
| Deterministic economic harmonization function. | |
| """ | |
| lag_factor = 1.0 + (reporting_lag * 0.005) | |
| synthetic_index = physical_anchor / lag_factor | |
| confidence = max( | |
| 0.0, | |
| min( | |
| 1.0, | |
| 1.0 - abs(physical_anchor - synthetic_index) | |
| / (physical_anchor + 1e-9), | |
| ), | |
| ) | |
| return { | |
| "commodity": commodity, | |
| "physical_anchor": physical_anchor, | |
| "reporting_lag_days": reporting_lag, | |
| "synthetic_index": round(synthetic_index, 4), | |
| "confidence": round(confidence, 4), | |
| } |