Created
August 25, 2022 02:14
-
-
Save Fabiocke/1acc16179c42c3dc5ca25d0488698d45 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| import pandas as pd | |
| def selic(): | |
| # busca o histórico diário da selic | |
| r=requests.get('https://api.bcb.gov.br/dados/serie/bcdata.sgs.11/dados?formato=json').json() | |
| df = pd.DataFrame(r).set_index('data') | |
| df['valor'] = df['valor'].astype(float) | |
| # anualiza as taxas, considerando 252 dias úteis no ano | |
| df['valor'] = df['valor'].apply(lambda x: 1+x/100)**252-1 | |
| # obtem o valor atual | |
| selic=df['valor'].iloc[-1] | |
| return selic |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment