load data points for economic table

i would like to build a tabel with economic data, but it is not possible to receive data, i tried different fields and checked "DIB" in workspace, are there any fields working?
import refinitiv.data as rd
import pandas as pd
from datetime import datetime, timedelta
from IPython.display import display, HTML
INDICATORS = {
"US_PMI_SERVICES": {
"ric": "aXGBUSA/A", # PMI Dienstleistungen
"name": "US PMI Services Index",
"interval": "monthly",
"thresholds": {
"red_below": 49.0,
"green_above": 51.0,
"orange_range": (49.0, 51.0)
},
"good_is_high": True,
"status_description": {
"green": "Expansion (über 51)",
"orange": "Neutral/Leichte Veränderung (49-51)",
"red": "Kontraktion (unter 49)"
}
},
"GLOBAL_PMI_MANUFACTURING": {
"ric": "XWPMIM=ECI", # PMI Industrie Weltweit
"name": "Global PMI Manufacturing Index",
"interval": "monthly",
"thresholds": {
"red_below": 49.0,
"green_above": 51.0,
"orange_range": (49.0, 51.0)
},
"good_is_high": True,
"status_description": {
"green": "Expansion (über 51)",
"orange": "Neutral/Leichte Veränderung (49-51)",
"red": "Kontraktion (unter 49)"
}
},
"US_ISM_NEW_ORDERS": {
"ric": "USISMN=ECI", # ISM New Orders
"name": "US ISM New Orders Index",
"interval": "monthly",
"thresholds": {
"red_below": 48.0,
"green_above": 53.0,
"orange_range": (48.0, 53.0)
},
"good_is_high": True,
"status_description": {
"green": "Starkes Wachstum (über 53)",
"orange": "Moderates Wachstum (48-53)",
"red": "Kontraktion/Schwäche (unter 48)"
}
},
"OECD_CLI_USA": {
"ric": "aoctliatadj/A", # OECD CLI USA
"name": "OECD CLI USA",
"field": "VALUE", # explizit VALUE für get_data verwenden
"interval": "daily", # auf daily gesetzt, um get_data besser nutzen zu können
"thresholds": {
"red_below": 99.0,
"green_above": 101.0,
"orange_range": (99.0, 101.0)
},
"good_is_high": True,
"status_description": {
"green": "Über Trend-Wachstum (über 101)",
"orange": "Um Trend-Wachstum (99-101)",
"red": "Unter Trend-Wachstum (unter 99)"
}
},
"OECD_CLI_EUROZONE": {
"ric": "Axzclead", # OECD CLI Eurozone
"name": "OECD CLI Eurozone",
"field": "VALUE", # explizit VALUE für get_data verwenden
"interval": "daily", # auf daily gesetzt
"thresholds": {
"red_below": 99.0,
"green_above": 101.0,
"orange_range": (99.0, 101.0)
},
"good_is_high": True,
"status_description": {
"green": "Über Trend-Wachstum (über 101)",
"orange": "Um Trend-Wachstum (99-101)",
"red": "Unter Trend-Wachstum (unter 99)"
}
},
# "US_YIELD_CURVE": { # Vorübergehend auskommentiert aufgrund von RIC-Fehlern
# "ric": ("FRTCM10", "FRTBS3M"), # Zinskurve: 10-Jahres Treasury Constant Maturity minus 3-Monats Treasury Bill
# "name": "US Zinskurve (10Y-3M)",
# "interval": "daily", # Zinsdaten sind täglich
# "thresholds": {
# "green_above": 0.0, # Positiv = keine Rezession
# "red_below": 0.0, # Negativ = Rezession
# "orange_range": (-0.05, 0.05) # Kleiner Puffer um 0 für neutral, kann angepasst werden
# },
# "good_is_high": True, # Höhere Werte (positiver Spread) sind besser
# "status_description": {
# "green": "Normal (positive Steigung)",
# "orange": "Flach/Nahe Inversion",
# "red": "Invertiert (Rezessionssignal)"
# },
# "is_spread": True # Kennzeichnet, dass es sich um einen Spread handelt
# },
# --- ECONOMIC SURPRISE INDIKATOREN ---
"CESI_USD": {
"ric": ".CESIUSD", # Citi Economic Surprise Index - USA
"name": "Citi ESI - USA",
"field": "CF_LAST", # Spezifisches Feld für diesen Indikator
"interval": "daily",
"thresholds": {
"green_above": 10.0, # Über 10 ist grün
"red_below": -10.0, # Unter -10 ist rot
"orange_range": (-10.0, 10.0) # Zwischen -10 und 10 ist orange
},
"good_is_high": True,
"status_description": {
"green": "Pos. Überraschungen (Econ. > Erwartungen)",
"orange": "Neutrale Überraschungen (Econ. = Erwartungen)",
"red": "Neg. Überraschungen (Econ. < Erwartungen)"
}
},
"CESI_EUROZONE": {
"ric": ".CESIEUR", # Citi Economic Surprise Index - Eurozone
"name": "Citi ESI - Eurozone",
"field": "CF_LAST", # Spezifisches Feld für diesen Indikator
"interval": "daily",
"thresholds": {
"green_above": 10.0,
"red_below": -10.0,
"orange_range": (-10.0, 10.0)
},
"good_is_high": True,
"status_description": {
"green": "Pos. Überraschungen (Econ. > Erwartungen)",
"orange": "Neutrale Überraschungen (Econ. = Erwartungen)",
"red": "Neg. Überraschungen (Econ. < Erwartungen)"
}
},
"CESI_CHINA": {
"ric": ".CESICNY", # Citi Economic Surprise Index - China (RIC korrigiert)
"name": "Citi ESI - China",
"field": "CF_LAST", # Spezifisches Feld für diesen Indikator
"interval": "daily",
"thresholds": {
"green_above": 10.0,
"red_below": -10.0,
"orange_range": (-10.0, 10.0)
},
"good_is_high": True,
"status_description": {
"green": "Pos. Überraschungen (Econ. > Erwartungen)",
"orange": "Neutrale Überraschungen (Econ. = Erwartungen)",
"red": "Neg. Überraschungen (Econ. < Erwartungen)"
}
},
# --- NEUE TREASURY INDIKATOREN ---
"US_10Y_TREASURY_YIELD": {
"ric": "US10YT=RR", # 10-jährige US Treasury Rendite (Constant Maturity Rate)
"name": "US 10Y Treasury Yield",
"field": "CF_YIELD", # Abzufragendes Feld (Rendite)
"interval": "daily", # Renditen sind täglich verfügbar
"thresholds": {
"green_above": 4.0, # Beispiel: Über 4% könnte auf starke Konjunktur/Inflation hindeuten
"red_below": 3.0, # Beispiel: Unter 3% könnte auf Konjunktursorgen hindeuten
"orange_range": (3.0, 4.0)
},
"good_is_high": True, # Höhere Renditen können auf Wachstum hindeuten (kontextabhängig!)
"status_description": {
"green": "Höher (Wirtschaftswachstum / Inflationserwartung)",
"orange": "Moderat",
"red": "Niedriger (Konjunktursorgen)"
}
},
"US_2Y_TREASURY_YIELD": {
"ric": "US2YT=RR", # 2-jährige US Treasury Rendite (Constant Maturity Rate)
"name": "US 2Y Treasury Yield",
"field": "CF_YIELD", # Abzufragendes Feld (Rendite)
"interval": "daily",
"thresholds": {
"green_above": 4.5, # Beispiel: Höhere kurzfristige Renditen spiegeln oft Zinserhöhungserwartungen wider
"red_below": 3.5,
"orange_range": (3.5, 4.5)
},
"good_is_high": True,
"status_description": {
"green": "Höher (Zinserhöhungserwartung)",
"orange": "Moderat",
"red": "Niedriger (Zinssenkungserwartung)"
}
},
# --- NEUER US CPI INDIKATOR ---
"US_CPI": {
"ric": "aUSCPI", # US Consumer Price Index
"name": "US Consumer Price Index (YoY)",
"field": "VALUE", # Abzufragendes Feld (Standard für historische Zeitreihen)
"interval": "monthly", # CPI ist typischerweise monatlich
"thresholds": {
# Für CPI definieren wir einen "guten" Bereich
"green_min": 1.5,
"green_max": 2.5,
# Rot außerhalb aller orange/grün Bereiche
"red_below": 0.5,
"red_above": 4.0
# Orange ist implizit: Wenn nicht grün und nicht rot.
},
"good_is_range": True, # Neuer Parameter, um anzuzeigen, dass 'gut' ein Bereich ist
"status_description": {
"green": "Zielbereich (moderate Inflation)",
"orange": "Abweichung vom Ziel (moderater Druck)",
"red": "Starke Abweichung (hohe Inflation / Deflationsrisiko)"
}
}
}
end_date = datetime.now()
start_date = end_date - timedelta(days=365 * 2) # Mehr Daten für tägliche Indizes
def get_indicator_data(indicator_config):
"""
Ruft Daten für einen bestimmten Indikator ab und wendet die Ampel-Logik an.
Gibt ein Dictionary mit Datum, Wert, Farbe und Status-Text zurück.
"""
ric_or_tuple = indicator_config["ric"]
name = indicator_config["name"]
interval = indicator_config["interval"]
thresholds = indicator_config["thresholds"]
status_desc = indicator_config["status_description"]
is_spread = indicator_config.get("is_spread", False)
field_to_query = indicator_config.get("field", "VALUE")
good_is_range = indicator_config.get("good_is_range", False) # Neuer Parameter für Bereichslogik
print(f"Rufe Daten für {name} ({ric_or_tuple}) mit Feld '{field_to_query}' ab...")--- Hauptausführung ---
try:
df = pd.DataFrame() # Initialize df
if is_spread:
# Der auskommentierte Spread-Teil bleibt hier unverändert.
# Wenn US_YIELD_CURVE aktiviert wird, muss sichergestellt sein,
# dass die RICs (FRTCM10, FRTBS3M) über get_history mit VALUE abrufbar sind.
ric1, ric2 = ric_or_tuple
df1 = rd.get_history(
universe=ric1,
fields="VALUE",
start=start_date.strftime('%Y-%m-%d'),
end=end_date.strftime('%Y-%m-%d'),
interval=interval
)
df2 = rd.get_history(
universe=ric2,
fields="VALUE",
start=start_date.strftime('%Y-%m-%d'),
end=end_date.strftime('%Y-%m-%d'),
interval=interval
)
if df1.empty or df2.empty:
print(f"Keine ausreichenden Daten für Spread {name}.")
return {
"name": name,
"date": "N/A",
"value": "N/A",
"color": "gray",
"status": "Daten nicht verfügbar für Spread"
}
df_spread = pd.merge(df1.rename(columns={'VALUE': 'RIC1_Value'}),
df2.rename(columns={'VALUE': 'RIC2_Value'}),
left_index=True, right_index=True, how='inner')
df_spread['Value'] = df_spread['RIC1_Value'] - df_spread['RIC2_Value']
df_spread.index.name = 'Date'
df = df_spread
else: # Standardfall für einzelne RICs
if "field" in indicator_config: # Wenn ein spezifisches Feld angegeben ist, verwenden wir get_data (Snapshot)
data_snapshot = rd.get_data(universe=ric_or_tuple, fields=field_to_query)
if not data_snapshot.empty and ric_or_tuple in data_snapshot.index and field_to_query in data_snapshot.columns:
raw_value = data_snapshot.loc[ric_or_tuple, field_to_query]
if isinstance(raw_value, pd.Series):
latest_value = raw_value.iloc[0]
else:
latest_value = raw_value
latest_date = datetime.now().strftime('%Y-%m-%d') # Snapshot-Datum ist heute
df = pd.DataFrame([latest_value], index=[datetime.now()], columns=['Value'])
df.index.name = 'Date'
else:
print(f"Warnung: get_data lieferte keine gültigen Daten für {name} mit Feld '{field_to_query}'.")
df = pd.DataFrame()
else: # Andernfalls (kein explizites 'field'), versuchen wir get_history mit 'VALUE' (Zeitreihe)
df = rd.get_history(
universe=ric_or_tuple,
fields="VALUE",
start=start_date.strftime('%Y-%m-%d'),
end=end_date.strftime('%Y-%m-%d'),
interval=interval
)
if not df.empty and 'VALUE' in df.columns:
df.rename(columns={'VALUE': 'Value'}, inplace=True) # Ensure 'Value' column
else:
print(f"Warnung: get_history lieferte keine gültigen Daten für {name} mit Feld 'VALUE'.")
df = pd.DataFrame()
if df.empty:
print(f"Keine Daten für {name} gefunden (DataFrame ist leer).")
return {
"name": name,
"date": "N/A",
"value": "N/A",
"color": "gray",
"status": "Daten nicht verfügbar"
}
else:
if 'Value' not in df.columns:
print(f"Fehler: 'Value' Spalte nicht im DataFrame für {name} gefunden. Datenfehler.")
return {
"name": name,
"date": "N/A",
"value": "N/A",
"color": "gray",
"status": "Datenfeld nicht verfügbar"
}
if not df['Value'].dropna().empty:
latest_value = df['Value'].dropna().iloc[-1]
if "field" in indicator_config: # Wenn get_data verwendet wurde, ist das Datum heute
latest_date = datetime.now().strftime('%Y-%m-%d')
else: # Wenn get_history verwendet wurde, ist das Datum der letzte Index-Eintrag
latest_date = df['Value'].dropna().index[-1].strftime('%Y-%m-%d')
else:
latest_value = None
latest_date = "N/A"
if latest_value is None:
return {
"name": name,
"date": "N/A",
"value": "N/A",
"color": "gray",
"status": "Keine gültigen Daten verfügbar"
}
color = "gray"
status_text = "Nicht definiert"
# --- Ampel-Logik angepasst für "good_is_range" ---
if good_is_range:
green_min = thresholds.get("green_min")
green_max = thresholds.get("green_max")
red_below = thresholds.get("red_below")
red_above = thresholds.get("red_above")
if green_min is not None and green_max is not None and green_min <= latest_value <= green_max:
color = "green"
status_text = status_desc.get("green", "Optimaler Bereich")
elif red_below is not None and latest_value < red_below:
color = "red"
status_text = status_desc.get("red", "Kritisch niedrig")
elif red_above is not None and latest_value > red_above:
color = "red"
status_text = status_desc.get("red", "Kritisch hoch")
else:
# Wenn nicht grün und nicht rot, dann orange
color = "orange"
status_text = status_desc.get("orange", "Moderate Abweichung")
else: # Ursprüngliche Ampel-Logik für good_is_high/low und orange_range
red_below = thresholds.get("red_below")
red_above = thresholds.get("red_above")
green_below = thresholds.get("green_below")
green_above = thresholds.get("green_above")
orange_range = thresholds.get("orange_range")
if green_above is not None and latest_value > green_above:
color = "green"
status_text = status_desc.get("green", "Gut")
elif green_below is not None and latest_value < green_below:
color = "green"
status_text = status_desc.get("green", "Gut")
elif red_below is not None and latest_value < red_below:
color = "red"
status_text = status_desc.get("red", "Schlecht")
elif red_above is not None and latest_value > red_above:
color = "red"
status_text = status_desc.get("red", "Schlecht")
elif orange_range is not None and orange_range[0] <= latest_value <= orange_range[1]:
color = "orange"
status_text = status_desc.get("orange", "Neutral")
else:
# Fallback für Werte, die nicht explizit in den Bereichen liegen
# Dies ist für Indikatoren, wo 'good_is_high' oder 'good_is_low' zutrifft,
# aber der Wert nicht exakt in einem der definierten Schwellenwerte liegt.
if indicator_config.get("good_is_high", True): # Standard ist 'good_is_high'
if (green_above is not None and latest_value > green_above):
color = "green"
status_text = status_desc.get("green", "Positiv")
elif (red_below is not None and latest_value < red_below):
color = "red"
status_text = status_desc.get("red", "Negativ")
else:
color = "orange"
status_text = status_desc.get("orange", "Unbestimmt")
else: # Fallback für good_is_low
if (green_below is not None and latest_value < green_below):
color = "green"
status_text = status_desc.get("green", "Positiv")
elif (red_above is not None and latest_value > red_above):
color = "red"
status_text = status_desc.get("red", "Negativ")
else:
color = "orange"
status_text = status_desc.get("orange", "Unbestimmt")
return {
"name": name,
"date": latest_date,
"value": f"{latest_value:.2f}",
"color": color,
"status": status_text
}
except Exception as e:
print(f"Fehler beim Abrufen von {name} ({ric_or_tuple}): {e}")
return {
"name": name,
"date": "N/A",
"value": "N/A",
"color": "gray",
"status": f"Fehler: {e}"
}
if name == "main":
try:
rd.open_session()
results = []
for key, config in INDICATORS.items():
results.append(get_indicator_data(config))
# --- HTML-Tabelle mit Ampelsystem erstellen ---
html_table = f"""
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap');
body {{ font-family: 'Inter', sans-serif; }}
table {{
width: 90%;
border-collapse: collapse;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
margin: 20px auto;
}}
th, td {{
border: 1px solid #e0e0e0;
padding: 12px 15px;
text-align: left;
}}
th {{
background-color: #f0f4f8;
color: #333;
font-weight: 600;
}}
tbody tr:nth-child(even) {{
background-color: #f9f9f9;
}}
tbody tr:hover {{
background-color: #f1f1f1;
}}
.green {{
background-color: #d4edda;
color: #155724;
font-weight: bold;
}}
.orange {{
background-color: #fff3cd;
color: #856404;
font-weight: bold;
}}
.red {{
background-color: #f8d7da;
color: #721c24;
font-weight: bold;
}}
.gray {{
background-color: #e9ecef;
color: #495057;
font-weight: normal;
}}
h2 {{
text-align: center;
color: #333;
font-family: 'Inter', sans-serif;
margin-top: 30px;
margin-bottom: 20px;
}}
p {{
text-align: center;
color: #555;
font-family: 'Inter', sans-serif;
margin-bottom: 30px;
}}
</style>
<h2>GKB Makro View - Factors to watch</h2>
<p>Aktuelle Werte und Status (Stand: {datetime.now().strftime('%Y-%m-%d %H:%M')})</p>
<table>
<thead>
<tr>
<th>Indikator</th>
<th>Datum</th>
<th>Wert</th>
<th>Status</th>
</tr>
</thead>
<tbody>
"""
for res in results:
html_table += f"""
<tr>
<td>{res['name']}</td>
<td>{res['date']}</td>
<td class='{res['color']}'>{res['value']}</td>
<td class='{res['color']}'>{res['status']}</td>
</tr>
"""
html_table += """
</tbody>
</table>
"""
display(HTML(html_table))
except Exception as e:
print(f"Ein Fehler ist aufgetreten: {e}")
finally:
rd.close_session()
print("\nSkript beendet.")
Answers
-
Thank you for reaching out to us.
This forum is dedicated to software developers using LSEG APIs. The moderators on this forum do not have deep expertise in every bit of content available through LSEG products, which is required to answer content questions such as this one.
The best resource for content questions is the Helpdesk support team, which can be reached by submitting queries through MyAccount. The support team will either have the required content expertise ready available or can reach out to relevant content experts to get the answer for you.
0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 684 Datastream
- 1.4K DSS
- 615 Eikon COM
- 5.2K Eikon Data APIs
- 10 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 251 ETA
- 556 WebSocket API
- 37 FX Venues
- 14 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 275 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 22 RDMS
- 1.9K Refinitiv Data Platform
- 649 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 27 DACS Station
- 121 Open DACS
- 1.1K RFA
- 104 UPA
- 193 TREP Infrastructure
- 228 TRKD
- 916 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 90 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 46 中文论坛