pyield 0.48.2__tar.gz → 0.48.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyield-0.48.2 → pyield-0.48.4}/PKG-INFO +20 -20
- {pyield-0.48.2 → pyield-0.48.4}/README.md +19 -19
- pyield-0.48.4/pyield/__about__.py +1 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/__init__.py +2 -2
- {pyield-0.48.2 → pyield-0.48.4}/pyield/_internal/converters.py +2 -2
- {pyield-0.48.2 → pyield-0.48.4}/pyield/anbima/tpf.py +3 -3
- {pyield-0.48.2 → pyield-0.48.4}/pyield/b3/_validar_pregao.py +2 -2
- {pyield-0.48.2 → pyield-0.48.4}/pyield/b3/di1.py +3 -3
- {pyield-0.48.2 → pyield-0.48.4}/pyield/b3/futuro/contratos.py +2 -2
- {pyield-0.48.2 → pyield-0.48.4}/pyield/b3/futuro/historico.py +2 -2
- {pyield-0.48.2 → pyield-0.48.4}/pyield/b3/futuro/intradia.py +3 -3
- {pyield-0.48.2 → pyield-0.48.4}/pyield/bc/compromissada.py +21 -21
- {pyield-0.48.2 → pyield-0.48.4}/pyield/bc/copom.py +4 -4
- {pyield-0.48.2 → pyield-0.48.4}/pyield/bc/leiloes.py +21 -21
- {pyield-0.48.2 → pyield-0.48.4}/pyield/bc/ptax.py +17 -17
- {pyield-0.48.2 → pyield-0.48.4}/pyield/bc/taxas.py +26 -26
- {pyield-0.48.2 → pyield-0.48.4}/pyield/bc/tpf_intradia.py +2 -2
- {pyield-0.48.2/pyield/dus → pyield-0.48.4/pyield/du}/__init__.py +1 -1
- {pyield-0.48.2/pyield/dus → pyield-0.48.4/pyield/du}/core.py +41 -41
- pyield-0.48.4/pyield/du/feriados/__init__.py +3 -0
- pyield-0.48.4/pyield/ipca/__init__.py +10 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/ipca/historico.py +39 -33
- {pyield-0.48.2 → pyield-0.48.4}/pyield/selic/cpm.py +2 -2
- {pyield-0.48.2 → pyield-0.48.4}/pyield/tn/leiloes.py +5 -5
- {pyield-0.48.2 → pyield-0.48.4}/pyield/tn/lft.py +3 -3
- {pyield-0.48.2 → pyield-0.48.4}/pyield/tn/ltn.py +4 -4
- {pyield-0.48.2 → pyield-0.48.4}/pyield/tn/ntnb.py +7 -7
- {pyield-0.48.2 → pyield-0.48.4}/pyield/tn/ntnb1.py +3 -3
- {pyield-0.48.2 → pyield-0.48.4}/pyield/tn/ntnbprinc.py +2 -2
- {pyield-0.48.2 → pyield-0.48.4}/pyield/tn/ntnc.py +10 -12
- {pyield-0.48.2 → pyield-0.48.4}/pyield/tn/ntnf.py +13 -13
- {pyield-0.48.2 → pyield-0.48.4}/pyield/tn/pre.py +2 -2
- pyield-0.48.2/pyield/__about__.py +0 -1
- pyield-0.48.2/pyield/dus/feriados/__init__.py +0 -3
- pyield-0.48.2/pyield/ipca/__init__.py +0 -10
- {pyield-0.48.2 → pyield-0.48.4}/.gitignore +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/LICENSE +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/_internal/__init__.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/_internal/br_numbers.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/_internal/cache.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/_internal/data_cache.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/_internal/retry.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/_internal/types.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/anbima/__init__.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/anbima/ettj_intradia.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/anbima/ettj_ultima.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/anbima/ima_ultimo.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/anbima/imaq.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/b3/__init__.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/b3/_contratos.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/b3/boletim.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/b3/derivativos_intradia.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/b3/di_over.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/b3/futuro/__init__.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/bc/__init__.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/bc/tpf_mensal.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/bc/vna.py +0 -0
- {pyield-0.48.2/pyield/dus → pyield-0.48.4/pyield/du}/feriados/feriados_antigos_br.txt +0 -0
- {pyield-0.48.2/pyield/dus → pyield-0.48.4/pyield/du}/feriados/feriados_br.py +0 -0
- {pyield-0.48.2/pyield/dus → pyield-0.48.4/pyield/du}/feriados/feriados_novos_br.txt +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/fwd.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/interpolador.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/ipca/projetado.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/py.typed +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/relogio.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/selic/__init__.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/selic/probabilities.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/tn/__init__.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/tn/benchmark.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/tn/rmd.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyield/tn/utils.py +0 -0
- {pyield-0.48.2 → pyield-0.48.4}/pyproject.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyield
|
|
3
|
-
Version: 0.48.
|
|
3
|
+
Version: 0.48.4
|
|
4
4
|
Summary: A Python library for analysis of fixed income instruments in Brazil
|
|
5
5
|
Project-URL: Homepage, https://github.com/crdcj/PYield
|
|
6
6
|
Project-URL: Documentation, https://crdcj.github.io/PYield
|
|
@@ -64,11 +64,11 @@ pip install pyield
|
|
|
64
64
|
## Início Rápido
|
|
65
65
|
|
|
66
66
|
```python
|
|
67
|
-
from pyield import
|
|
67
|
+
from pyield import du, b3, bc, ntnb, Interpolador
|
|
68
68
|
|
|
69
69
|
# Dias úteis (base de todos os cálculos)
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
du.contar("02-01-2025", "15-01-2025") # -> 9
|
|
71
|
+
du.deslocar("29-12-2023", 1) # -> datetime.date(2024, 1, 2)
|
|
72
72
|
|
|
73
73
|
# Curva de DI Futuro
|
|
74
74
|
df = b3.futuro("31-05-2024", "DI1")
|
|
@@ -92,28 +92,28 @@ Um notebook no Colab com mais exemplos:
|
|
|
92
92
|
|
|
93
93
|
## Blocos Principais
|
|
94
94
|
|
|
95
|
-
### Dias Úteis (`
|
|
95
|
+
### Dias Úteis (`du`)
|
|
96
96
|
|
|
97
|
-
O módulo `
|
|
97
|
+
O módulo `du` é a base do PYield. Todos os cálculos com datas (preço, duration, taxas a termo) dependem da contagem correta de dias úteis com feriados brasileiros.
|
|
98
98
|
|
|
99
99
|
```python
|
|
100
|
-
from pyield import
|
|
100
|
+
from pyield import du
|
|
101
101
|
|
|
102
102
|
# Conta dias úteis (início inclusivo, fim exclusivo)
|
|
103
|
-
|
|
103
|
+
du.contar("29-12-2023", "02-01-2024") # -> 1
|
|
104
104
|
|
|
105
105
|
# Avança N dias úteis
|
|
106
|
-
|
|
106
|
+
du.deslocar("29-12-2023", 1) # -> datetime.date(2024, 1, 2)
|
|
107
107
|
|
|
108
108
|
# Ajusta dia não útil para o próximo dia útil
|
|
109
|
-
|
|
109
|
+
du.deslocar("30-12-2023", 0) # -> datetime.date(2024, 1, 2)
|
|
110
110
|
|
|
111
111
|
# Gera intervalo de dias úteis
|
|
112
|
-
|
|
112
|
+
du.gerar("22-12-2023", "02-01-2024")
|
|
113
113
|
# -> Series: [2023-12-22, 2023-12-26, 2023-12-27, 2023-12-28, 2023-12-29, 2024-01-02]
|
|
114
114
|
|
|
115
115
|
# Verifica se a data é dia útil
|
|
116
|
-
|
|
116
|
+
du.e_dia_util("25-12-2023") # -> False (Natal)
|
|
117
117
|
```
|
|
118
118
|
|
|
119
119
|
Todas as funções suportam operações vetorizadas com listas, Series ou arrays.
|
|
@@ -170,7 +170,7 @@ forwards(dias_uteis, taxas) # -> Series: [0.05, 0.070095, 0.090284]
|
|
|
170
170
|
|
|
171
171
|
| Módulo | Finalidade |
|
|
172
172
|
|--------|---------|
|
|
173
|
-
| `
|
|
173
|
+
| `du` | Calendário de dias úteis com feriados brasileiros |
|
|
174
174
|
| `b3.futuro` | Dados históricos de futuros da B3 (DI1, DDI, DAP, DOL, WDO, IND, WIN e outros) |
|
|
175
175
|
| `b3.di1` | Curva DI1 interpolada e datas de negociação disponíveis |
|
|
176
176
|
| `Interpolador` | Interpolação de taxas (flat_forward, linear) |
|
|
@@ -241,10 +241,10 @@ Tratamento de nulos: funções escalares retornam `float('nan')` para entradas a
|
|
|
241
241
|
(propaga nos cálculos). Funções vetorizadas propagam `null` elemento a elemento.
|
|
242
242
|
|
|
243
243
|
```python
|
|
244
|
-
from pyield import ntnb,
|
|
244
|
+
from pyield import ntnb, du
|
|
245
245
|
|
|
246
246
|
ntnb.cotacao(None, "15-05-2035", 0.06149) # -> nan
|
|
247
|
-
|
|
247
|
+
du.contar(["01-01-2024", None], "01-02-2024") # -> Series: [22, null]
|
|
248
248
|
```
|
|
249
249
|
|
|
250
250
|
Consultas sem dados disponíveis (data futura, feriado, fim de semana ou
|
|
@@ -264,11 +264,11 @@ A partir da versão 0.48.0, a API pública foi migrada para o português. Os pri
|
|
|
264
264
|
|
|
265
265
|
| Antes (< 0.48) | Depois (≥ 0.48) |
|
|
266
266
|
|---|---|
|
|
267
|
-
| `yd.bday` | `yd.
|
|
268
|
-
| `bday.count()` | `
|
|
269
|
-
| `bday.offset()` | `
|
|
270
|
-
| `bday.generate()` | `
|
|
271
|
-
| `bday.is_business_day()` | `
|
|
267
|
+
| `yd.bday` | `yd.du` |
|
|
268
|
+
| `bday.count()` | `du.contar()` |
|
|
269
|
+
| `bday.offset()` | `du.deslocar()` |
|
|
270
|
+
| `bday.generate()` | `du.gerar()` |
|
|
271
|
+
| `bday.is_business_day()` | `du.e_dia_util()` |
|
|
272
272
|
| `Interpolator(method, bdays, rates)` | `Interpolador(dias_uteis, taxas, metodo=...)` |
|
|
273
273
|
| `extrapolate=True` | `extrapolar=True` |
|
|
274
274
|
| `ntnb.quotation()` | `ntnb.cotacao()` |
|
|
@@ -20,11 +20,11 @@ pip install pyield
|
|
|
20
20
|
## Início Rápido
|
|
21
21
|
|
|
22
22
|
```python
|
|
23
|
-
from pyield import
|
|
23
|
+
from pyield import du, b3, bc, ntnb, Interpolador
|
|
24
24
|
|
|
25
25
|
# Dias úteis (base de todos os cálculos)
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
du.contar("02-01-2025", "15-01-2025") # -> 9
|
|
27
|
+
du.deslocar("29-12-2023", 1) # -> datetime.date(2024, 1, 2)
|
|
28
28
|
|
|
29
29
|
# Curva de DI Futuro
|
|
30
30
|
df = b3.futuro("31-05-2024", "DI1")
|
|
@@ -48,28 +48,28 @@ Um notebook no Colab com mais exemplos:
|
|
|
48
48
|
|
|
49
49
|
## Blocos Principais
|
|
50
50
|
|
|
51
|
-
### Dias Úteis (`
|
|
51
|
+
### Dias Úteis (`du`)
|
|
52
52
|
|
|
53
|
-
O módulo `
|
|
53
|
+
O módulo `du` é a base do PYield. Todos os cálculos com datas (preço, duration, taxas a termo) dependem da contagem correta de dias úteis com feriados brasileiros.
|
|
54
54
|
|
|
55
55
|
```python
|
|
56
|
-
from pyield import
|
|
56
|
+
from pyield import du
|
|
57
57
|
|
|
58
58
|
# Conta dias úteis (início inclusivo, fim exclusivo)
|
|
59
|
-
|
|
59
|
+
du.contar("29-12-2023", "02-01-2024") # -> 1
|
|
60
60
|
|
|
61
61
|
# Avança N dias úteis
|
|
62
|
-
|
|
62
|
+
du.deslocar("29-12-2023", 1) # -> datetime.date(2024, 1, 2)
|
|
63
63
|
|
|
64
64
|
# Ajusta dia não útil para o próximo dia útil
|
|
65
|
-
|
|
65
|
+
du.deslocar("30-12-2023", 0) # -> datetime.date(2024, 1, 2)
|
|
66
66
|
|
|
67
67
|
# Gera intervalo de dias úteis
|
|
68
|
-
|
|
68
|
+
du.gerar("22-12-2023", "02-01-2024")
|
|
69
69
|
# -> Series: [2023-12-22, 2023-12-26, 2023-12-27, 2023-12-28, 2023-12-29, 2024-01-02]
|
|
70
70
|
|
|
71
71
|
# Verifica se a data é dia útil
|
|
72
|
-
|
|
72
|
+
du.e_dia_util("25-12-2023") # -> False (Natal)
|
|
73
73
|
```
|
|
74
74
|
|
|
75
75
|
Todas as funções suportam operações vetorizadas com listas, Series ou arrays.
|
|
@@ -126,7 +126,7 @@ forwards(dias_uteis, taxas) # -> Series: [0.05, 0.070095, 0.090284]
|
|
|
126
126
|
|
|
127
127
|
| Módulo | Finalidade |
|
|
128
128
|
|--------|---------|
|
|
129
|
-
| `
|
|
129
|
+
| `du` | Calendário de dias úteis com feriados brasileiros |
|
|
130
130
|
| `b3.futuro` | Dados históricos de futuros da B3 (DI1, DDI, DAP, DOL, WDO, IND, WIN e outros) |
|
|
131
131
|
| `b3.di1` | Curva DI1 interpolada e datas de negociação disponíveis |
|
|
132
132
|
| `Interpolador` | Interpolação de taxas (flat_forward, linear) |
|
|
@@ -197,10 +197,10 @@ Tratamento de nulos: funções escalares retornam `float('nan')` para entradas a
|
|
|
197
197
|
(propaga nos cálculos). Funções vetorizadas propagam `null` elemento a elemento.
|
|
198
198
|
|
|
199
199
|
```python
|
|
200
|
-
from pyield import ntnb,
|
|
200
|
+
from pyield import ntnb, du
|
|
201
201
|
|
|
202
202
|
ntnb.cotacao(None, "15-05-2035", 0.06149) # -> nan
|
|
203
|
-
|
|
203
|
+
du.contar(["01-01-2024", None], "01-02-2024") # -> Series: [22, null]
|
|
204
204
|
```
|
|
205
205
|
|
|
206
206
|
Consultas sem dados disponíveis (data futura, feriado, fim de semana ou
|
|
@@ -220,11 +220,11 @@ A partir da versão 0.48.0, a API pública foi migrada para o português. Os pri
|
|
|
220
220
|
|
|
221
221
|
| Antes (< 0.48) | Depois (≥ 0.48) |
|
|
222
222
|
|---|---|
|
|
223
|
-
| `yd.bday` | `yd.
|
|
224
|
-
| `bday.count()` | `
|
|
225
|
-
| `bday.offset()` | `
|
|
226
|
-
| `bday.generate()` | `
|
|
227
|
-
| `bday.is_business_day()` | `
|
|
223
|
+
| `yd.bday` | `yd.du` |
|
|
224
|
+
| `bday.count()` | `du.contar()` |
|
|
225
|
+
| `bday.offset()` | `du.deslocar()` |
|
|
226
|
+
| `bday.generate()` | `du.gerar()` |
|
|
227
|
+
| `bday.is_business_day()` | `du.e_dia_util()` |
|
|
228
228
|
| `Interpolator(method, bdays, rates)` | `Interpolador(dias_uteis, taxas, metodo=...)` |
|
|
229
229
|
| `extrapolate=True` | `extrapolar=True` |
|
|
230
230
|
| `ntnb.quotation()` | `ntnb.cotacao()` |
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.48.4"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
|
|
3
|
-
from pyield import anbima, b3, bc,
|
|
3
|
+
from pyield import anbima, b3, bc, du, ipca, selic, tn
|
|
4
4
|
from pyield.__about__ import __version__
|
|
5
5
|
from pyield.b3 import di1
|
|
6
6
|
from pyield.fwd import forward, forwards
|
|
@@ -18,7 +18,7 @@ __all__ = [
|
|
|
18
18
|
"bc",
|
|
19
19
|
"copom_options",
|
|
20
20
|
"di1",
|
|
21
|
-
"
|
|
21
|
+
"du",
|
|
22
22
|
"forward",
|
|
23
23
|
"forwards",
|
|
24
24
|
"hoje",
|
|
@@ -11,9 +11,9 @@ def data_referencia_valida(date: dt.date | None) -> bool:
|
|
|
11
11
|
"""Verifica se a data é dia útil e não está no futuro."""
|
|
12
12
|
if date is None:
|
|
13
13
|
return False
|
|
14
|
-
from pyield import
|
|
14
|
+
from pyield import du, relogio # noqa: PLC0415
|
|
15
15
|
|
|
16
|
-
return
|
|
16
|
+
return du.e_dia_util(date) and date <= relogio.hoje()
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
def converter_datas_expr(expr: pl.Expr | str) -> pl.Expr:
|
|
@@ -19,7 +19,7 @@ from typing import Literal
|
|
|
19
19
|
import polars as pl
|
|
20
20
|
import requests
|
|
21
21
|
|
|
22
|
-
from pyield import
|
|
22
|
+
from pyield import du
|
|
23
23
|
from pyield._internal.br_numbers import float_br, taxa_br
|
|
24
24
|
from pyield._internal.converters import converter_datas, data_referencia_valida
|
|
25
25
|
from pyield._internal.data_cache import obter_dataset_cacheado
|
|
@@ -74,8 +74,8 @@ def _montar_nome_arquivo(data: dt.date) -> str:
|
|
|
74
74
|
|
|
75
75
|
|
|
76
76
|
def _montar_url_arquivo(data: dt.date) -> str:
|
|
77
|
-
ultimo_dia_util =
|
|
78
|
-
qtd_dias_uteis =
|
|
77
|
+
ultimo_dia_util = du.ultimo_dia_util()
|
|
78
|
+
qtd_dias_uteis = du.contar(data, ultimo_dia_util)
|
|
79
79
|
if qtd_dias_uteis > DIAS_RETENCAO_PUBLICA:
|
|
80
80
|
# Para datas com mais de 5 dias úteis, apenas os dados da RTM estão disponíveis
|
|
81
81
|
logger.info("Tentando buscar dados RTM para %s", data.strftime("%d/%m/%Y"))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import datetime as dt
|
|
2
2
|
|
|
3
|
-
from pyield import
|
|
3
|
+
from pyield import du, relogio
|
|
4
4
|
|
|
5
5
|
# Pregão abre às 9:00, porém os dados intradia têm atraso de 15 minutos.
|
|
6
6
|
# Esperar 1 minuto adicional para garantir que estejam disponíveis (9:16h).
|
|
@@ -18,7 +18,7 @@ def data_negociacao_valida(data_negociacao: dt.date) -> bool:
|
|
|
18
18
|
"""
|
|
19
19
|
if data_negociacao > relogio.hoje():
|
|
20
20
|
return False
|
|
21
|
-
if not
|
|
21
|
+
if not du.e_dia_util(data_negociacao):
|
|
22
22
|
return False
|
|
23
23
|
|
|
24
24
|
# Não tem pregão na véspera de Natal e Ano Novo
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import polars as pl
|
|
2
2
|
|
|
3
3
|
import pyield._internal.converters as cv
|
|
4
|
-
from pyield import b3,
|
|
4
|
+
from pyield import b3, du, interpolador
|
|
5
5
|
from pyield._internal.data_cache import obter_dataset_cacheado
|
|
6
6
|
from pyield._internal.types import ArrayLike, DateLike, any_is_collection, any_is_empty
|
|
7
7
|
from pyield.b3.futuro import futuro_datas_disponiveis as _listar_datas
|
|
@@ -74,7 +74,7 @@ def dados(
|
|
|
74
74
|
.unique(subset=["data_vencimento", "data_referencia"])
|
|
75
75
|
.select(
|
|
76
76
|
data_ref_tpf=pl.col("data_referencia"),
|
|
77
|
-
data_vencimento=
|
|
77
|
+
data_vencimento=du.deslocar_expr("data_vencimento", 0),
|
|
78
78
|
)
|
|
79
79
|
.sort("data_ref_tpf", "data_vencimento")
|
|
80
80
|
)
|
|
@@ -207,7 +207,7 @@ def interpolar_taxas(
|
|
|
207
207
|
|
|
208
208
|
# Inicializa taxa_interpolada como None
|
|
209
209
|
df_entrada = df_entrada.with_columns(
|
|
210
|
-
dias_uteis=
|
|
210
|
+
dias_uteis=du.contar_expr("data_referencia", "data_vencimento"),
|
|
211
211
|
taxa_interpolada=None,
|
|
212
212
|
)
|
|
213
213
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import polars as pl
|
|
2
2
|
|
|
3
|
-
from pyield import
|
|
3
|
+
from pyield import du
|
|
4
4
|
|
|
5
5
|
# Lista de contratos que negociam por taxa (juros/cupom).
|
|
6
6
|
# Nestes contratos, as colunas OHLC são taxas e precisam ser divididas por 100.
|
|
@@ -71,6 +71,6 @@ def adicionar_vencimento(
|
|
|
71
71
|
).alias("data_vencimento")
|
|
72
72
|
)
|
|
73
73
|
# Garante que a data de vencimento é um dia útil
|
|
74
|
-
df = df.with_columns(data_vencimento=
|
|
74
|
+
df = df.with_columns(data_vencimento=du.deslocar_expr("data_vencimento", 0))
|
|
75
75
|
|
|
76
76
|
return df
|
|
@@ -3,7 +3,7 @@ import datetime as dt
|
|
|
3
3
|
import polars as pl
|
|
4
4
|
import polars.selectors as cs
|
|
5
5
|
|
|
6
|
-
from pyield import
|
|
6
|
+
from pyield import du
|
|
7
7
|
from pyield._internal.data_cache import obter_dataset_cacheado
|
|
8
8
|
from pyield.b3.futuro.contratos import (
|
|
9
9
|
CONTRATOS_TAXA,
|
|
@@ -107,7 +107,7 @@ def _obter_cache_filtrado(contrato: str) -> pl.DataFrame:
|
|
|
107
107
|
|
|
108
108
|
def _enriquecer_dados(df: pl.DataFrame, contrato: str) -> pl.DataFrame:
|
|
109
109
|
df = df.with_columns(
|
|
110
|
-
dias_uteis=
|
|
110
|
+
dias_uteis=du.contar_expr("data_referencia", "data_vencimento"),
|
|
111
111
|
dias_corridos=(
|
|
112
112
|
pl.col("data_vencimento") - pl.col("data_referencia")
|
|
113
113
|
).dt.total_days(),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import polars as pl
|
|
2
2
|
import polars.selectors as cs
|
|
3
3
|
|
|
4
|
-
from pyield import
|
|
4
|
+
from pyield import du
|
|
5
5
|
from pyield.b3._validar_pregao import intradia_disponivel
|
|
6
6
|
from pyield.b3.derivativos_intradia import derivativo_intradia
|
|
7
7
|
from pyield.b3.futuro.contratos import CONTRATOS_TAXA, expr_dv01
|
|
@@ -92,11 +92,11 @@ def _processar_intradia(df: pl.DataFrame, contrato: str) -> pl.DataFrame:
|
|
|
92
92
|
df = df.rename(_PRECO_PARA_TAXA_INTRADIA, strict=False)
|
|
93
93
|
df = df.drop_nulls("data_vencimento").sort("data_vencimento")
|
|
94
94
|
|
|
95
|
-
data_negociacao =
|
|
95
|
+
data_negociacao = du.ultimo_dia_util()
|
|
96
96
|
df = df.with_columns(
|
|
97
97
|
data_referencia=data_negociacao,
|
|
98
98
|
dias_corridos=(pl.col("data_vencimento") - data_negociacao).dt.total_days(),
|
|
99
|
-
dias_uteis=
|
|
99
|
+
dias_uteis=du.contar_expr(data_negociacao, "data_vencimento"),
|
|
100
100
|
).filter(pl.col("dias_corridos") > 0)
|
|
101
101
|
|
|
102
102
|
if contrato in CONTRATOS_TAXA:
|
|
@@ -16,7 +16,7 @@ import polars as pl
|
|
|
16
16
|
import requests
|
|
17
17
|
|
|
18
18
|
import pyield._internal.converters as cv
|
|
19
|
-
from pyield import
|
|
19
|
+
from pyield import du
|
|
20
20
|
from pyield._internal.br_numbers import float_br, taxa_br
|
|
21
21
|
from pyield._internal.retry import retry_padrao
|
|
22
22
|
from pyield._internal.types import DateLike
|
|
@@ -25,25 +25,25 @@ URL_BASE_API = "https://olinda.bcb.gov.br/olinda/servico/leiloes_selic/versao/v1
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
def _montar_url(
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
inicio: DateLike | None,
|
|
29
|
+
fim: DateLike | None,
|
|
30
30
|
) -> str:
|
|
31
31
|
"""Monta URL de consulta conforme parâmetros opcionais de período.
|
|
32
32
|
|
|
33
33
|
Regras da API:
|
|
34
|
-
- Apenas
|
|
35
|
-
- Apenas
|
|
34
|
+
- Apenas inicio: retorna de inicio até o fim da série.
|
|
35
|
+
- Apenas fim: retorna do início da série até fim.
|
|
36
36
|
- Ambos ausentes: retorna a série completa.
|
|
37
37
|
"""
|
|
38
38
|
url = URL_BASE_API
|
|
39
|
-
if
|
|
40
|
-
|
|
41
|
-
inicio_str =
|
|
39
|
+
if inicio:
|
|
40
|
+
inicio_dt = cv.converter_datas(inicio)
|
|
41
|
+
inicio_str = inicio_dt.strftime("%Y-%m-%d")
|
|
42
42
|
url += f"@dataLancamentoInicio='{inicio_str}'"
|
|
43
43
|
|
|
44
|
-
if
|
|
45
|
-
|
|
46
|
-
fim_str =
|
|
44
|
+
if fim:
|
|
45
|
+
fim_dt = cv.converter_datas(fim)
|
|
46
|
+
fim_str = fim_dt.strftime("%Y-%m-%d")
|
|
47
47
|
url += f"&@dataLancamentoFim='{fim_str}'"
|
|
48
48
|
|
|
49
49
|
url += "&$format=text/csv" # Adiciona o formato CSV ao final
|
|
@@ -81,7 +81,7 @@ def _processar_df(df: pl.DataFrame) -> pl.DataFrame:
|
|
|
81
81
|
data_retorno=pl.col("dataRetorno").str.to_date("%Y-%m-%d"),
|
|
82
82
|
hora_inicio=pl.col("horaInicio").str.to_time("%H:%M"),
|
|
83
83
|
prazo_dias_corridos=pl.col("prazoDiasCorridos").cast(pl.Int64),
|
|
84
|
-
prazo_dias_uteis=
|
|
84
|
+
prazo_dias_uteis=du.contar_expr("dataLiquidacao", "dataRetorno"),
|
|
85
85
|
numero_comunicado=pl.col("numeroComunicado").cast(pl.Int64),
|
|
86
86
|
tipo_oferta=pl.col("nomeTipoOferta"),
|
|
87
87
|
publico_permitido=pl.col("publicoPermitidoLeilao"),
|
|
@@ -94,19 +94,19 @@ def _processar_df(df: pl.DataFrame) -> pl.DataFrame:
|
|
|
94
94
|
|
|
95
95
|
|
|
96
96
|
def compromissadas(
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
inicio: DateLike | None = None,
|
|
98
|
+
fim: DateLike | None = None,
|
|
99
99
|
) -> pl.DataFrame:
|
|
100
100
|
"""Consulta e retorna leilões de operações compromissadas do BCB.
|
|
101
101
|
|
|
102
102
|
Semântica dos parâmetros de período (API OData):
|
|
103
|
-
-
|
|
104
|
-
-
|
|
103
|
+
- inicio somente: dados de inicio até o fim da série.
|
|
104
|
+
- fim somente: dados do início da série até fim.
|
|
105
105
|
- ambos omitidos: série histórica completa.
|
|
106
106
|
|
|
107
107
|
Args:
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
inicio: Data inicial (inclusive) ou None.
|
|
109
|
+
fim: Data final (inclusive) ou None.
|
|
110
110
|
|
|
111
111
|
Returns:
|
|
112
112
|
DataFrame com colunas normalizadas em português e tipos
|
|
@@ -119,7 +119,7 @@ def compromissadas(
|
|
|
119
119
|
- hora_inicio (Time): horário de início do leilão.
|
|
120
120
|
- prazo_dias_corridos (Int64): dias corridos até a data de retorno.
|
|
121
121
|
- prazo_dias_uteis (Int64): dias úteis entre liquidação e retorno
|
|
122
|
-
(
|
|
122
|
+
(du.contar).
|
|
123
123
|
- numero_comunicado (Int64): número do comunicado/aviso do BC (pode ser nulo).
|
|
124
124
|
- tipo_oferta (String): classif. do tipo de oferta (ex: Tomador, Compromissada 1047).
|
|
125
125
|
- publico_permitido (String): escopo de participantes (SomenteDealer, TodoMercado).
|
|
@@ -133,7 +133,7 @@ def compromissadas(
|
|
|
133
133
|
|
|
134
134
|
Examples:
|
|
135
135
|
>>> from pyield import bc
|
|
136
|
-
>>> bc.compromissadas(
|
|
136
|
+
>>> bc.compromissadas(inicio="21-08-2025", fim="21-08-2025")
|
|
137
137
|
shape: (2, 12)
|
|
138
138
|
┌─────────────┬─────────────────┬──────────────┬─────────────┬───┬───────────────────┬───────────────┬────────────┬───────────────────┐
|
|
139
139
|
│ data_leilao ┆ data_liquidacao ┆ data_retorno ┆ hora_inicio ┆ … ┆ publico_permitido ┆ volume_aceito ┆ taxa_corte ┆ percentual_aceito │
|
|
@@ -144,7 +144,7 @@ def compromissadas(
|
|
|
144
144
|
│ 2025-08-21 ┆ 2025-08-22 ┆ 2025-11-21 ┆ 12:00:00 ┆ … ┆ TodoMercado ┆ 5000000000 ┆ 0.9978 ┆ 35.87 │
|
|
145
145
|
└─────────────┴─────────────────┴──────────────┴─────────────┴───┴───────────────────┴───────────────┴────────────┴───────────────────┘
|
|
146
146
|
"""
|
|
147
|
-
url = _montar_url(
|
|
147
|
+
url = _montar_url(inicio=inicio, fim=fim)
|
|
148
148
|
csv_api = _buscar_csv_api(url)
|
|
149
149
|
df = _ler_csv(csv_api)
|
|
150
150
|
if df.is_empty():
|
|
@@ -20,7 +20,7 @@ import logging
|
|
|
20
20
|
import polars as pl
|
|
21
21
|
import requests
|
|
22
22
|
|
|
23
|
-
from pyield import
|
|
23
|
+
from pyield import du, relogio
|
|
24
24
|
from pyield._internal.converters import converter_datas
|
|
25
25
|
from pyield._internal.retry import retry_padrao
|
|
26
26
|
from pyield._internal.types import DateLike
|
|
@@ -146,8 +146,8 @@ def calendar(
|
|
|
146
146
|
|
|
147
147
|
Notes
|
|
148
148
|
-----
|
|
149
|
-
ExpiryDate is computed with ``
|
|
150
|
-
the Brazilian holiday calendar already embedded in ``pyield.
|
|
149
|
+
ExpiryDate is computed with ``du.deslocar_expr("EndDate", 1)``, using
|
|
150
|
+
the Brazilian holiday calendar already embedded in ``pyield.du``.
|
|
151
151
|
|
|
152
152
|
Examples
|
|
153
153
|
--------
|
|
@@ -169,7 +169,7 @@ def calendar(
|
|
|
169
169
|
|
|
170
170
|
# ExpiryDate: next business day after the meeting ends.
|
|
171
171
|
# Vectorized via deslocar_expr — consistent with the rest of the codebase.
|
|
172
|
-
df = df.with_columns(ExpiryDate=
|
|
172
|
+
df = df.with_columns(ExpiryDate=du.deslocar_expr("EndDate", 1))
|
|
173
173
|
|
|
174
174
|
# Optional date-range filter on EndDate
|
|
175
175
|
if start is not None:
|
|
@@ -15,7 +15,7 @@ import polars.selectors as cs
|
|
|
15
15
|
import requests
|
|
16
16
|
|
|
17
17
|
import pyield._internal.converters as cv
|
|
18
|
-
from pyield import
|
|
18
|
+
from pyield import du
|
|
19
19
|
from pyield._internal.br_numbers import float_br, taxa_br
|
|
20
20
|
from pyield._internal.retry import retry_padrao
|
|
21
21
|
from pyield._internal.types import DateLike
|
|
@@ -78,17 +78,17 @@ MAPA_TIPO_LEILAO = {"venda": "Venda", "compra": "Compra"}
|
|
|
78
78
|
|
|
79
79
|
|
|
80
80
|
def _montar_url(
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
inicio: DateLike | None = None,
|
|
82
|
+
fim: DateLike | None = None,
|
|
83
83
|
tipo_leilao: Literal["venda", "compra"] | None = None,
|
|
84
84
|
) -> str:
|
|
85
85
|
url = URL_BASE_API
|
|
86
|
-
if
|
|
87
|
-
|
|
88
|
-
url += f"@dataMovimentoInicio='{
|
|
89
|
-
if
|
|
90
|
-
|
|
91
|
-
url += f"&@dataMovimentoFim='{
|
|
86
|
+
if inicio:
|
|
87
|
+
inicio = cv.converter_datas(inicio)
|
|
88
|
+
url += f"@dataMovimentoInicio='{inicio:%Y-%m-%d}'"
|
|
89
|
+
if fim:
|
|
90
|
+
fim = cv.converter_datas(fim)
|
|
91
|
+
url += f"&@dataMovimentoFim='{fim:%Y-%m-%d}'"
|
|
92
92
|
if tipo_leilao:
|
|
93
93
|
url += f"&@tipoOferta='{MAPA_TIPO_LEILAO[tipo_leilao.lower()]}'"
|
|
94
94
|
url += "&$format=text/csv"
|
|
@@ -174,7 +174,7 @@ def _processar_df(df: pl.DataFrame) -> pl.DataFrame:
|
|
|
174
174
|
quantidade_liquidada_total=pl.sum_horizontal(
|
|
175
175
|
"quantidade_liquidada_1v", "quantidade_liquidada_2v"
|
|
176
176
|
),
|
|
177
|
-
dias_uteis=
|
|
177
|
+
dias_uteis=du.contar_expr("data_liquidacao", "data_vencimento"),
|
|
178
178
|
)
|
|
179
179
|
.with_columns(
|
|
180
180
|
financeiro_1v=pl.when(pl.col("quantidade_aceita_1v") != 0)
|
|
@@ -231,11 +231,11 @@ def _buscar_ptax(df: pl.DataFrame) -> pl.DataFrame:
|
|
|
231
231
|
assert isinstance(data_inicio, dt.date)
|
|
232
232
|
assert isinstance(data_fim, dt.date)
|
|
233
233
|
|
|
234
|
-
ultimo_dia_util =
|
|
234
|
+
ultimo_dia_util = du.ultimo_dia_util()
|
|
235
235
|
if data_inicio >= ultimo_dia_util:
|
|
236
|
-
data_inicio =
|
|
236
|
+
data_inicio = du.deslocar(ultimo_dia_util, -1)
|
|
237
237
|
|
|
238
|
-
df_ptax = ptax_serie(
|
|
238
|
+
df_ptax = ptax_serie(inicio=data_inicio, fim=data_fim)
|
|
239
239
|
if df_ptax.is_empty():
|
|
240
240
|
return pl.DataFrame()
|
|
241
241
|
|
|
@@ -265,21 +265,21 @@ def _adicionar_dv01_usd(df: pl.DataFrame) -> pl.DataFrame:
|
|
|
265
265
|
|
|
266
266
|
|
|
267
267
|
def leiloes(
|
|
268
|
-
|
|
269
|
-
|
|
268
|
+
inicio: DateLike | None = None,
|
|
269
|
+
fim: DateLike | None = None,
|
|
270
270
|
tipo_leilao: Literal["venda", "compra"] | None = None,
|
|
271
271
|
) -> pl.DataFrame:
|
|
272
272
|
"""Dados de leilões de títulos públicos federais do BCB.
|
|
273
273
|
|
|
274
274
|
Fonte: Banco Central do Brasil. Disponível desde 12/11/2012.
|
|
275
275
|
|
|
276
|
-
Se ambos `
|
|
276
|
+
Se ambos `inicio` e `fim` forem omitidos, retorna a série
|
|
277
277
|
histórica completa. Se apenas um for informado, a API do BCB
|
|
278
278
|
usa o início ou fim do histórico como limite.
|
|
279
279
|
|
|
280
280
|
Args:
|
|
281
|
-
|
|
282
|
-
|
|
281
|
+
inicio: Data de início. Padrão é ``None``.
|
|
282
|
+
fim: Data de fim. Padrão é ``None``.
|
|
283
283
|
tipo_leilao: Tipo de leilão (``"venda"`` ou ``"compra"``).
|
|
284
284
|
Padrão é ``None`` (todos).
|
|
285
285
|
|
|
@@ -328,7 +328,7 @@ def leiloes(
|
|
|
328
328
|
|
|
329
329
|
Examples:
|
|
330
330
|
>>> from pyield import bc
|
|
331
|
-
>>> bc.leiloes(
|
|
331
|
+
>>> bc.leiloes(inicio="19-08-2025", fim="19-08-2025")
|
|
332
332
|
shape: (5, 34)
|
|
333
333
|
┌─────────────┬─────────────────┬─────────────┬───────────────┬───┬─────────────────────────┬───────────────┬───────────────┬──────────────────┐
|
|
334
334
|
│ data_leilao ┆ data_liquidacao ┆ tipo_leilao ┆ numero_edital ┆ … ┆ quantidade_aceita_total ┆ financeiro_1v ┆ financeiro_2v ┆ financeiro_total │
|
|
@@ -343,8 +343,8 @@ def leiloes(
|
|
|
343
343
|
└─────────────┴─────────────────┴─────────────┴───────────────┴───┴─────────────────────────┴───────────────┴───────────────┴──────────────────┘
|
|
344
344
|
"""
|
|
345
345
|
url = _montar_url(
|
|
346
|
-
|
|
347
|
-
|
|
346
|
+
inicio=inicio,
|
|
347
|
+
fim=fim,
|
|
348
348
|
tipo_leilao=tipo_leilao,
|
|
349
349
|
)
|
|
350
350
|
dados = _buscar_csv(url)
|