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).
Exemplo¶
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)