Skip to content

Instantly share code, notes, and snippets.

@Fabiocke
Created August 25, 2022 02:14
Show Gist options
  • Select an option

  • Save Fabiocke/1acc16179c42c3dc5ca25d0488698d45 to your computer and use it in GitHub Desktop.

Select an option

Save Fabiocke/1acc16179c42c3dc5ca25d0488698d45 to your computer and use it in GitHub Desktop.
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