import%20marimo%0A%0A__generated_with%20%3D%20%220.15.2%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%20Brazil%20Core%20Inflation%20Analysis%0A%0A%20%20%20%20This%20notebook%20analyzes%20Brazil's%20core%20inflation%20measures%20using%20data%20from%20the%20Central%20Bank%20of%20Brazil%20(BCB)%20and%20IBGE.%0A%0A%20%20%20%20**Macroeconomic%20Context%3A**%0A%20%20%20%20Core%20inflation%20measures%20are%20essential%20tools%20for%20monetary%20policy%20as%20they%20exclude%20volatile%20components%20like%20food%20and%20energy%20prices%2C%20providing%20a%20clearer%20view%20of%20underlying%20inflationary%20pressures.%20Brazil%20uses%20multiple%20core%20inflation%20indicators%20to%20assess%20price%20stability%20and%20guide%20interest%20rate%20decisions.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%200.%20Import%20Libraries%0A%0A%20%20%20%20We'll%20use%3A%0A%0A%20%20%20%20-%20**bcb**%3A%20To%20access%20Brazilian%20Central%20Bank%20time%20series%20data%0A%20%20%20%20-%20**pandas%2Fnumpy**%3A%20For%20data%20manipulation%20and%20analysis%0A%20%20%20%20-%20**matplotlib%2Fseaborn**%3A%20For%20data%20visualization%0A%20%20%20%20-%20**statsmodels**%3A%20For%20time%20series%20decomposition%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20%23%20Import%20required%20libraries%0A%20%20%20%20from%20bcb%20import%20sgs%20%20%23%20Brazilian%20Central%20Bank%20API%0A%20%20%20%20import%20pandas%20as%20pd%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20import%20seaborn%20as%20sns%0A%20%20%20%20import%20statsmodels.api%20as%20sm%0A%20%20%20%20from%20typing%20import%20TYPE_CHECKING%0A%0A%20%20%20%20if%20TYPE_CHECKING%3A%0A%20%20%20%20%20%20%20%20from%20pandas%20import%20Series%0A%0A%20%20%20%20%23%20Define%20color%20palette%20for%20consistent%20visualization%0A%20%20%20%20colors%20%3D%20%7B%0A%20%20%20%20%20%20%20%20'blue'%3A%20'%23282f6b'%2C%20%0A%20%20%20%20%20%20%20%20'red'%3A%20'%23b22200'%2C%0A%20%20%20%20%20%20%20%20'green'%3A%20'%23224f20'%2C%0A%20%20%20%20%20%20%20%20'purple'%3A%20'%235f487c'%2C%0A%20%20%20%20%20%20%20%20'gray'%3A%20'%23666666'%2C%0A%20%20%20%20%20%20%20%20'orange'%3A%20'%23b35c1e'%0A%20%20%20%20%7D%0A%20%20%20%20return%20colors%2C%20np%2C%20pd%2C%20plt%2C%20sgs%2C%20sm%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%201.%20Extract%20Data%0A%0A%20%20%20%20**Core%20Inflation%20Measures%20in%20Brazil%3A**%0A%0A%20%20%20%20Brazil's%20Central%20Bank%20tracks%20several%20core%20inflation%20indicators%3A%0A%0A%20%20%20%20-%20**EX0**%3A%20IPCA%20excluding%20food%20at%20home%20and%20monitored%20prices%0A%20%20%20%20-%20**EX3**%3A%20IPCA%20excluding%20food%20and%20energy%0A%20%20%20%20-%20**DP**%3A%20Double-weighted%20IPCA%20(Dupla%20Pondera%C3%A7%C3%A3o)%0A%20%20%20%20-%20**MS**%3A%20Trimmed%20mean%20IPCA%20(M%C3%A9dia%20Aparada)%0A%20%20%20%20-%20**P55**%3A%2055%25%20trimmed%20mean%20IPCA%0A%20%20%20%20-%20**IPCA**%3A%20Full%20Consumer%20Price%20Index%20for%20comparison%0A%0A%20%20%20%20These%20measures%20help%20identify%20persistent%20inflation%20trends%20by%20removing%20temporary%20price%20shocks.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(sgs)%3A%0A%20%20%20%20%23%20Fetch%20core%20inflation%20time%20series%20from%20BCB%20using%20SGS%20codes%0A%20%20%20%20core_inflation_df%20%3D%20sgs.get(%7B%0A%20%20%20%20%20%20%20%20'ex0'%3A%2011427%2C%20%20%20%20%23%20IPCA%20excluding%20food%20at%20home%20and%20monitored%20prices%0A%20%20%20%20%20%20%20%20'ex3'%3A%2027839%2C%20%20%20%20%23%20IPCA%20excluding%20food%20and%20energy%0A%20%20%20%20%20%20%20%20'dp'%3A%2016122%2C%20%20%20%20%20%23%20Double-weighted%20IPCA%0A%20%20%20%20%20%20%20%20'ms'%3A%204466%2C%20%20%20%20%20%20%23%20Trimmed%20mean%20IPCA%0A%20%20%20%20%20%20%20%20'p55'%3A%2028750%2C%20%20%20%20%23%2055%25%20trimmed%20mean%20IPCA%0A%20%20%20%20%20%20%20%20'ipca'%3A%20433%20%20%20%20%20%20%23%20Full%20IPCA%20for%20comparison%0A%20%20%20%20%7D%2C%20start%3D'2002-01-01')%0A%0A%20%20%20%20core_inflation_df%0A%20%20%20%20return%20(core_inflation_df%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%202.%20Transform%20Data%0A%0A%20%20%20%20**Creating%20a%20Composite%20Core%20Inflation%20Measure%3A**%0A%0A%20%20%20%20We%20calculate%20the%20average%20of%20all%20core%20inflation%20measures%20to%20create%20a%20single%2C%20robust%20indicator.%20This%20approach%3A%0A%0A%20%20%20%20-%20Reduces%20noise%20from%20individual%20measures%0A%20%20%20%20-%20Provides%20a%20more%20stable%20signal%20of%20underlying%20inflation%0A%20%20%20%20-%20Helps%20identify%20seasonal%20patterns%20in%20price%20behavior%0A%0A%20%20%20%20We%20also%20analyze%20monthly%20seasonality%20to%20understand%20when%20inflation%20typically%20peaks%20or%20troughs%20during%20the%20year.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(core_inflation_df%2C%20pd)%3A%0A%20%20%20%20%23%20Create%20working%20copy%20and%20calculate%20composite%20core%20inflation%20measure%0A%20%20%20%20core_data%20%3D%20core_inflation_df.copy()%0A%0A%20%20%20%20%23%20Calculate%20mean%20of%20all%20core%20measures%20(excluding%20headline%20IPCA)%0A%20%20%20%20core_data%5B'mean_core_inflation'%5D%20%3D%20core_data.drop('ipca'%2C%20axis%3D1).mean(axis%3D1)%0A%0A%20%20%20%20%23%20Extract%20month%20names%20for%20seasonality%20analysis%0A%20%20%20%20core_data%5B'month'%5D%20%3D%20core_data.index.month_name()%0A%0A%20%20%20%20%23%20Calculate%20monthly%20statistics%20for%20seasonality%20analysis%0A%20%20%20%20monthly_mean%20%3D%20core_data.groupby('month')%5B'mean_core_inflation'%5D.mean()%0A%20%20%20%20monthly_p20%20%3D%20core_data.groupby('month')%5B'mean_core_inflation'%5D.quantile(0.2)%0A%20%20%20%20monthly_p80%20%3D%20core_data.groupby('month')%5B'mean_core_inflation'%5D.quantile(0.8)%0A%0A%20%20%20%20%23%20Combine%20monthly%20statistics%20into%20results%20dataframe%0A%20%20%20%20monthly_results%20%3D%20pd.DataFrame(%7B%0A%20%20%20%20%20%20%20%20'month'%3A%20monthly_mean.index%2C%0A%20%20%20%20%20%20%20%20'monthly_mean'%3A%20monthly_mean.values%2C%0A%20%20%20%20%20%20%20%20'percentile_20'%3A%20monthly_p20.values%2C%0A%20%20%20%20%20%20%20%20'percentile_80'%3A%20monthly_p80.values%0A%20%20%20%20%7D)%0A%0A%20%20%20%20monthly_results%0A%20%20%20%20return%20core_data%2C%20monthly_results%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%203.%20Current%20Year%20Analysis%0A%0A%20%20%20%20**Recent%20Performance%20Context%3A**%0A%0A%20%20%20%20Analyzing%20the%20current%20year's%20inflation%20data%20helps%20assess%3A%0A%0A%20%20%20%20-%20How%20current%20inflation%20compares%20to%20historical%20seasonal%20patterns%0A%20%20%20%20-%20Whether%20recent%20price%20pressures%20are%20within%20normal%20ranges%0A%20%20%20%20-%20If%20monetary%20policy%20adjustments%20may%20be%20needed%0A%0A%20%20%20%20This%20comparison%20is%20crucial%20for%20central%20bank%20communication%20and%20market%20expectations.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(core_data)%3A%0A%20%20%20%20%23%20Extract%20current%20year%20data%20for%20comparison%20with%20historical%20patterns%0A%20%20%20%20current_year_data%20%3D%20(%0A%20%20%20%20%20%20%20%20core_data%0A%20%20%20%20%20%20%20%20.query('index%20%3E%3D%20%222025-01-01%22')%0A%20%20%20%20%20%20%20%20.reset_index()%0A%20%20%20%20%20%20%20%20%5B%5B'month'%2C%20'mean_core_inflation'%2C%20'ipca'%5D%5D%0A%20%20%20%20)%0A%20%20%20%20return%20(current_year_data%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(current_year_data%2C%20monthly_results%2C%20pd)%3A%0A%20%20%20%20%23%20Merge%20historical%20monthly%20patterns%20with%20current%20year%20data%0A%20%20%20%20combined_monthly_data%20%3D%20pd.merge(%0A%20%20%20%20%20%20%20%20left%3Dmonthly_results%2C%20%0A%20%20%20%20%20%20%20%20right%3Dcurrent_year_data%2C%20%0A%20%20%20%20%20%20%20%20how%3D'outer'%0A%20%20%20%20)%0A%20%20%20%20combined_monthly_data%0A%20%20%20%20return%20(combined_monthly_data%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(combined_monthly_data%2C%20pd)%3A%0A%20%20%20%20%23%20Sort%20months%20in%20chronological%20order%20and%20format%20for%20display%0A%20%20%20%20month_order%20%3D%20sorted(%0A%20%20%20%20%20%20%20%20combined_monthly_data%5B'month'%5D.unique()%2C%20%0A%20%20%20%20%20%20%20%20key%3Dlambda%20x%3A%20pd.to_datetime(x%2C%20format%3D'%25B')%0A%20%20%20%20)%0A%0A%20%20%20%20%23%20Create%20ordered%20categorical%20for%20proper%20sorting%0A%20%20%20%20combined_monthly_data%5B'month'%5D%20%3D%20pd.Categorical(%0A%20%20%20%20%20%20%20%20combined_monthly_data%5B'month'%5D%2C%20%0A%20%20%20%20%20%20%20%20categories%3Dmonth_order%2C%20%0A%20%20%20%20%20%20%20%20ordered%3DTrue%0A%20%20%20%20)%0A%20%20%20%20combined_monthly_data.sort_values(by%3D'month'%2C%20inplace%3DTrue)%0A%0A%20%20%20%20%23%20Create%20abbreviated%20month%20names%20for%20charts%0A%20%20%20%20combined_monthly_data%5B'month_abbrev'%5D%20%3D%20combined_monthly_data%5B'month'%5D.str.slice(stop%3D3)%0A%0A%20%20%20%20combined_monthly_data%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(np)%3A%0A%20%20%20%20def%20calculate_cumulative_inflation(data%2C%20window%3A%20int)%3A%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20Calculate%20cumulative%20inflation%20over%20rolling%20windows.%0A%0A%20%20%20%20%20%20%20%20This%20function%20compounds%20monthly%20inflation%20rates%20to%20show%20accumulated%20%0A%20%20%20%20%20%20%20%20inflation%20over%20specified%20periods%2C%20which%20is%20essential%20for%3A%0A%20%20%20%20%20%20%20%20-%20Annual%20inflation%20targeting%20(12-month%20windows)%0A%20%20%20%20%20%20%20%20-%20Policy%20assessment%20(shorter-term%20trends)%0A%0A%20%20%20%20%20%20%20%20Args%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20data%3A%20Series%20of%20monthly%20inflation%20rates%20as%20percentages%0A%20%20%20%20%20%20%20%20%20%20%20%20window%3A%20Number%20of%20periods%20to%20accumulate%20over%0A%0A%20%20%20%20%20%20%20%20Returns%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20Series%20with%20cumulative%20inflation%20rates%20as%20percentages%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20return%20(((data%20%2F%20100)%20%2B%201)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.rolling(window%3Dwindow)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.apply(np.prod)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20-%201)%20*%20100%0A%20%20%20%20return%20(calculate_cumulative_inflation%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(core_data%2C%20sm)%3A%0A%20%20%20%20%23%20Perform%20seasonal%20decomposition%20to%20isolate%20trend%20from%20seasonal%20effects%0A%20%20%20%20decomposition%20%3D%20sm.tsa.seasonal_decompose(%0A%20%20%20%20%20%20%20%20core_data.mean_core_inflation%2C%20%0A%20%20%20%20%20%20%20%20model%3D'additive'%0A%20%20%20%20)%0A%0A%20%20%20%20%23%20Create%20seasonally%20adjusted%20series%20by%20removing%20seasonal%20component%0A%20%20%20%20core_data%5B'core_inflation_sa'%5D%20%3D%20(%0A%20%20%20%20%20%20%20%20core_data.mean_core_inflation.values%20-%20decomposition.seasonal.values%0A%20%20%20%20)%0A%20%20%20%20return%20(decomposition%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(calculate_cumulative_inflation%2C%20core_data)%3A%0A%20%20%20%20%23%20Calculate%20key%20inflation%20metrics%20for%20policy%20analysis%0A%20%20%20%20inflation_metrics%20%3D%20(%0A%20%20%20%20%20%20%20%20core_data%0A%20%20%20%20%20%20%20%20.assign(%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%2012-month%20accumulated%20inflation%20(standard%20policy%20measure)%0A%20%20%20%20%20%20%20%20%20%20%20%20core_12m_cumulative%20%3D%20lambda%20x%3A%20calculate_cumulative_inflation(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20x.mean_core_inflation%2C%20window%3D12%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%203-month%20annualized%20moving%20average%20(shows%20recent%20momentum)%0A%20%20%20%20%20%20%20%20%20%20%20%20core_3m_annualized%20%3D%20lambda%20x%3A%20(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20x.core_inflation_sa.rolling(window%3D3).mean()%20*%2012%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20.reset_index()%0A%20%20%20%20%20%20%20%20.dropna()%20%20%23%20Remove%20NaN%20values%20as%20per%20project%20specification%0A%20%20%20%20)%0A%0A%20%20%20%20inflation_metrics%0A%20%20%20%20return%20(inflation_metrics%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%205.%20Visualization%20-%20Core%20Inflation%20Trends%0A%0A%20%20%20%20**Interpreting%20the%20Chart%3A**%0A%0A%20%20%20%20-%20**Blue%20line%20(12M%20Cumulative)**%3A%20Shows%20inflation%20over%20the%20past%2012%20months%0A%20%20%20%20-%20**Orange%20line%20(3M%20Annualized)**%3A%20Shows%20recent%20inflation%20momentum%0A%0A%20%20%20%20**Policy%20Implications%3A**%0A%0A%20%20%20%20-%20When%20lines%20converge%3A%20Inflation%20is%20stabilizing%0A%20%20%20%20-%20When%203M%20is%20above%2012M%3A%20Inflation%20is%20accelerating%0A%20%20%20%20-%20When%203M%20is%20below%2012M%3A%20Inflation%20is%20decelerating%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(colors%2C%20inflation_metrics%2C%20pd%2C%20plt)%3A%0A%20%20%20%20%23%20Transform%20data%20to%20long%20format%20for%20plotting%0A%20%20%20%20metrics_long%20%3D%20inflation_metrics%5B%5B%0A%20%20%20%20%20%20%20%20'Date'%2C%20'core_12m_cumulative'%2C%20'core_3m_annualized'%0A%20%20%20%20%5D%5D.melt(id_vars%3D%5B'Date'%5D)%0A%0A%20%20%20%20%23%20Create%20the%20main%20inflation%20trends%20chart%0A%20%20%20%20fig%2C%20ax%20%3D%20plt.subplots(figsize%3D(12%2C%206))%0A%0A%20%20%20%20%23%20Plot%20each%20metric%20with%20appropriate%20styling%0A%20%20%20%20for%20variable%2C%20group_data%20in%20metrics_long.groupby('variable')%3A%0A%20%20%20%20%20%20%20%20if%20variable%20%3D%3D%20'core_12m_cumulative'%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20color%20%3D%20colors%5B'blue'%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20label%20%3D%20'12M%20Cumulative'%0A%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20color%20%3D%20colors%5B'orange'%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20label%20%3D%20'3M%20Annualized'%0A%0A%20%20%20%20%20%20%20%20plt.plot(%0A%20%20%20%20%20%20%20%20%20%20%20%20group_data%5B'Date'%5D%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20group_data%5B'value'%5D%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20label%3Dlabel%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20linewidth%3D2%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20color%3Dcolor%0A%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20%23%20Format%20x-axis%20with%202-year%20intervals%0A%20%20%20%20date_ticks%20%3D%20pd.date_range(%0A%20%20%20%20%20%20%20%20start%3Dmetrics_long%5B'Date'%5D.min()%2C%20%0A%20%20%20%20%20%20%20%20end%3Dmetrics_long%5B'Date'%5D.max()%2C%20%0A%20%20%20%20%20%20%20%20freq%3D'2YS'%0A%20%20%20%20)%0A%20%20%20%20plt.xticks(%0A%20%20%20%20%20%20%20%20ticks%3Ddate_ticks%2C%0A%20%20%20%20%20%20%20%20labels%3Ddate_ticks.strftime('%25b%2F%25y')%2C%0A%20%20%20%20%20%20%20%20rotation%3D45%0A%20%20%20%20)%0A%0A%20%20%20%20%23%20Chart%20formatting%20and%20labels%0A%20%20%20%20plt.title(%22Brazil%20Core%20Inflation%20Average%22%2C%20fontsize%3D16%2C%20fontweight%3D'bold')%0A%20%20%20%20plt.suptitle(%2212-Month%20Cumulative%20and%203-Month%20Annualized%20(SAAR)%22%2C%20fontsize%3D12)%0A%20%20%20%20plt.xlabel(%22Year%22)%0A%20%20%20%20plt.ylabel(%22Inflation%20Rate%20(%25)%22)%0A%20%20%20%20plt.legend(loc%3D%22upper%20left%22)%0A%20%20%20%20plt.grid(True%2C%20alpha%3D0.3)%0A%20%20%20%20plt.tight_layout()%0A%0A%20%20%20%20%23%20Add%20source%20note%0A%20%20%20%20plt.figtext(%0A%20%20%20%20%20%20%20%200.99%2C%200.01%2C%20%0A%20%20%20%20%20%20%20%20%22Source%3A%20IBGE%20and%20BCB%20%7C%20Analysis%3A%20quantitative%20research%22%2C%20%0A%20%20%20%20%20%20%20%20horizontalalignment%3D'right'%2C%20%0A%20%20%20%20%20%20%20%20fontsize%3D10%2C%20%0A%20%20%20%20%20%20%20%20color%3D'gray'%0A%20%20%20%20)%0A%0A%20%20%20%20plt.show()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%206.%20Seasonal%20Analysis%0A%0A%20%20%20%20**Understanding%20Inflation%20Seasonality%3A**%0A%0A%20%20%20%20Seasonal%20patterns%20in%20inflation%20help%20policymakers%3A%0A%0A%20%20%20%20-%20Distinguish%20between%20seasonal%20effects%20and%20underlying%20trends%0A%20%20%20%20-%20Time%20policy%20announcements%20and%20interventions%0A%20%20%20%20-%20Set%20appropriate%20expectations%20for%20specific%20months%0A%0A%0A%20%20%20%20**Reading%20the%20Chart%3A**%0A%0A%20%20%20%20-%20**Gray%20band**%3A%20Historical%20range%20(20th-80th%20percentile)%0A%20%20%20%20-%20**Black%20line**%3A%20Long-term%20monthly%20averages%0A%20%20%20%20-%20**Colored%20lines**%3A%20Current%20year%20vs%20historical%20patterns%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(colors%2C%20combined_monthly_data%2C%20plt)%3A%0A%20%20%20%20%23%20Set%20up%20the%20seasonal%20analysis%20chart%0A%20%20%20%20plt.figure(figsize%3D(12%2C%206))%0A%0A%20%20%20%20%23%20Create%20x-axis%20positions%20for%20months%0A%20%20%20%20x_positions%20%3D%20range(len(combined_monthly_data))%0A%0A%20%20%20%20%23%20Plot%20the%20uncertainty%20band%20(20th-80th%20percentile%20range)%0A%20%20%20%20plt.fill_between(%0A%20%20%20%20%20%20%20%20x_positions%2C%0A%20%20%20%20%20%20%20%20combined_monthly_data%5B'percentile_20'%5D%2C%20%0A%20%20%20%20%20%20%20%20combined_monthly_data%5B'percentile_80'%5D%2C%20%0A%20%20%20%20%20%20%20%20color%3D'lightgray'%2C%20%0A%20%20%20%20%20%20%20%20alpha%3D0.5%2C%20%0A%20%20%20%20%20%20%20%20label%3D'Historical%20Range%20(P20-P80)'%0A%20%20%20%20)%0A%0A%20%20%20%20%23%20Plot%20historical%20monthly%20averages%0A%20%20%20%20plt.plot(%0A%20%20%20%20%20%20%20%20x_positions%2C%0A%20%20%20%20%20%20%20%20combined_monthly_data%5B'monthly_mean'%5D%2C%20%0A%20%20%20%20%20%20%20%20color%3D'black'%2C%20%0A%20%20%20%20%20%20%20%20linewidth%3D2%2C%20%0A%20%20%20%20%20%20%20%20marker%3D'o'%2C%20%0A%20%20%20%20%20%20%20%20markersize%3D4%2C%0A%20%20%20%20%20%20%20%20label%3D'Historical%20Average'%0A%20%20%20%20)%0A%0A%20%20%20%20%23%20Plot%20current%20year%20core%20inflation%20if%20available%0A%20%20%20%20if%20'mean_core_inflation'%20in%20combined_monthly_data.columns%3A%0A%20%20%20%20%20%20%20%20current_mask%20%3D%20combined_monthly_data%5B'mean_core_inflation'%5D.notna()%0A%20%20%20%20%20%20%20%20if%20current_mask.any()%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20current_positions%20%3D%20%5Bi%20for%20i%2C%20mask%20in%20enumerate(current_mask)%20if%20mask%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20plt.plot(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20current_positions%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20combined_monthly_data.loc%5Bcurrent_mask%2C%20'mean_core_inflation'%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20color%3Dcolors%5B'blue'%5D%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20linewidth%3D2.5%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20marker%3D's'%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20markersize%3D6%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20label%3D'2024%20Core%20Inflation'%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20%23%20Plot%20current%20year%20headline%20IPCA%20if%20available%0A%20%20%20%20if%20'ipca'%20in%20combined_monthly_data.columns%3A%0A%20%20%20%20%20%20%20%20ipca_mask%20%3D%20combined_monthly_data%5B'ipca'%5D.notna()%0A%20%20%20%20%20%20%20%20if%20ipca_mask.any()%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20ipca_positions%20%3D%20%5Bi%20for%20i%2C%20mask%20in%20enumerate(ipca_mask)%20if%20mask%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20plt.plot(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ipca_positions%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20combined_monthly_data.loc%5Bipca_mask%2C%20'ipca'%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20color%3Dcolors%5B'red'%5D%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20linewidth%3D2.5%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20marker%3D'%5E'%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20markersize%3D6%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20label%3D'2024%20Headline%20IPCA'%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20%23%20Chart%20formatting%0A%20%20%20%20plt.title(%0A%20%20%20%20%20%20%20%20'Monthly%20Core%20Inflation%20Seasonality%20Analysis%20(2002-2024)'%2C%20%0A%20%20%20%20%20%20%20%20fontsize%3D14%2C%20%0A%20%20%20%20%20%20%20%20fontweight%3D'bold'%0A%20%20%20%20)%0A%20%20%20%20plt.xlabel('Month'%2C%20fontsize%3D12)%0A%20%20%20%20plt.ylabel('Monthly%20Inflation%20Rate%20(%25)'%2C%20fontsize%3D12)%0A%0A%20%20%20%20%23%20Set%20month%20labels%20on%20x-axis%0A%20%20%20%20plt.xticks(%0A%20%20%20%20%20%20%20%20x_positions%2C%20%0A%20%20%20%20%20%20%20%20combined_monthly_data%5B'month_abbrev'%5D%2C%20%0A%20%20%20%20%20%20%20%20rotation%3D0%0A%20%20%20%20)%0A%0A%20%20%20%20%23%20Add%20grid%20and%20legend%0A%20%20%20%20plt.grid(True%2C%20alpha%3D0.3)%0A%20%20%20%20plt.legend(bbox_to_anchor%3D(1.05%2C%201)%2C%20loc%3D'upper%20left')%0A%0A%20%20%20%20%23%20Adjust%20layout%20to%20prevent%20legend%20cutoff%0A%20%20%20%20plt.tight_layout()%0A%0A%20%20%20%20plt.show()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%207.%20Seasonal%20Decomposition%20Analysis%0A%0A%20%20%20%20**Understanding%20the%20Components%3A**%0A%0A%20%20%20%20This%20analysis%20shows%20how%20core%20inflation%20can%20be%20decomposed%20into%3A%0A%20%20%20%20-%20**Original%20Series**%3A%20Raw%20core%20inflation%20data%0A%20%20%20%20-%20**Seasonally%20Adjusted**%3A%20Core%20inflation%20with%20seasonal%20effects%20removed%0A%20%20%20%20-%20**Seasonal%20Component**%3A%20The%20recurring%20seasonal%20pattern%0A%0A%20%20%20%20The%20seasonally%20adjusted%20series%20is%20crucial%20for%20policy%20analysis%20as%20it%20reveals%20the%20underlying%20inflation%20trend%20without%20seasonal%20noise.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(colors%2C%20core_data%2C%20decomposition%2C%20plt)%3A%0A%20%20%20%20%23%20Create%20a%20comprehensive%20decomposition%20chart%0A%20%20%20%20fig2%2C%20axes%20%3D%20plt.subplots(2%2C%202%2C%20figsize%3D(15%2C%2010))%0A%20%20%20%20fig2.suptitle('Core%20Inflation%20Time%20Series%20Decomposition'%2C%20fontsize%3D16%2C%20fontweight%3D'bold')%0A%0A%20%20%20%20%23%20Original%20series%0A%20%20%20%20axes%5B0%2C%200%5D.plot(core_data.index%2C%20core_data%5B'mean_core_inflation'%5D%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20color%3Dcolors%5B'blue'%5D%2C%20linewidth%3D1.5)%0A%20%20%20%20axes%5B0%2C%200%5D.set_title('Original%20Core%20Inflation%20Series')%0A%20%20%20%20axes%5B0%2C%200%5D.set_ylabel('Inflation%20Rate%20(%25)')%0A%20%20%20%20axes%5B0%2C%200%5D.grid(True%2C%20alpha%3D0.3)%0A%0A%20%20%20%20%23%20Trend%20component%0A%20%20%20%20axes%5B0%2C%201%5D.plot(core_data.index%2C%20decomposition.trend%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20color%3Dcolors%5B'green'%5D%2C%20linewidth%3D1.5)%0A%20%20%20%20axes%5B0%2C%201%5D.set_title('Trend%20Component')%0A%20%20%20%20axes%5B0%2C%201%5D.set_ylabel('Inflation%20Rate%20(%25)')%0A%20%20%20%20axes%5B0%2C%201%5D.grid(True%2C%20alpha%3D0.3)%0A%0A%20%20%20%20%23%20Seasonal%20component%0A%20%20%20%20axes%5B1%2C%200%5D.plot(core_data.index%2C%20decomposition.seasonal%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20color%3Dcolors%5B'orange'%5D%2C%20linewidth%3D1.5)%0A%20%20%20%20axes%5B1%2C%200%5D.set_title('Seasonal%20Component')%0A%20%20%20%20axes%5B1%2C%200%5D.set_ylabel('Seasonal%20Effect%20(%25)')%0A%20%20%20%20axes%5B1%2C%200%5D.set_xlabel('Date')%0A%20%20%20%20axes%5B1%2C%200%5D.grid(True%2C%20alpha%3D0.3)%0A%0A%20%20%20%20%23%20Seasonally%20adjusted%20series%0A%20%20%20%20axes%5B1%2C%201%5D.plot(core_data.index%2C%20core_data%5B'core_inflation_sa'%5D%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20color%3Dcolors%5B'purple'%5D%2C%20linewidth%3D1.5)%0A%20%20%20%20axes%5B1%2C%201%5D.set_title('Seasonally%20Adjusted%20Series')%0A%20%20%20%20axes%5B1%2C%201%5D.set_ylabel('Inflation%20Rate%20(%25)')%0A%20%20%20%20axes%5B1%2C%201%5D.set_xlabel('Date')%0A%20%20%20%20axes%5B1%2C%201%5D.grid(True%2C%20alpha%3D0.3)%0A%0A%20%20%20%20%23%20Format%20all%20x-axes%0A%20%20%20%20for%20_ax%20in%20axes.flat%3A%0A%20%20%20%20%20%20%20%20_ax.tick_params(axis%3D'x'%2C%20rotation%3D45)%0A%0A%20%20%20%20plt.tight_layout()%0A%20%20%20%20plt.show()%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
de7420c05e2edfe3d25275b5d7c2af2ed93b198920b4dba758e4e85f926a5d8f