Spaces:
Sleeping
Sleeping
fix: Align analyzer field names with MCP data structure
Browse filesValuation:
- Use pb_ratio/ps_ratio instead of price_to_book/price_to_sales
- Check both yahoo_finance and alpha_vantage sources (fallback)
Macro:
- Use interest_rate instead of fed_funds_rate
- Use cpi_inflation instead of cpi_yoy
- Use unemployment instead of unemployment_rate
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- src/nodes/analyzer.py +12 -10
src/nodes/analyzer.py
CHANGED
|
@@ -644,14 +644,16 @@ def _extract_key_metrics(raw_data: str) -> dict:
|
|
| 644 |
if not val or "error" in val:
|
| 645 |
val = data.get("multi_source", {}).get("valuation_all", {})
|
| 646 |
if val and "error" not in val:
|
| 647 |
-
|
| 648 |
-
|
|
|
|
|
|
|
| 649 |
extracted["valuation"] = {
|
| 650 |
-
"pe_trailing": _extract_valuation_metric(yf_val.get("trailing_pe", {})),
|
| 651 |
-
"pe_forward": _extract_valuation_metric(yf_val.get("forward_pe", {})),
|
| 652 |
-
"pb_ratio": _extract_valuation_metric(yf_val.get("
|
| 653 |
-
"ps_ratio": _extract_valuation_metric(yf_val.get("
|
| 654 |
-
"ev_ebitda": _extract_valuation_metric(yf_val.get("ev_ebitda", {})),
|
| 655 |
"valuation_signal": val.get("overall_signal"),
|
| 656 |
}
|
| 657 |
|
|
@@ -692,9 +694,9 @@ def _extract_key_metrics(raw_data: str) -> dict:
|
|
| 692 |
|
| 693 |
extracted["macro"] = {
|
| 694 |
"gdp_growth": _extract_valuation_metric(bea.get("gdp_growth", {})),
|
| 695 |
-
"interest_rate": _extract_valuation_metric(fred.get("
|
| 696 |
-
"inflation": _extract_valuation_metric(bls.get("
|
| 697 |
-
"unemployment": _extract_valuation_metric(bls.get("
|
| 698 |
}
|
| 699 |
|
| 700 |
# Extract news with VADER sentiment
|
|
|
|
| 644 |
if not val or "error" in val:
|
| 645 |
val = data.get("multi_source", {}).get("valuation_all", {})
|
| 646 |
if val and "error" not in val:
|
| 647 |
+
# New MCP structure: {yahoo_finance: {...}, alpha_vantage: {...}}
|
| 648 |
+
# Check both sources - yahoo_finance is primary, alpha_vantage is fallback
|
| 649 |
+
yf_val = val.get("yahoo_finance", {})
|
| 650 |
+
av_val = val.get("alpha_vantage", {})
|
| 651 |
extracted["valuation"] = {
|
| 652 |
+
"pe_trailing": _extract_valuation_metric(yf_val.get("trailing_pe") or av_val.get("trailing_pe", {})),
|
| 653 |
+
"pe_forward": _extract_valuation_metric(yf_val.get("forward_pe") or av_val.get("forward_pe", {})),
|
| 654 |
+
"pb_ratio": _extract_valuation_metric(yf_val.get("pb_ratio") or av_val.get("pb_ratio", {})),
|
| 655 |
+
"ps_ratio": _extract_valuation_metric(yf_val.get("ps_ratio") or av_val.get("ps_ratio", {})),
|
| 656 |
+
"ev_ebitda": _extract_valuation_metric(av_val.get("ev_ebitda") or yf_val.get("ev_ebitda", {})),
|
| 657 |
"valuation_signal": val.get("overall_signal"),
|
| 658 |
}
|
| 659 |
|
|
|
|
| 694 |
|
| 695 |
extracted["macro"] = {
|
| 696 |
"gdp_growth": _extract_valuation_metric(bea.get("gdp_growth", {})),
|
| 697 |
+
"interest_rate": _extract_valuation_metric(fred.get("interest_rate", {})),
|
| 698 |
+
"inflation": _extract_valuation_metric(bls.get("cpi_inflation", {})),
|
| 699 |
+
"unemployment": _extract_valuation_metric(bls.get("unemployment", {})),
|
| 700 |
}
|
| 701 |
|
| 702 |
# Extract news with VADER sentiment
|