Spaces:
Sleeping
Sleeping
Create core_engine.py
Browse files- core_engine.py +18 -0
core_engine.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import math
|
| 2 |
+
from typing import Dict
|
| 3 |
+
|
| 4 |
+
def harmonize_price(raw_price: float, physical_indicator: float, lag_factor: float) -> Dict[str, float]:
|
| 5 |
+
"""
|
| 6 |
+
Returns harmonized pricing with distortion and confidence.
|
| 7 |
+
"""
|
| 8 |
+
# Correction reduces false inflation from synthetic trading
|
| 9 |
+
correction = (raw_price - physical_indicator) * min(1.0, lag_factor)
|
| 10 |
+
harmonized = raw_price - correction
|
| 11 |
+
confidence = 1.0 - abs(correction) / max(raw_price, 1)
|
| 12 |
+
|
| 13 |
+
return {
|
| 14 |
+
"raw_price": raw_price,
|
| 15 |
+
"harmonized_price": round(harmonized, 4),
|
| 16 |
+
"distortion": round(correction, 4),
|
| 17 |
+
"confidence": round(max(0.0, min(confidence, 1.0)), 4)
|
| 18 |
+
}
|