Tesouro Data
auction(auction_date)
Fetches and processes Brazilian Treasury auction data for a given date.
This function queries the Tesouro Nacional API to retrieve auction results for a specific date. It then processes the JSON response using the Polars library to create a well-structured and typed DataFrame.
Exemplo de resposta da API de leilões do Tesouro: https://apiapex.tesouro.gov.br/aria/v1/api-leiloes-pub/custom/resultados?dataleilao=30/09/2025
{
"registros": [
{...},
{
"quantidade_bcb": 0,
"liquidacao_segunda_volta": "2025-10-01T00:00:00.000Z",
"oferta_segunda_volta": 37499,
"data_leilao": "30/09/2025",
"oferta": 150000,
"titulo": "LFT",
"liquidacao": "01/10/2025",
"financeiro_aceito_segunda_volta": 0,
"quantidade_aceita": 150000,
"prazo": 1067,
"vencimento": "01/09/2028",
"benchmark": "LFT 3 anos",
"pu_medio": 17434.81182753125,
"taxa_media": 0.0669,
"financeiro_aceito": 2615194916.22,
"pu_minimo": 17434.632775,
"numero_edital": 230,
"taxa_maxima": 0.0669,
"tipo_leilao": "Venda",
"financeiro_bcb": 0,
"quantidade_aceita_segunda_volta": 0
},
{...},
],
"status": "ok"
}
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auction_date
|
DateScalar
|
The date of the auction in the format accepted by PYield DateScalar (e.g., "DD-MM-YYYY", datetime.date, etc.). |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Um DataFrame do Polars contendo os dados processados do leilão. As colunas são: |
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
Retorna um DataFrame do Pandas vazio se ocorrer um erro na requisição, no processamento, ou se não houver dados para a data especificada.
Source code in pyield/tn/auctions.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
benchmarks(bond_type=None, include_history=False)
Fetches benchmark data for Brazilian Treasury Bonds from the TN API.
This function retrieves current or historical benchmark data for various Brazilian Treasury bond types (e.g., LTN, LFT, NTN-B). The data is sourced directly from the official Tesouro Nacional API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_history
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: A Polars DataFrame containing the benchmark data.
The DataFrame includes the following columns:
* |
Notes
- Data is sourced from the official Tesouro Nacional (Brazilian Treasury) API.
- An retry mechanism is implemented for SSL certificate verification errors.
- The API documentation can be found at: https://portal-conhecimento.tesouro.gov.br/catalogo-componentes/api-leil%C3%B5es
- Rows with any
NaNvalues are dropped before returning the DataFrame.
Examples:
>>> from pyield import tn
>>> df_current = tn.benchmarks()
>>> # Get historical benchmarks
>>> tn.benchmarks(bond_type="LFT", include_history=True).head()
shape: (5, 5)
┌──────────┬──────────────┬────────────┬────────────┬────────────┐
│ BondType ┆ MaturityDate ┆ Benchmark ┆ StartDate ┆ EndDate │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ date ┆ str ┆ date ┆ date │
╞══════════╪══════════════╪════════════╪════════════╪════════════╡
│ LFT ┆ 2020-03-01 ┆ LFT 6 anos ┆ 2014-01-01 ┆ 2014-06-30 │
│ LFT ┆ 2020-09-01 ┆ LFT 6 anos ┆ 2014-07-01 ┆ 2014-12-31 │
│ LFT ┆ 2021-03-01 ┆ LFT 6 anos ┆ 2015-01-01 ┆ 2015-04-30 │
│ LFT ┆ 2021-09-01 ┆ LFT 6 anos ┆ 2015-05-01 ┆ 2015-12-31 │
│ LFT ┆ 2022-03-01 ┆ LFT 6 anos ┆ 2016-01-01 ┆ 2016-06-30 │
└──────────┴──────────────┴────────────┴────────────┴────────────┘
Source code in pyield/tn/benchmark.py
di_spreads(date, bps=False)
Calcula o DI Spread para títulos prefixados (LTN e NTN-F) em uma data de referência.
spread = taxa indicativa do PRE - taxa de ajuste do DI
Quando bps=False a coluna retorna essa diferença em formato decimal
(ex: 0.000439 ≈ 4.39 bps). Quando bps=True o valor é automaticamente
multiplicado por 10_000 e exibido diretamente em basis points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date
|
DateScalar
|
Data de referência para buscar as taxas. |
required |
bps
|
bool
|
Se True, retorna DISpread já convertido em basis points. Default False. |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame com colunas: - BondType - MaturityDate - DISpread (decimal ou bps conforme parâmetro) |
Examples:
>>> from pyield import pre
>>> pre.di_spreads("30-05-2025", bps=True)
shape: (18, 3)
┌──────────┬──────────────┬──────────┐
│ BondType ┆ MaturityDate ┆ DISpread │
│ --- ┆ --- ┆ --- │
│ str ┆ date ┆ f64 │
╞══════════╪══════════════╪══════════╡
│ LTN ┆ 2025-07-01 ┆ 4.39 │
│ LTN ┆ 2025-10-01 ┆ -9.0 │
│ LTN ┆ 2026-01-01 ┆ -4.88 │
│ LTN ┆ 2026-04-01 ┆ -4.45 │
│ LTN ┆ 2026-07-01 ┆ 0.81 │
│ … ┆ … ┆ … │
│ NTN-F ┆ 2027-01-01 ┆ -3.31 │
│ NTN-F ┆ 2029-01-01 ┆ 14.21 │
│ NTN-F ┆ 2031-01-01 ┆ 21.61 │
│ NTN-F ┆ 2033-01-01 ┆ 11.51 │
│ NTN-F ┆ 2035-01-01 ┆ 22.0 │
└──────────┴──────────────┴──────────┘