Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
a762158
1
Parent(s):
8e147e7
fix: resolve Chronos API error and display advanced risk metrics
Browse filesFix critical issues preventing ML forecasts and hiding P1 metrics:
1. Chronos API call mismatch
- Changed predict() to use positional argument instead of keyword
- Fixed: ChronosBoltPipeline.predict() error with 'context' parameter
- Changed torch_dtype to dtype parameter to resolve deprecation warning
2. Missing advanced metrics display
- Extract Information Ratio, Calmar Ratio, Ulcer Index from risk analysis
- Display metrics conditionally in UI when available
- Metrics were calculated but never shown to users
Backend changes:
- backend/mcp_servers/ensemble_predictor_mcp.py (lines 178, 192)
Frontend changes:
- app.py format_analysis_result() (lines 300-321)
Test coverage: All 19 P1 tests passing
- app.py +13 -0
- backend/mcp_servers/ensemble_predictor_mcp.py +2 -2
app.py
CHANGED
|
@@ -297,6 +297,11 @@ def format_analysis_result(final_state: AgentState, holdings: List[Dict[str, Any
|
|
| 297 |
sharpe = float(risk_metrics.get("sharpe_ratio", 0))
|
| 298 |
volatility = float(risk_metrics.get("volatility_annual", 0)) * 100
|
| 299 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
metrics_md = f"""
|
| 301 |
### Key Metrics
|
| 302 |
|
|
@@ -307,6 +312,14 @@ def format_analysis_result(final_state: AgentState, holdings: List[Dict[str, Any
|
|
| 307 |
- **CVaR (95%)**: ${cvar_95:,.2f}
|
| 308 |
"""
|
| 309 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
# Format ML forecasts if available
|
| 311 |
forecasts_md = ""
|
| 312 |
ensemble_forecasts = final_state.get("ensemble_forecasts", {})
|
|
|
|
| 297 |
sharpe = float(risk_metrics.get("sharpe_ratio", 0))
|
| 298 |
volatility = float(risk_metrics.get("volatility_annual", 0)) * 100
|
| 299 |
|
| 300 |
+
# Extract advanced metrics
|
| 301 |
+
information_ratio = risk_metrics.get("information_ratio")
|
| 302 |
+
calmar_ratio = risk_metrics.get("calmar_ratio")
|
| 303 |
+
ulcer_index = risk_metrics.get("ulcer_index")
|
| 304 |
+
|
| 305 |
metrics_md = f"""
|
| 306 |
### Key Metrics
|
| 307 |
|
|
|
|
| 312 |
- **CVaR (95%)**: ${cvar_95:,.2f}
|
| 313 |
"""
|
| 314 |
|
| 315 |
+
# Add advanced metrics if available
|
| 316 |
+
if information_ratio is not None:
|
| 317 |
+
metrics_md += f"- **Information Ratio**: {float(information_ratio):.2f}\n"
|
| 318 |
+
if calmar_ratio is not None:
|
| 319 |
+
metrics_md += f"- **Calmar Ratio**: {float(calmar_ratio):.2f}\n"
|
| 320 |
+
if ulcer_index is not None:
|
| 321 |
+
metrics_md += f"- **Ulcer Index**: {float(ulcer_index):.2f}\n"
|
| 322 |
+
|
| 323 |
# Format ML forecasts if available
|
| 324 |
forecasts_md = ""
|
| 325 |
ensemble_forecasts = final_state.get("ensemble_forecasts", {})
|
backend/mcp_servers/ensemble_predictor_mcp.py
CHANGED
|
@@ -175,7 +175,7 @@ def _forecast_chronos(
|
|
| 175 |
_chronos_pipeline = BaseChronosPipeline.from_pretrained(
|
| 176 |
model_name,
|
| 177 |
device_map=device,
|
| 178 |
-
|
| 179 |
)
|
| 180 |
logger.info(f"Chronos model loaded successfully on {device}")
|
| 181 |
except Exception as e:
|
|
@@ -189,7 +189,7 @@ def _forecast_chronos(
|
|
| 189 |
# Generate forecast
|
| 190 |
try:
|
| 191 |
forecast = _chronos_pipeline.predict(
|
| 192 |
-
|
| 193 |
prediction_length=horizon,
|
| 194 |
)
|
| 195 |
|
|
|
|
| 175 |
_chronos_pipeline = BaseChronosPipeline.from_pretrained(
|
| 176 |
model_name,
|
| 177 |
device_map=device,
|
| 178 |
+
dtype=dtype,
|
| 179 |
)
|
| 180 |
logger.info(f"Chronos model loaded successfully on {device}")
|
| 181 |
except Exception as e:
|
|
|
|
| 189 |
# Generate forecast
|
| 190 |
try:
|
| 191 |
forecast = _chronos_pipeline.predict(
|
| 192 |
+
context_tensor,
|
| 193 |
prediction_length=horizon,
|
| 194 |
)
|
| 195 |
|