pyield 0.47.4__tar.gz → 0.48.0__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.47.4 → pyield-0.48.0}/PKG-INFO +75 -57
- {pyield-0.47.4 → pyield-0.48.0}/README.md +74 -56
- pyield-0.48.0/pyield/__about__.py +1 -0
- pyield-0.48.0/pyield/__init__.py +29 -0
- {pyield-0.47.4 → pyield-0.48.0}/pyield/_internal/converters.py +2 -2
- {pyield-0.47.4 → pyield-0.48.0}/pyield/_internal/data_cache.py +6 -6
- pyield-0.48.0/pyield/anbima/__init__.py +15 -0
- pyield-0.47.4/pyield/anbima/ettj_intraday.py → pyield-0.48.0/pyield/anbima/ettj_intradia.py +8 -8
- pyield-0.47.4/pyield/anbima/ettj_last.py → pyield-0.48.0/pyield/anbima/ettj_ultima.py +5 -5
- pyield-0.47.4/pyield/anbima/ima.py → pyield-0.48.0/pyield/anbima/ima_ultimo.py +9 -9
- {pyield-0.47.4 → pyield-0.48.0}/pyield/anbima/imaq.py +4 -4
- {pyield-0.47.4 → pyield-0.48.0}/pyield/anbima/tpf.py +30 -29
- pyield-0.48.0/pyield/b3/__init__.py +27 -0
- pyield-0.47.4/pyield/b3/_contracts.py → pyield-0.48.0/pyield/b3/_contratos.py +15 -15
- {pyield-0.47.4 → pyield-0.48.0}/pyield/b3/_validar_pregao.py +10 -10
- pyield-0.47.4/pyield/b3/price_report.py → pyield-0.48.0/pyield/b3/boletim.py +46 -38
- pyield-0.47.4/pyield/b3/derivatives_intraday.py → pyield-0.48.0/pyield/b3/derivativos_intradia.py +19 -19
- {pyield-0.47.4 → pyield-0.48.0}/pyield/b3/di1.py +77 -74
- {pyield-0.47.4 → pyield-0.48.0}/pyield/b3/di_over.py +4 -4
- {pyield-0.47.4/pyield/b3/futures → pyield-0.48.0/pyield/b3/futuro}/__init__.py +39 -38
- pyield-0.47.4/pyield/b3/futures/common.py → pyield-0.48.0/pyield/b3/futuro/contratos.py +4 -4
- pyield-0.47.4/pyield/b3/futures/historical.py → pyield-0.48.0/pyield/b3/futuro/historico.py +31 -27
- pyield-0.47.4/pyield/b3/futures/intraday.py → pyield-0.48.0/pyield/b3/futuro/intradia.py +22 -22
- pyield-0.48.0/pyield/bc/__init__.py +33 -0
- pyield-0.47.4/pyield/bc/repo.py → pyield-0.48.0/pyield/bc/compromissada.py +25 -21
- {pyield-0.47.4 → pyield-0.48.0}/pyield/bc/copom.py +7 -7
- pyield-0.47.4/pyield/bc/auction.py → pyield-0.48.0/pyield/bc/leiloes.py +31 -38
- pyield-0.47.4/pyield/bc/ptax_api.py → pyield-0.48.0/pyield/bc/ptax.py +23 -20
- pyield-0.47.4/pyield/bc/rates.py → pyield-0.48.0/pyield/bc/taxas.py +54 -52
- pyield-0.47.4/pyield/bc/trades_intraday.py → pyield-0.48.0/pyield/bc/tpf_intradia.py +8 -8
- pyield-0.47.4/pyield/bc/trades_monthly.py → pyield-0.48.0/pyield/bc/tpf_mensal.py +14 -11
- {pyield-0.47.4 → pyield-0.48.0}/pyield/bc/vna.py +7 -7
- pyield-0.48.0/pyield/dus/__init__.py +21 -0
- {pyield-0.47.4/pyield/bday → pyield-0.48.0/pyield/dus}/core.py +230 -220
- pyield-0.48.0/pyield/dus/feriados/__init__.py +3 -0
- pyield-0.47.4/pyield/bday/holidays/br_holidays_old.txt → pyield-0.48.0/pyield/dus/feriados/feriados_antigos_br.txt +2 -2
- pyield-0.47.4/pyield/bday/holidays/brholidays.py → pyield-0.48.0/pyield/dus/feriados/feriados_br.py +19 -15
- pyield-0.47.4/pyield/bday/holidays/br_holidays_new.txt → pyield-0.48.0/pyield/dus/feriados/feriados_novos_br.txt +7 -5
- {pyield-0.47.4 → pyield-0.48.0}/pyield/fwd.py +57 -56
- pyield-0.47.4/pyield/interpolator.py → pyield-0.48.0/pyield/interpolador.py +42 -50
- pyield-0.48.0/pyield/ipca/__init__.py +10 -0
- pyield-0.47.4/pyield/ipca/historical.py → pyield-0.48.0/pyield/ipca/historico.py +21 -21
- pyield-0.47.4/pyield/ipca/projected.py → pyield-0.48.0/pyield/ipca/projetado.py +2 -2
- pyield-0.47.4/pyield/clock.py → pyield-0.48.0/pyield/relogio.py +7 -7
- {pyield-0.47.4 → pyield-0.48.0}/pyield/selic/cpm.py +9 -9
- {pyield-0.47.4 → pyield-0.48.0}/pyield/selic/probabilities.py +7 -7
- pyield-0.48.0/pyield/tn/__init__.py +19 -0
- {pyield-0.47.4 → pyield-0.48.0}/pyield/tn/benchmark.py +12 -11
- pyield-0.47.4/pyield/tn/auctions.py → pyield-0.48.0/pyield/tn/leiloes.py +71 -110
- {pyield-0.47.4 → pyield-0.48.0}/pyield/tn/lft.py +74 -64
- {pyield-0.47.4 → pyield-0.48.0}/pyield/tn/ltn.py +118 -109
- {pyield-0.47.4 → pyield-0.48.0}/pyield/tn/ntnb.py +213 -202
- {pyield-0.47.4 → pyield-0.48.0}/pyield/tn/ntnb1.py +98 -91
- pyield-0.48.0/pyield/tn/ntnbprinc.py +77 -0
- {pyield-0.47.4 → pyield-0.48.0}/pyield/tn/ntnc.py +92 -84
- {pyield-0.47.4 → pyield-0.48.0}/pyield/tn/ntnf.py +319 -298
- {pyield-0.47.4 → pyield-0.48.0}/pyield/tn/pre.py +69 -55
- {pyield-0.47.4/pyield → pyield-0.48.0/pyield/tn}/rmd.py +13 -21
- {pyield-0.47.4 → pyield-0.48.0}/pyield/tn/utils.py +37 -37
- pyield-0.47.4/pyield/__about__.py +0 -1
- pyield-0.47.4/pyield/__init__.py +0 -42
- pyield-0.47.4/pyield/anbima/__init__.py +0 -15
- pyield-0.47.4/pyield/b3/__init__.py +0 -27
- pyield-0.47.4/pyield/bc/__init__.py +0 -32
- pyield-0.47.4/pyield/bday/__init__.py +0 -21
- pyield-0.47.4/pyield/ipca/__init__.py +0 -15
- pyield-0.47.4/pyield/tn/__init__.py +0 -5
- pyield-0.47.4/pyield/tn/ntnbprinc.py +0 -77
- {pyield-0.47.4 → pyield-0.48.0}/.gitignore +0 -0
- {pyield-0.47.4 → pyield-0.48.0}/LICENSE +0 -0
- {pyield-0.47.4 → pyield-0.48.0}/pyield/_internal/__init__.py +0 -0
- {pyield-0.47.4 → pyield-0.48.0}/pyield/_internal/br_numbers.py +0 -0
- {pyield-0.47.4 → pyield-0.48.0}/pyield/_internal/cache.py +0 -0
- {pyield-0.47.4 → pyield-0.48.0}/pyield/_internal/retry.py +0 -0
- {pyield-0.47.4 → pyield-0.48.0}/pyield/_internal/types.py +0 -0
- {pyield-0.47.4 → pyield-0.48.0}/pyield/py.typed +0 -0
- {pyield-0.47.4 → pyield-0.48.0}/pyield/selic/__init__.py +0 -0
- {pyield-0.47.4 → pyield-0.48.0}/pyproject.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyield
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.48.0
|
|
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
|
|
@@ -63,26 +63,27 @@ pip install pyield
|
|
|
63
63
|
## Início Rápido
|
|
64
64
|
|
|
65
65
|
```python
|
|
66
|
-
|
|
66
|
+
from pyield import dus, b3, bc, Interpolador
|
|
67
|
+
from pyield.tn import ntnb
|
|
67
68
|
|
|
68
69
|
# Dias úteis (base de todos os cálculos)
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
dus.contar("02-01-2025", "15-01-2025") # -> 9
|
|
71
|
+
dus.deslocar("29-12-2023", 1) # -> datetime.date(2024, 1, 2)
|
|
71
72
|
|
|
72
73
|
# Curva de DI Futuro
|
|
73
|
-
df =
|
|
74
|
-
#
|
|
74
|
+
df = b3.futuro("31-05-2024", "DI1")
|
|
75
|
+
# Colunas: data_referencia, codigo_negociacao, data_vencimento, dias_uteis, taxa_ajuste, ...
|
|
75
76
|
|
|
76
77
|
# Interpolação de taxas (flat forward, convenção 252 dias úteis/ano)
|
|
77
|
-
interp =
|
|
78
|
+
interp = Interpolador(df["dias_uteis"], df["taxa_ajuste"], metodo="flat_forward")
|
|
78
79
|
interp(45) # -> 0.04833...
|
|
79
|
-
interp([30, 60]) # ->
|
|
80
|
+
interp([30, 60]) # -> Series do Polars com taxas interpoladas
|
|
80
81
|
|
|
81
82
|
# Precificação de títulos públicos
|
|
82
|
-
|
|
83
|
+
ntnb.cotacao("31-05-2024", "15-05-2035", 0.061490) # -> 99.3651
|
|
83
84
|
|
|
84
85
|
# Indicadores do BCB
|
|
85
|
-
|
|
86
|
+
bc.selic_over("31-05-2024") # -> 0.000414...
|
|
86
87
|
```
|
|
87
88
|
|
|
88
89
|
Um notebook no Colab com mais exemplos:
|
|
@@ -91,56 +92,56 @@ Um notebook no Colab com mais exemplos:
|
|
|
91
92
|
|
|
92
93
|
## Blocos Principais
|
|
93
94
|
|
|
94
|
-
### Dias Úteis (`
|
|
95
|
+
### Dias Úteis (`dus`)
|
|
95
96
|
|
|
96
|
-
O módulo `
|
|
97
|
+
O módulo `dus` é 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.
|
|
97
98
|
|
|
98
99
|
```python
|
|
99
|
-
from pyield import
|
|
100
|
+
from pyield import dus
|
|
100
101
|
|
|
101
102
|
# Conta dias úteis (início inclusivo, fim exclusivo)
|
|
102
|
-
|
|
103
|
+
dus.contar("29-12-2023", "02-01-2024") # -> 1
|
|
103
104
|
|
|
104
105
|
# Avança N dias úteis
|
|
105
|
-
|
|
106
|
+
dus.deslocar("29-12-2023", 1) # -> datetime.date(2024, 1, 2)
|
|
106
107
|
|
|
107
108
|
# Ajusta dia não útil para o próximo dia útil
|
|
108
|
-
|
|
109
|
+
dus.deslocar("30-12-2023", 0) # -> datetime.date(2024, 1, 2)
|
|
109
110
|
|
|
110
111
|
# Gera intervalo de dias úteis
|
|
111
|
-
|
|
112
|
+
dus.gerar("22-12-2023", "02-01-2024")
|
|
112
113
|
# -> Series: [2023-12-22, 2023-12-26, 2023-12-27, 2023-12-28, 2023-12-29, 2024-01-02]
|
|
113
114
|
|
|
114
115
|
# Verifica se a data é dia útil
|
|
115
|
-
|
|
116
|
+
dus.e_dia_util("25-12-2023") # -> False (Natal)
|
|
116
117
|
```
|
|
117
118
|
|
|
118
119
|
Todas as funções suportam operações vetorizadas com listas, Series ou arrays.
|
|
119
120
|
|
|
120
|
-
### Interpolação de Taxas (`
|
|
121
|
+
### Interpolação de Taxas (`Interpolador`)
|
|
121
122
|
|
|
122
|
-
A classe `
|
|
123
|
+
A classe `Interpolador` interpola taxas usando a convenção de 252 dias úteis/ano, padrão no mercado brasileiro.
|
|
123
124
|
|
|
124
125
|
```python
|
|
125
|
-
from pyield import
|
|
126
|
+
from pyield import Interpolador
|
|
126
127
|
|
|
127
|
-
|
|
128
|
-
|
|
128
|
+
dias_uteis = [30, 60, 90]
|
|
129
|
+
taxas = [0.045, 0.05, 0.055]
|
|
129
130
|
|
|
130
131
|
# Interpolação flat forward (padrão de mercado)
|
|
131
|
-
interp =
|
|
132
|
+
interp = Interpolador(dias_uteis, taxas, metodo="flat_forward")
|
|
132
133
|
interp(45) # -> 0.04833...
|
|
133
134
|
|
|
134
135
|
# Interpolação linear
|
|
135
|
-
linear =
|
|
136
|
+
linear = Interpolador(dias_uteis, taxas, metodo="linear")
|
|
136
137
|
linear(45) # -> 0.0475
|
|
137
138
|
|
|
138
139
|
# Vetorizado
|
|
139
|
-
interp([15, 45, 75]) # -> pl.Series
|
|
140
|
+
interp([15, 45, 75]) # -> pl.Series com 3 taxas
|
|
140
141
|
|
|
141
142
|
# Extrapolação (desabilitada por padrão, retorna NaN)
|
|
142
143
|
interp(100) # -> nan
|
|
143
|
-
|
|
144
|
+
Interpolador(dias_uteis, taxas, metodo="flat_forward", extrapolar=True)(100) # -> 0.055
|
|
144
145
|
```
|
|
145
146
|
|
|
146
147
|
### Taxas a Termo (`forward`, `forwards`)
|
|
@@ -157,33 +158,33 @@ Convenção utilizada:
|
|
|
157
158
|
from pyield import forward, forwards
|
|
158
159
|
|
|
159
160
|
# Taxa a termo única entre dois pontos
|
|
160
|
-
forward(
|
|
161
|
+
forward(10, 20, 0.05, 0.06) # -> 0.0700952...
|
|
161
162
|
|
|
162
163
|
# Curva a termo vetorizada a partir de taxas spot
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
forwards(
|
|
164
|
+
dias_uteis = [10, 20, 30]
|
|
165
|
+
taxas = [0.05, 0.06, 0.07]
|
|
166
|
+
forwards(dias_uteis, taxas) # -> Series: [0.05, 0.070095, 0.090284]
|
|
166
167
|
```
|
|
167
168
|
|
|
168
169
|
## Visão Geral dos Módulos
|
|
169
170
|
|
|
170
171
|
| Módulo | Finalidade |
|
|
171
172
|
|--------|---------|
|
|
172
|
-
| `
|
|
173
|
-
| `
|
|
174
|
-
| `di1` | Curva DI1 interpolada e datas de negociação disponíveis |
|
|
175
|
-
| `
|
|
173
|
+
| `dus` | Calendário de dias úteis com feriados brasileiros |
|
|
174
|
+
| `b3.futuro` | Dados históricos de futuros da B3 (DI1, DDI, DAP, DOL, WDO, IND, WIN e outros) |
|
|
175
|
+
| `b3.di1` | Curva DI1 interpolada e datas de negociação disponíveis |
|
|
176
|
+
| `Interpolador` | Interpolação de taxas (flat_forward, linear) |
|
|
176
177
|
| `forward` / `forwards` | Cálculo de taxas a termo |
|
|
177
178
|
| `ltn`, `ntnb`, `ntnf`, `lft`, `ntnc` | Precificação e análise dos títulos públicos principais |
|
|
178
179
|
| `ntnb1`, `ntnbprinc`, `pre` | Títulos e curvas adicionais (NTN-B1, NTN-B Principal, curva PRE) |
|
|
179
|
-
| `tn.
|
|
180
|
+
| `tn.leiloes` / `tn.benchmarks` | Leilões e benchmarks de títulos públicos |
|
|
180
181
|
| `anbima` | Dados da ANBIMA (preços de TPF, curvas de juros, índices IMA) |
|
|
181
182
|
| `bc` | Indicadores do BCB (SELIC, PTAX, repos, VNA, leilões, negociações) |
|
|
182
183
|
| `b3` | Dados da B3 (DI over, price reports, derivativos intradiários) |
|
|
183
184
|
| `ipca` | Dados de inflação (histórico e projeções) |
|
|
184
185
|
| `selic` | Opções digitais de COPOM e probabilidades implícitas |
|
|
185
|
-
| `rmd` | Relatório Mensal da Dívida do Tesouro Nacional |
|
|
186
|
-
| `
|
|
186
|
+
| `tn.rmd` | Relatório Mensal da Dívida do Tesouro Nacional |
|
|
187
|
+
| `hoje` / `agora` | Data/hora atual no Brasil (America/Sao_Paulo) |
|
|
187
188
|
|
|
188
189
|
## Títulos Públicos
|
|
189
190
|
|
|
@@ -191,37 +192,37 @@ forwards(bdays, rates) # -> Series: [0.05, 0.070095, 0.090284]
|
|
|
191
192
|
from pyield import ltn, ntnb, ntnf
|
|
192
193
|
|
|
193
194
|
# Busca taxas indicativas da ANBIMA
|
|
194
|
-
ltn.
|
|
195
|
-
ntnb.
|
|
195
|
+
ltn.dados("23-08-2024") # -> DataFrame com títulos LTN
|
|
196
|
+
ntnb.dados("23-08-2024") # -> DataFrame com títulos NTN-B
|
|
196
197
|
|
|
197
198
|
# Calcula cotação do título (base 100)
|
|
198
|
-
ntnb.
|
|
199
|
-
ntnb.
|
|
199
|
+
ntnb.cotacao("31-05-2024", "15-05-2035", 0.061490) # -> 99.3651
|
|
200
|
+
ntnb.cotacao("31-05-2024", "15-08-2060", 0.061878) # -> 99.5341
|
|
200
201
|
|
|
201
|
-
#
|
|
202
|
-
ntnf.
|
|
203
|
-
# -> DataFrame: titulo, data_vencimento,
|
|
202
|
+
# Prêmio sobre o DI (pontos_base=True multiplica por 10.000)
|
|
203
|
+
ntnf.premio("30-05-2025", pontos_base=True)
|
|
204
|
+
# -> DataFrame: titulo, data_vencimento, premio
|
|
204
205
|
```
|
|
205
206
|
|
|
206
207
|
## Dados de Futuros
|
|
207
208
|
|
|
208
209
|
```python
|
|
209
|
-
|
|
210
|
+
import pyield as yd
|
|
210
211
|
|
|
211
212
|
# DI1 (Futuro de Depósito Interfinanceiro)
|
|
212
|
-
|
|
213
|
+
b3.futuro("31-05-2024", "DI1")
|
|
213
214
|
|
|
214
215
|
# Outros contratos disponíveis no cache histórico:
|
|
215
216
|
# - Juros: DI1, DDI, FRC, FRO, DAP
|
|
216
217
|
# - Moedas: DOL, WDO
|
|
217
218
|
# - Índices: IND, WIN
|
|
218
|
-
|
|
219
|
+
b3.futuro("31-05-2024", "DAP")
|
|
219
220
|
|
|
220
221
|
# Múltiplas datas de uma vez
|
|
221
|
-
|
|
222
|
+
b3.futuro(["29-05-2024", "31-05-2024"], "DI1")
|
|
222
223
|
|
|
223
224
|
# Dados intradiários (quando o mercado estiver aberto)
|
|
224
|
-
|
|
225
|
+
b3.futuro_intradia("DI1") # Retorna dados ao vivo durante o horário de negociação
|
|
225
226
|
```
|
|
226
227
|
|
|
227
228
|
## Tratamento de Datas
|
|
@@ -240,23 +241,40 @@ Tratamento de nulos: funções escalares retornam `float('nan')` para entradas a
|
|
|
240
241
|
(propaga nos cálculos). Funções vetorizadas propagam `null` elemento a elemento.
|
|
241
242
|
|
|
242
243
|
```python
|
|
243
|
-
from pyield import ntnb
|
|
244
|
+
from pyield.tn import ntnb
|
|
245
|
+
from pyield import dus
|
|
244
246
|
|
|
245
|
-
ntnb.
|
|
246
|
-
|
|
247
|
+
ntnb.cotacao(None, "15-05-2035", 0.06149) # -> nan
|
|
248
|
+
dus.contar(["01-01-2024", None], "01-02-2024") # -> Series: [22, null]
|
|
247
249
|
```
|
|
248
250
|
|
|
249
251
|
Consultas sem dados disponíveis (data futura, feriado, fim de semana ou
|
|
250
252
|
fonte indisponível) retornam DataFrame vazio ou `nan`, sem lançar exceção:
|
|
251
253
|
|
|
252
254
|
```python
|
|
253
|
-
from pyield import
|
|
255
|
+
from pyield import b3, bc
|
|
254
256
|
|
|
255
|
-
|
|
256
|
-
bc.
|
|
257
|
-
bc.ptax("25-12-2025")
|
|
257
|
+
b3.futuro("01-01-2030", "DI1").is_empty() # -> True (data futura)
|
|
258
|
+
bc.tpf_mensal("01-01-2030").is_empty() # -> True (mês futuro)
|
|
259
|
+
bc.ptax("25-12-2025") # -> nan (feriado)
|
|
258
260
|
```
|
|
259
261
|
|
|
262
|
+
## Migração para Português (v0.48.0+)
|
|
263
|
+
|
|
264
|
+
A partir da versão 0.48.0, a API pública foi migrada para o português. Os principais renomes:
|
|
265
|
+
|
|
266
|
+
| Antes (< 0.48) | Depois (≥ 0.48) |
|
|
267
|
+
|---|---|
|
|
268
|
+
| `yd.bday` | `yd.dus` |
|
|
269
|
+
| `bday.count()` | `dus.contar()` |
|
|
270
|
+
| `bday.offset()` | `dus.deslocar()` |
|
|
271
|
+
| `bday.generate()` | `dus.gerar()` |
|
|
272
|
+
| `bday.is_business_day()` | `dus.e_dia_util()` |
|
|
273
|
+
| `Interpolator(method, bdays, rates)` | `Interpolador(dias_uteis, taxas, metodo=...)` |
|
|
274
|
+
| `extrapolate=True` | `extrapolar=True` |
|
|
275
|
+
| `ntnb.quotation()` | `ntnb.cotacao()` |
|
|
276
|
+
| `ntnb.data()` | `ntnb.dados()` |
|
|
277
|
+
|
|
260
278
|
## Migração para Polars (v0.40.0+)
|
|
261
279
|
|
|
262
280
|
A partir da versão 0.40.0, todas as saídas tabulares passaram de Pandas para **Polars**. Entradas vetoriais que antes aceitavam `pd.Series` e `np.ndarray` agora aceitam apenas listas, tuplas ou `pl.Series`. Para converter:
|
|
@@ -19,26 +19,27 @@ pip install pyield
|
|
|
19
19
|
## Início Rápido
|
|
20
20
|
|
|
21
21
|
```python
|
|
22
|
-
|
|
22
|
+
from pyield import dus, b3, bc, Interpolador
|
|
23
|
+
from pyield.tn import ntnb
|
|
23
24
|
|
|
24
25
|
# Dias úteis (base de todos os cálculos)
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
dus.contar("02-01-2025", "15-01-2025") # -> 9
|
|
27
|
+
dus.deslocar("29-12-2023", 1) # -> datetime.date(2024, 1, 2)
|
|
27
28
|
|
|
28
29
|
# Curva de DI Futuro
|
|
29
|
-
df =
|
|
30
|
-
#
|
|
30
|
+
df = b3.futuro("31-05-2024", "DI1")
|
|
31
|
+
# Colunas: data_referencia, codigo_negociacao, data_vencimento, dias_uteis, taxa_ajuste, ...
|
|
31
32
|
|
|
32
33
|
# Interpolação de taxas (flat forward, convenção 252 dias úteis/ano)
|
|
33
|
-
interp =
|
|
34
|
+
interp = Interpolador(df["dias_uteis"], df["taxa_ajuste"], metodo="flat_forward")
|
|
34
35
|
interp(45) # -> 0.04833...
|
|
35
|
-
interp([30, 60]) # ->
|
|
36
|
+
interp([30, 60]) # -> Series do Polars com taxas interpoladas
|
|
36
37
|
|
|
37
38
|
# Precificação de títulos públicos
|
|
38
|
-
|
|
39
|
+
ntnb.cotacao("31-05-2024", "15-05-2035", 0.061490) # -> 99.3651
|
|
39
40
|
|
|
40
41
|
# Indicadores do BCB
|
|
41
|
-
|
|
42
|
+
bc.selic_over("31-05-2024") # -> 0.000414...
|
|
42
43
|
```
|
|
43
44
|
|
|
44
45
|
Um notebook no Colab com mais exemplos:
|
|
@@ -47,56 +48,56 @@ Um notebook no Colab com mais exemplos:
|
|
|
47
48
|
|
|
48
49
|
## Blocos Principais
|
|
49
50
|
|
|
50
|
-
### Dias Úteis (`
|
|
51
|
+
### Dias Úteis (`dus`)
|
|
51
52
|
|
|
52
|
-
O módulo `
|
|
53
|
+
O módulo `dus` é 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.
|
|
53
54
|
|
|
54
55
|
```python
|
|
55
|
-
from pyield import
|
|
56
|
+
from pyield import dus
|
|
56
57
|
|
|
57
58
|
# Conta dias úteis (início inclusivo, fim exclusivo)
|
|
58
|
-
|
|
59
|
+
dus.contar("29-12-2023", "02-01-2024") # -> 1
|
|
59
60
|
|
|
60
61
|
# Avança N dias úteis
|
|
61
|
-
|
|
62
|
+
dus.deslocar("29-12-2023", 1) # -> datetime.date(2024, 1, 2)
|
|
62
63
|
|
|
63
64
|
# Ajusta dia não útil para o próximo dia útil
|
|
64
|
-
|
|
65
|
+
dus.deslocar("30-12-2023", 0) # -> datetime.date(2024, 1, 2)
|
|
65
66
|
|
|
66
67
|
# Gera intervalo de dias úteis
|
|
67
|
-
|
|
68
|
+
dus.gerar("22-12-2023", "02-01-2024")
|
|
68
69
|
# -> Series: [2023-12-22, 2023-12-26, 2023-12-27, 2023-12-28, 2023-12-29, 2024-01-02]
|
|
69
70
|
|
|
70
71
|
# Verifica se a data é dia útil
|
|
71
|
-
|
|
72
|
+
dus.e_dia_util("25-12-2023") # -> False (Natal)
|
|
72
73
|
```
|
|
73
74
|
|
|
74
75
|
Todas as funções suportam operações vetorizadas com listas, Series ou arrays.
|
|
75
76
|
|
|
76
|
-
### Interpolação de Taxas (`
|
|
77
|
+
### Interpolação de Taxas (`Interpolador`)
|
|
77
78
|
|
|
78
|
-
A classe `
|
|
79
|
+
A classe `Interpolador` interpola taxas usando a convenção de 252 dias úteis/ano, padrão no mercado brasileiro.
|
|
79
80
|
|
|
80
81
|
```python
|
|
81
|
-
from pyield import
|
|
82
|
+
from pyield import Interpolador
|
|
82
83
|
|
|
83
|
-
|
|
84
|
-
|
|
84
|
+
dias_uteis = [30, 60, 90]
|
|
85
|
+
taxas = [0.045, 0.05, 0.055]
|
|
85
86
|
|
|
86
87
|
# Interpolação flat forward (padrão de mercado)
|
|
87
|
-
interp =
|
|
88
|
+
interp = Interpolador(dias_uteis, taxas, metodo="flat_forward")
|
|
88
89
|
interp(45) # -> 0.04833...
|
|
89
90
|
|
|
90
91
|
# Interpolação linear
|
|
91
|
-
linear =
|
|
92
|
+
linear = Interpolador(dias_uteis, taxas, metodo="linear")
|
|
92
93
|
linear(45) # -> 0.0475
|
|
93
94
|
|
|
94
95
|
# Vetorizado
|
|
95
|
-
interp([15, 45, 75]) # -> pl.Series
|
|
96
|
+
interp([15, 45, 75]) # -> pl.Series com 3 taxas
|
|
96
97
|
|
|
97
98
|
# Extrapolação (desabilitada por padrão, retorna NaN)
|
|
98
99
|
interp(100) # -> nan
|
|
99
|
-
|
|
100
|
+
Interpolador(dias_uteis, taxas, metodo="flat_forward", extrapolar=True)(100) # -> 0.055
|
|
100
101
|
```
|
|
101
102
|
|
|
102
103
|
### Taxas a Termo (`forward`, `forwards`)
|
|
@@ -113,33 +114,33 @@ Convenção utilizada:
|
|
|
113
114
|
from pyield import forward, forwards
|
|
114
115
|
|
|
115
116
|
# Taxa a termo única entre dois pontos
|
|
116
|
-
forward(
|
|
117
|
+
forward(10, 20, 0.05, 0.06) # -> 0.0700952...
|
|
117
118
|
|
|
118
119
|
# Curva a termo vetorizada a partir de taxas spot
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
forwards(
|
|
120
|
+
dias_uteis = [10, 20, 30]
|
|
121
|
+
taxas = [0.05, 0.06, 0.07]
|
|
122
|
+
forwards(dias_uteis, taxas) # -> Series: [0.05, 0.070095, 0.090284]
|
|
122
123
|
```
|
|
123
124
|
|
|
124
125
|
## Visão Geral dos Módulos
|
|
125
126
|
|
|
126
127
|
| Módulo | Finalidade |
|
|
127
128
|
|--------|---------|
|
|
128
|
-
| `
|
|
129
|
-
| `
|
|
130
|
-
| `di1` | Curva DI1 interpolada e datas de negociação disponíveis |
|
|
131
|
-
| `
|
|
129
|
+
| `dus` | Calendário de dias úteis com feriados brasileiros |
|
|
130
|
+
| `b3.futuro` | Dados históricos de futuros da B3 (DI1, DDI, DAP, DOL, WDO, IND, WIN e outros) |
|
|
131
|
+
| `b3.di1` | Curva DI1 interpolada e datas de negociação disponíveis |
|
|
132
|
+
| `Interpolador` | Interpolação de taxas (flat_forward, linear) |
|
|
132
133
|
| `forward` / `forwards` | Cálculo de taxas a termo |
|
|
133
134
|
| `ltn`, `ntnb`, `ntnf`, `lft`, `ntnc` | Precificação e análise dos títulos públicos principais |
|
|
134
135
|
| `ntnb1`, `ntnbprinc`, `pre` | Títulos e curvas adicionais (NTN-B1, NTN-B Principal, curva PRE) |
|
|
135
|
-
| `tn.
|
|
136
|
+
| `tn.leiloes` / `tn.benchmarks` | Leilões e benchmarks de títulos públicos |
|
|
136
137
|
| `anbima` | Dados da ANBIMA (preços de TPF, curvas de juros, índices IMA) |
|
|
137
138
|
| `bc` | Indicadores do BCB (SELIC, PTAX, repos, VNA, leilões, negociações) |
|
|
138
139
|
| `b3` | Dados da B3 (DI over, price reports, derivativos intradiários) |
|
|
139
140
|
| `ipca` | Dados de inflação (histórico e projeções) |
|
|
140
141
|
| `selic` | Opções digitais de COPOM e probabilidades implícitas |
|
|
141
|
-
| `rmd` | Relatório Mensal da Dívida do Tesouro Nacional |
|
|
142
|
-
| `
|
|
142
|
+
| `tn.rmd` | Relatório Mensal da Dívida do Tesouro Nacional |
|
|
143
|
+
| `hoje` / `agora` | Data/hora atual no Brasil (America/Sao_Paulo) |
|
|
143
144
|
|
|
144
145
|
## Títulos Públicos
|
|
145
146
|
|
|
@@ -147,37 +148,37 @@ forwards(bdays, rates) # -> Series: [0.05, 0.070095, 0.090284]
|
|
|
147
148
|
from pyield import ltn, ntnb, ntnf
|
|
148
149
|
|
|
149
150
|
# Busca taxas indicativas da ANBIMA
|
|
150
|
-
ltn.
|
|
151
|
-
ntnb.
|
|
151
|
+
ltn.dados("23-08-2024") # -> DataFrame com títulos LTN
|
|
152
|
+
ntnb.dados("23-08-2024") # -> DataFrame com títulos NTN-B
|
|
152
153
|
|
|
153
154
|
# Calcula cotação do título (base 100)
|
|
154
|
-
ntnb.
|
|
155
|
-
ntnb.
|
|
155
|
+
ntnb.cotacao("31-05-2024", "15-05-2035", 0.061490) # -> 99.3651
|
|
156
|
+
ntnb.cotacao("31-05-2024", "15-08-2060", 0.061878) # -> 99.5341
|
|
156
157
|
|
|
157
|
-
#
|
|
158
|
-
ntnf.
|
|
159
|
-
# -> DataFrame: titulo, data_vencimento,
|
|
158
|
+
# Prêmio sobre o DI (pontos_base=True multiplica por 10.000)
|
|
159
|
+
ntnf.premio("30-05-2025", pontos_base=True)
|
|
160
|
+
# -> DataFrame: titulo, data_vencimento, premio
|
|
160
161
|
```
|
|
161
162
|
|
|
162
163
|
## Dados de Futuros
|
|
163
164
|
|
|
164
165
|
```python
|
|
165
|
-
|
|
166
|
+
import pyield as yd
|
|
166
167
|
|
|
167
168
|
# DI1 (Futuro de Depósito Interfinanceiro)
|
|
168
|
-
|
|
169
|
+
b3.futuro("31-05-2024", "DI1")
|
|
169
170
|
|
|
170
171
|
# Outros contratos disponíveis no cache histórico:
|
|
171
172
|
# - Juros: DI1, DDI, FRC, FRO, DAP
|
|
172
173
|
# - Moedas: DOL, WDO
|
|
173
174
|
# - Índices: IND, WIN
|
|
174
|
-
|
|
175
|
+
b3.futuro("31-05-2024", "DAP")
|
|
175
176
|
|
|
176
177
|
# Múltiplas datas de uma vez
|
|
177
|
-
|
|
178
|
+
b3.futuro(["29-05-2024", "31-05-2024"], "DI1")
|
|
178
179
|
|
|
179
180
|
# Dados intradiários (quando o mercado estiver aberto)
|
|
180
|
-
|
|
181
|
+
b3.futuro_intradia("DI1") # Retorna dados ao vivo durante o horário de negociação
|
|
181
182
|
```
|
|
182
183
|
|
|
183
184
|
## Tratamento de Datas
|
|
@@ -196,23 +197,40 @@ Tratamento de nulos: funções escalares retornam `float('nan')` para entradas a
|
|
|
196
197
|
(propaga nos cálculos). Funções vetorizadas propagam `null` elemento a elemento.
|
|
197
198
|
|
|
198
199
|
```python
|
|
199
|
-
from pyield import ntnb
|
|
200
|
+
from pyield.tn import ntnb
|
|
201
|
+
from pyield import dus
|
|
200
202
|
|
|
201
|
-
ntnb.
|
|
202
|
-
|
|
203
|
+
ntnb.cotacao(None, "15-05-2035", 0.06149) # -> nan
|
|
204
|
+
dus.contar(["01-01-2024", None], "01-02-2024") # -> Series: [22, null]
|
|
203
205
|
```
|
|
204
206
|
|
|
205
207
|
Consultas sem dados disponíveis (data futura, feriado, fim de semana ou
|
|
206
208
|
fonte indisponível) retornam DataFrame vazio ou `nan`, sem lançar exceção:
|
|
207
209
|
|
|
208
210
|
```python
|
|
209
|
-
from pyield import
|
|
211
|
+
from pyield import b3, bc
|
|
210
212
|
|
|
211
|
-
|
|
212
|
-
bc.
|
|
213
|
-
bc.ptax("25-12-2025")
|
|
213
|
+
b3.futuro("01-01-2030", "DI1").is_empty() # -> True (data futura)
|
|
214
|
+
bc.tpf_mensal("01-01-2030").is_empty() # -> True (mês futuro)
|
|
215
|
+
bc.ptax("25-12-2025") # -> nan (feriado)
|
|
214
216
|
```
|
|
215
217
|
|
|
218
|
+
## Migração para Português (v0.48.0+)
|
|
219
|
+
|
|
220
|
+
A partir da versão 0.48.0, a API pública foi migrada para o português. Os principais renomes:
|
|
221
|
+
|
|
222
|
+
| Antes (< 0.48) | Depois (≥ 0.48) |
|
|
223
|
+
|---|---|
|
|
224
|
+
| `yd.bday` | `yd.dus` |
|
|
225
|
+
| `bday.count()` | `dus.contar()` |
|
|
226
|
+
| `bday.offset()` | `dus.deslocar()` |
|
|
227
|
+
| `bday.generate()` | `dus.gerar()` |
|
|
228
|
+
| `bday.is_business_day()` | `dus.e_dia_util()` |
|
|
229
|
+
| `Interpolator(method, bdays, rates)` | `Interpolador(dias_uteis, taxas, metodo=...)` |
|
|
230
|
+
| `extrapolate=True` | `extrapolar=True` |
|
|
231
|
+
| `ntnb.quotation()` | `ntnb.cotacao()` |
|
|
232
|
+
| `ntnb.data()` | `ntnb.dados()` |
|
|
233
|
+
|
|
216
234
|
## Migração para Polars (v0.40.0+)
|
|
217
235
|
|
|
218
236
|
A partir da versão 0.40.0, todas as saídas tabulares passaram de Pandas para **Polars**. Entradas vetoriais que antes aceitavam `pd.Series` e `np.ndarray` agora aceitam apenas listas, tuplas ou `pl.Series`. Para converter:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.48.0"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
from pyield import anbima, b3, bc, dus, ipca, relogio, selic, tn
|
|
4
|
+
from pyield.__about__ import __version__
|
|
5
|
+
from pyield.fwd import forward, forwards
|
|
6
|
+
from pyield.interpolador import Interpolador
|
|
7
|
+
from pyield.relogio import agora, hoje
|
|
8
|
+
from pyield.selic.cpm import data as copom_options
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"Interpolador",
|
|
12
|
+
"__version__",
|
|
13
|
+
"anbima",
|
|
14
|
+
"b3",
|
|
15
|
+
"bc",
|
|
16
|
+
"copom_options",
|
|
17
|
+
"dus",
|
|
18
|
+
"forward",
|
|
19
|
+
"forwards",
|
|
20
|
+
"agora",
|
|
21
|
+
"ipca",
|
|
22
|
+
"relogio",
|
|
23
|
+
"selic",
|
|
24
|
+
"tn",
|
|
25
|
+
"hoje",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
# Configura o logger do pacote principal com um NullHandler
|
|
29
|
+
logging.getLogger(__name__).addHandler(logging.NullHandler())
|
|
@@ -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 dus, relogio # noqa: PLC0415
|
|
15
15
|
|
|
16
|
-
return
|
|
16
|
+
return dus.e_dia_util(date) and date <= relogio.hoje()
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
def converter_datas_expr(expr: pl.Expr | str) -> pl.Expr:
|
|
@@ -7,7 +7,7 @@ import polars as pl
|
|
|
7
7
|
import requests
|
|
8
8
|
|
|
9
9
|
from pyield._internal.retry import retry_padrao
|
|
10
|
-
from pyield.
|
|
10
|
+
from pyield.relogio import agora
|
|
11
11
|
|
|
12
12
|
URL_BASE = "https://github.com/crdcj/pyield-data/releases/latest/download"
|
|
13
13
|
registro = logging.getLogger(__name__)
|
|
@@ -16,7 +16,7 @@ registro = logging.getLogger(__name__)
|
|
|
16
16
|
# Estrutura interna única — usuário não vê isso
|
|
17
17
|
class _Dataset(Enum):
|
|
18
18
|
TPF = ("anbima_tpf.parquet", "data_referencia", "TPF (ANBIMA)")
|
|
19
|
-
|
|
19
|
+
FUTURO = ("b3_futures.parquet", "data_referencia", "Futuro (B3)")
|
|
20
20
|
|
|
21
21
|
def __init__(self, nome_arquivo: str, coluna_data: str, descricao: str):
|
|
22
22
|
self.nome_arquivo = nome_arquivo
|
|
@@ -24,11 +24,11 @@ class _Dataset(Enum):
|
|
|
24
24
|
self.descricao = descricao
|
|
25
25
|
|
|
26
26
|
|
|
27
|
-
type IdDataset = Literal["tpf", "
|
|
27
|
+
type IdDataset = Literal["tpf", "futuro"]
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
def _obter_chave_data_hoje() -> str:
|
|
31
|
-
return
|
|
31
|
+
return agora().strftime("%Y-%m-%d")
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
def _validar_id_dataset(id_dataset: str) -> _Dataset:
|
|
@@ -36,7 +36,7 @@ def _validar_id_dataset(id_dataset: str) -> _Dataset:
|
|
|
36
36
|
try:
|
|
37
37
|
return _Dataset[dataset_normalizado.upper()]
|
|
38
38
|
except KeyError as e:
|
|
39
|
-
msg = f"id_dataset inválido: '{id_dataset}'. Valores aceitos: 'tpf', '
|
|
39
|
+
msg = f"id_dataset inválido: '{id_dataset}'. Valores aceitos: 'tpf', 'futuro'."
|
|
40
40
|
raise ValueError(msg) from e
|
|
41
41
|
|
|
42
42
|
|
|
@@ -77,7 +77,7 @@ def obter_dataset_cacheado(id_dataset: IdDataset) -> pl.DataFrame:
|
|
|
77
77
|
Obtém um dataset pelo ID. Cache expira diariamente.
|
|
78
78
|
|
|
79
79
|
Args:
|
|
80
|
-
id_dataset: "tpf" ou "
|
|
80
|
+
id_dataset: "tpf" ou "futuro"
|
|
81
81
|
"""
|
|
82
82
|
df = _obter_dataset_com_ttl(id_dataset.lower(), _obter_chave_data_hoje())
|
|
83
83
|
return df.clone()
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from pyield.anbima.ettj_intradia import ettj_intradia
|
|
2
|
+
from pyield.anbima.ettj_ultima import ettj_ultima
|
|
3
|
+
from pyield.anbima.ima_ultimo import ima_ultimo
|
|
4
|
+
from pyield.anbima.imaq import imaq
|
|
5
|
+
from pyield.anbima.tpf import tpf, tpf_fonte, tpf_vencimentos
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"ima_ultimo",
|
|
9
|
+
"imaq",
|
|
10
|
+
"tpf",
|
|
11
|
+
"tpf_vencimentos",
|
|
12
|
+
"tpf_fonte",
|
|
13
|
+
"ettj_ultima",
|
|
14
|
+
"ettj_intradia",
|
|
15
|
+
]
|