SGS

A função bcb.sgs.get() obtem os dados do webservice do Banco Central , interface json do serviço BCData/SGS - Sistema Gerenciador de Séries Temporais (SGS).

Exemplos

In [1]: from bcb import sgs

In [2]: import matplotlib.pyplot as plt

In [3]: import matplotlib as mpl

In [4]: mpl.style.use('bmh')

In [5]: df = sgs.get({'IPCA': 433}, start='2002-02-01')

In [6]: df.index = df.index.to_period('M')

In [7]: df.head()
Out[7]: 
         IPCA
Date         
2002-02  0.36
2002-03  0.60
2002-04  0.80
2002-05  0.21
2002-06  0.42
In [8]: dfr = df.rolling(12)

In [9]: i12 = dfr.apply(lambda x: (1 + x/100).prod() - 1).dropna() * 100

In [10]: i12.head()
Out[10]: 
              IPCA
Date              
2003-01  14.467041
2003-02  15.847124
2003-03  16.572608
2003-04  16.769209
2003-05  17.235307
In [11]: i12.plot(figsize=(12,6))
Out[11]: <Axes: xlabel='Date'>

In [12]: plt.title('Fonte: https://dadosabertos.bcb.gov.br', fontsize=10)
Out[12]: Text(0.5, 1.0, 'Fonte: https://dadosabertos.bcb.gov.br')

In [13]: plt.suptitle('IPCA acumulado 12 meses - Janela Móvel', fontsize=18)
Out[13]: Text(0.5, 0.98, 'IPCA acumulado 12 meses - Janela Móvel')

In [14]: plt.xlabel('Data')
Out[14]: Text(0.5, 0, 'Data')

In [15]: plt.ylabel('%')
Out[15]: Text(0, 0.5, '%')

In [16]: plt.legend().set_visible(False)
_images/sgs1.png

Dados de Inadimplência de Operações de Crédito

In [17]: from bcb.sgs.regional_economy import get_non_performing_loans

In [18]: from bcb.utils import BRAZILIAN_REGIONS, BRAZILIAN_STATES

In [19]: import pandas as pd

In [20]: get_non_performing_loans(["RR"], last=10, mode="all")
Out[20]: 
              RR
Date            
2024-01-01  3.87
2024-02-01  3.88
2024-03-01  3.96
2024-04-01  3.94
2024-05-01  4.22
2024-06-01  4.15
2024-07-01  4.07
2024-08-01  3.77
2024-09-01  3.85
2024-10-01  3.85
In [21]: northeast_states = BRAZILIAN_REGIONS["NE"]

In [22]: get_non_performing_loans(northeast_states, last=5, mode="pj")
Out[22]: 
              AL    BA    CE    MA    PB    PE    PI    RN    SE
Date                                                            
2024-06-01  2.69  3.45  2.58  4.00  3.47  3.44  1.97  3.56  3.49
2024-07-01  2.68  3.03  2.72  4.18  3.35  3.40  2.09  3.50  3.42
2024-08-01  2.77  3.06  2.70  4.35  3.40  3.18  2.18  3.50  3.45
2024-09-01  2.69  3.13  2.67  4.41  3.48  3.14  2.26  3.44  3.55
2024-10-01  2.60  3.09  2.77  4.59  3.56  3.02  2.33  3.64  3.61
In [23]: get_non_performing_loans(BRAZILIAN_STATES, mode="PF", start="2024-01-01")
Out[23]: 
              AC    AP    AM    PA    RO  ...    RJ    SP    PR    RS    SC
Date                                      ...                              
2024-01-01  3.49  4.09  5.40  4.16  2.76  ...  5.33  3.45  2.76  2.48  2.85
2024-02-01  3.48  4.05  5.25  4.15  2.78  ...  5.25  3.43  2.75  2.51  2.84
2024-03-01  3.43  4.01  5.18  4.09  2.81  ...  5.17  3.36  2.74  2.53  2.81
2024-04-01  3.46  4.10  5.15  4.09  2.85  ...  5.13  3.41  2.75  2.53  2.81
2024-05-01  3.54  4.22  5.26  4.15  2.99  ...  5.14  3.46  2.83  2.60  2.87
2024-06-01  3.50  4.11  5.14  4.09  3.07  ...  5.04  3.40  2.76  2.61  2.79
2024-07-01  3.49  4.13  5.14  4.14  3.16  ...  5.02  3.43  2.87  2.61  2.82
2024-08-01  3.44  4.04  5.06  4.14  3.24  ...  4.98  3.42  3.02  2.58  2.81
2024-09-01  3.58  4.06  4.99  4.16  3.24  ...  4.89  3.39  3.00  2.54  2.78
2024-10-01  3.59  3.98  4.87  4.22  3.26  ...  4.84  3.35  2.97  2.48  2.74

[10 rows x 27 columns]