from IPython.display import Markdown
import pandas as pd
from tulip.core.collection import TulipCollection
from tulip.data.bloomberg import BloombergClient as bb
from tulip.data.haver import HaverClient as hc
from tulip.plots import plot_line, plot_lines
from tulip.data.gs import GSClient as gs
from tulip.analysis.country_related.analytics import summarize_gs_eco_fct
import pycountry
ISO_2 = "BR"
haver_code = 223
pyctry = pycountry.countries.get(alpha_2=ISO_2)
Economic Forecasts (Brokers)¶
gs_eco_fct = gs.get_eco_forecast(geographyId=ISO_2)
gs_summary = summarize_gs_eco_fct(gs_eco_fct)
gs_summary = gs_summary[~gs_summary.index.str.contains("ngdp")].to_frame().T
gs_summary.style.set_caption(f"Goldman {pyctry.name} Economic Forecasts").format(
precision=2
)Current Activity Indicator (Goldman)¶
cai_series_soft_vs_hard = gs.get_CAI_series(
geographyId=ISO_2,
metricName=[
"CAI_HEADLINE",
"CAI_CONTRIBUTION_TYPE_HARD",
"CAI_CONTRIBUTION_TYPE_SOFT",
],
startDate="1980-01-01",
)
cai_series_soft_vs_hard = cai_series_soft_vs_hard.set_index("metricName", append=True)[
"metricValue"
].unstack("metricName")
cai_series_soft_vs_hard.columns = ["Hard", "Soft", "Headline"]
cai_plot = plot_lines(
cai_series_soft_vs_hard,
show_0=True,
title=f"<b>{pyctry.name} Current Activity Indicator</b> Updated: {pd.Timestamp.today().strftime('%Y-%m-%d')}",
years_limit=4,
)
cai_plotreal_gdp_yoy = hc.get_series("S223NGPC@EMERGE")
real_gdp_yoy.ts = real_gdp_yoy.ts.pct_change(4)
real_gdp_yoy.plot(show_0=True, tick_format="0.0%")GDP Detail:¶
growth_stats = {
"Real GDP": f"yryr%(S{haver_code}NGPC@EMERGE)", # Real Gross Domestic Product at Market Prices
"Fixed Investment": f"yryr%(S{haver_code}NFC@EMERGE)", # GDP: Gross Fixed Capital Formation
# "Inventories": f"S{haver_code}NBC@EMERGE", # GDP: Investment in Inventories
# "Consumption": f"yryr%(S{haver_code}NCC@EMERGE)", # GDP: Final Consumption Expenditure
"Private Consumption": f"yryr%(S{haver_code}NCPC@EMERGE)", # [Brazil: GDP: Private Consumption (SA, Mil.Chained.1995.Reais)]
"Public Consumption": f"yryr%(S{haver_code}NCGC@EMERGE)", # [Brazil: GDP: Government Consumption (SA, Mil.Chained.1995.Reais)]
"Exports": f"yryr%(S{haver_code}NXC@EMERGE)", # GDP: Exports of Goods and Services
"Imports": f"yryr%(S{haver_code}NMC@EMERGE)", # GDP: Imports of Goods and Services
}
growth_stats_collection = []
for k, v in growth_stats.items():
growth_stats_collection.append(hc.get_series(v))
growth_stats_collection = TulipCollection(growth_stats_collection)
# todo: be able to change to down only one gtime series
growth_stats_collection.dashboard.table()growth_stats_collection.dashboard.plots(show_0=True)Nominal GDP:¶
#### Nominal GDP:
hc.get_series(f"yryr%(H{haver_code}NGDP@EMERGE)").plot(
show_0=True, years_limit=4
) # Nominal GDP GrowthTrade¶
trade_stats = {
"Current Account Balance % GDP": f"H{haver_code}BCPG@EMERGE",
}
trade_collection = []
for k, v in trade_stats.items():
trade_collection.append(hc.get_series(v))
trade_collection = TulipCollection(trade_collection)
trade_collection.dashboard.table()trade_collection.dashboard.plots(show_0=True)Surveys¶
Fundacion Geturlio Vargas are the most tracked Sentiment Indicators
fgv_surveys = {
"Business industry": {
"confidence_index": "S223VBT@EMERGELA",
"current_condition": "S223VBTC@EMERGELA",
"expectations_index": "S223VBTE@EMERGELA",
},
"Manufacturing (CNAE 2.0)": {
"confidence_index": "S223VM@EMERGELA",
"current_condition": "S223VMC@EMERGELA",
"expectations_index": "S223VME@EMERGELA",
},
"Services": {
"confidence_index": "S223VS@EMERGELA",
"current_condition": "S223VSC@EMERGELA",
"expectations_index": "S223VSE@EMERGELA",
},
"Trade/commerce (TCOI)": {
"confidence_index": "S223VR@EMERGELA",
"current_condition": "S223VRC@EMERGELA",
"expectations_index": "S223VRE@EMERGELA",
},
}
fgv_surveys_collection = []
for category, metrics in fgv_surveys.items():
for metric_name, code in metrics.items():
fgv_surveys_collection.append(hc.get_series(code))
fgv_surveys_collection = TulipCollection(fgv_surveys_collection)
fgv_surveys_collection.dashboard.table()fig = plot_lines(
[ts.ts for ts in fgv_surveys_collection[0:3]],
title="Brazil: Business Manufacturing Index",
)
fig.update_traces(name="Confidence Index", selector=dict(name="S223VBT@EMERGELA"))
fig.update_traces(name="Current Condition", selector=dict(name="S223VBTC@EMERGELA"))
fig.update_traces(name="Expectations Index", selector=dict(name="S223VBTE@EMERGELA"))
fig.show()fig = plot_lines(
[ts.ts for ts in fgv_surveys_collection[4:6]],
title="Brazil: Business Manufacturing Index",
)
fig.update_traces(name="Confidence Index", selector=dict(name="S223VM@EMERGELA"))
fig.update_traces(name="Current Condition", selector=dict(name="S223VMC@EMERGELA"))
fig.update_traces(name="Expectations Index", selector=dict(name="S223VME@EMERGELA"))
fig.show()Other Surveys
surveys = {
"Consumer Con`fidence Index": "H223VCC@EMERGE ",
"Business Confidence Index": "N223VB@EMERGE",
"Business Prospects Index": "N223VBE@EMERGE ",
}
surveys_collection = []
for k, v in surveys.items():
surveys_collection.append(hc.get_series(v))
surveys_collection = TulipCollection(surveys_collection)
surveys_collection.dashboard.table()
surveys_collection.dashboard.plots(years_limit=3)Employment¶
# Employment metrics
employment = {
"Unemployment Rate": f"H{haver_code}ELUR@EMERGELA ",
"Workfoce Participation": f"H{haver_code}ELPR@EMERGELA ",
"Net Job Creation": f"H{haver_code}E5@EMERGELA ",
}
employment_collection = []
for k, v in employment.items():
employment_collection.append(hc.get_series(v))
employment_collection = TulipCollection(employment_collection)
# todo: fix direction
employment_collection.dashboard.table()
employment_collection.dashboard.plots()Output Gap¶
# Output gap metrics
output_gap = {
"Manufacturing Capacity Utilization": "S223DUM@EMERGELA",
"CNI Capacity Utilization": "S223UCC@EMERGELA",
}
output_gap_collection = []
for k, v in output_gap.items():
output_gap_collection.append(hc.get_series(v))
output_gap_collection = TulipCollection(output_gap_collection)
output_gap_collection.dashboard.table()
output_gap_collection.dashboard.plots()Prices¶
The Central Bank of Brazil (Banco Central do Brasil) targets the IPCA (Índice Nacional de Preços ao Consumidor Amplo), or Broad National Consumer Price Index, as its official inflation measure. This index is calculated by the Brazilian Institute of Geography and Statistics (IBGE) and serves as the primary benchmark for the country’s inflation-targeting regime. The inflation target is set in terms of the year-over-year rate of increase in the IPCA . The IPCA-15, on the other hand, is a mid-month preview of the IPCA. While it provides timely insights into inflation trends and is closely monitored by policymakers and analysts, it is not the official target for monetary policy. The IPCA-15 differs from the IPCA primarily in its data collection period and geographic coverage, offering an early indication of inflation but not serving as the formal benchmark . valorinternational
prices = {
"IPCA-15": "yryr%(N2231P@EMERGELA)",
"CPI YoY": f"yryr%(S{haver_code}IP@EMERGELA)",
"Wages YoY": f"yryr%(N{haver_code}EM@EMERGELA)",
"Commodity Prices": f"yryr%(N{haver_code}PZRB@EMERGELA)",
"Inflation Expectations 1Y": "N223VCVI@EMERGELA",
"Inflation Expectations 1Y FOCUS": "I223ICA@EMERGELA",
"Target Inflation": "A223VUCP@EMERGELA",
}
prices_collection = []
for k, v in prices.items():
prices_collection.append(hc.get_series(v))
prices_collection = TulipCollection(prices_collection)
prices_collection.dashboard.table()fig = plot_lines(
[ts.ts for ts in prices_collection],
title="",
years_limit=5,
tick_suffix="%",
default_y_range=(-5, 18),
figsize=(800, 600),
)
fig.update_traces(
name="CPI Core YoY (IPCA-15)",
line_width=4,
selector=dict(name="yryr%(N2231P@EMERGELA)"),
)
fig.update_traces(
name="CPI YoY (IPCA)",
line_width=4,
selector=dict(name=f"yryr%(S{haver_code}IP@EMERGELA)"),
)
fig.update_traces(
name="Wages YoY", selector=dict(name=f"yryr%(N{haver_code}EM@EMERGELA)")
)
fig.update_traces(
name="Commodity Prices",
selector=dict(name=f"yryr%(N{haver_code}PZRB@EMERGELA)"),
visible="legendonly",
)
fig.update_traces(name="Expectations", selector=dict(name="N223VCVI@EMERGELA"))
fig.update_traces(
name="Expectations (Focus survey)", selector=dict(name="I223ICA@EMERGELA")
)
fig.update_traces(
name="Upper Inflation Target", selector=dict(name="A223VUCP@EMERGELA")
)
fig.show()Double click on Focus survey¶
The Central Bank of Brazil conducts the weekly Focus Survey, aggregating forecasts from over 100 financial institutions. This survey provides median projections for key economic indicators, including the IPCA inflation rate. Within this framework, the “Top 5” ranking highlights institutions with the most accurate short-, medium-, and long-term forecasts, offering a benchmark for forecasting performance
focus_survey = {
"Key1": "I223ICA@EMERGELA",
"Key2": "I223TCA@EMERGELA",
"Key4": "C223TCA@EMERGELA",
"Key6": "M223TCA@EMERGELA",
"Key7": "L223TCA@EMERGELA",
}
focus_survey_collection = []
for k, v in focus_survey.items():
focus_survey_collection.append(hc.get_series(v))
focus_survey_collection = TulipCollection(focus_survey_collection)
focus_survey_collection.dashboard.table()plot_lines(focus_survey_collection.ts, years_limit=1)
fig = plot_lines(focus_survey_collection.ts, years_limit=1, logo=False, tick_suffix="%")
fig.update_traces(name="IPCA next year", selector=dict(name="I223ICA@EMERGELA"))
fig.update_traces(
name="IPCA next year, forecasts in the last 5 working days",
selector=dict(name="I223TCA@EMERGELA"),
)
fig.update_traces(
name="Top 5 Short term forecasts", selector=dict(name="C223TCA@EMERGELA")
)
fig.update_traces(
name="Top 5 medium term forcasts", selector=dict(name="M223TCA@EMERGELA")
)
fig.update_traces(
name="Top 5 long term forecasts", selector=dict(name="L223TCA@EMERGELA")
)
fig.show()
Breakeven expectations¶
breakeven_collection = [
bb.get_series(f"BRGGBE{i} Index") for i in ["01", "02", "05", "10"]
]
breakeven_collection = TulipCollection(breakeven_collection)
breakeven_collection.dashboard.table()bei = breakeven_collection.ts
bei.columns = ["1Y Breakeven", "2Y Breakeven", "5Y Breakeven", "10Y Breakeven"]
bei["IPCA-15"] = prices_collection[0].ts.resample("B").ffill()
bei["IPCA"] = prices_collection[1].ts.resample("B").ffill()
fig = plot_lines(
bei,
title="Brazil Breakeven Inflation vs Realized Inflation",
years_limit=5,
tick_suffix="%",
default_y_range=(-5, 18),
figsize=(800, 400),
logo=False,
)
fig.update_traces(
name="1Y Breakeven", selector=dict(name="1Y Breakeven"), visible="legendonly"
)
fig.update_traces(
name="2Y Breakeven", selector=dict(name="2Y Breakeven"), visible="legendonly"
)
fig.update_traces(name="5Y Breakeven", selector=dict(name="5Y Breakeven"))
fig.update_traces(
name="10Y Breakeven", selector=dict(name="10Y Breakeven"), visible="legendonly"
)
fig.update_traces(name="IPCA-15", selector=dict(name="IPCA-15"), line=dict(dash="dot"))
fig.update_traces(name="IPCA", selector=dict(name="IPCA"), line=dict(dash="dot"))
fig.show()
Credit Creation¶
ngdp = hc.get_series("H223MGDP@EMERGELA").ts.rolling(12).sum()### Credit Creation
credit = {
"Credit to Non-Financial Sector": f"N{haver_code}FCCT@EMERGELA",
"Loans": f"N{haver_code}FC@EMERGELA",
"Loans by National Financial System": f"N{haver_code}FCT@EMERGELA",
"Loans by Other Financial Corporations": f"N{haver_code}FCO@EMERGELA",
"Loans by Government Funds": f"N{haver_code}FCV@EMERGELA",
"Debt Securities": f"N{haver_code}FCD@EMERGELA",
"Government Debt Securities": f"N{haver_code}FCVD@EMERGELA",
"Corporate Debt Securities": f"N{haver_code}FCFD@EMERGELA",
"Securitization": f"N{haver_code}FCSD@EMERGELA",
"External Debt": f"N{haver_code}FCX@EMERGELA",
"External Loans": f"N{haver_code}FCXL@EMERGELA",
"External Market Debt Securities": f"N{haver_code}FCXE@EMERGELA",
"Domestic Market External Debt Securities": f"N{haver_code}FCXD@EMERGELA",
}
credit_collection = []
for k, v in credit.items():
credit_collection.append(hc.get_series(v))
credit_collection = TulipCollection(credit_collection)
credit_collection.dashboard.table()plot_line(
credit_collection[0].ts.diff(6).mul(2).div(ngdp, axis=0),
years_limit=10,
tick_format="0.0%",
title="<b>Credit Creation to the Non-financial Sector</b> (%NGDP, 6m chg ann.)",
)# Loans from banks, Loans from Other Financial Institutions, Loans from Covernment
loans_to_the_private_sector = hc.create_collection(
["N223FCT@EMERGELA", "N223FCO@EMERGELA", "N223FCV@EMERGELA", "N223FCFD@EMERGELA"]
)
loans_df = loans_to_the_private_sector.df
loans_df.columns = ["Bank Loans", "Other Loans", "Govt Loans", "Bond Issuance"]
private_credit_growth = loans_df.diff(6).mul(2).div(ngdp, axis=0)
plot_lines(
private_credit_growth,
years_limit=10,
tick_format="0.0%",
title="<b>Credit Creation to the Private Sector</b> (%NGDP, 6m chg ann.)",
)Budget¶
government_finance = {
"Public Debt": f"N{haver_code}FDP@EMERGELA", # Canada: Business Barometer Index: 3 Month Outlook
"Govt Budget Surplus/Deficit": f"N{haver_code}FGBP@EMERGELA", # Business Barometer Index: Canada
}
government_finance_collection = []
for k, v in government_finance.items():
government_finance_collection.append(hc.get_series(v))
government_finance_collection = TulipCollection(government_finance_collection)
government_finance_collection.dashboard.table()government_finance_collection.dashboard.plots(show_0=True)from tulip_mania.notebook_related import notebook_updated
notebook_updated()