pyield 0.46.8__tar.gz → 0.47.1__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.46.8 → pyield-0.47.1}/PKG-INFO +1 -1
- pyield-0.47.1/pyield/__about__.py +1 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/__init__.py +9 -10
- {pyield-0.46.8 → pyield-0.47.1}/pyield/_internal/data_cache.py +2 -6
- pyield-0.47.1/pyield/b3/__init__.py +27 -0
- pyield-0.46.8/pyield/b3/intraday_derivatives.py → pyield-0.47.1/pyield/b3/derivatives_intraday.py +6 -8
- {pyield-0.46.8 → pyield-0.47.1}/pyield/b3/di1.py +3 -3
- pyield-0.47.1/pyield/b3/futures/__init__.py +153 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/b3/futures/common.py +4 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/b3/futures/historical.py +140 -188
- pyield-0.47.1/pyield/b3/futures/intraday.py +112 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/b3/price_report.py +70 -49
- {pyield-0.46.8 → pyield-0.47.1}/pyield/selic/cpm.py +2 -2
- pyield-0.46.8/pyield/__about__.py +0 -1
- pyield-0.46.8/pyield/b3/__init__.py +0 -14
- pyield-0.46.8/pyield/b3/futures/__init__.py +0 -185
- pyield-0.46.8/pyield/b3/futures/intraday.py +0 -160
- {pyield-0.46.8 → pyield-0.47.1}/.gitignore +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/LICENSE +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/README.md +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/_internal/__init__.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/_internal/br_numbers.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/_internal/cache.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/_internal/converters.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/_internal/retry.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/_internal/types.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/anbima/__init__.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/anbima/ettj_intraday.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/anbima/ettj_last.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/anbima/ima.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/anbima/imaq.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/anbima/tpf.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/b3/_contracts.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/b3/_validar_pregao.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/b3/di_over.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/bc/__init__.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/bc/auction.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/bc/copom.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/bc/ptax_api.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/bc/rates.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/bc/repo.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/bc/trades_intraday.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/bc/trades_monthly.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/bc/vna.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/bday/__init__.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/bday/core.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/bday/holidays/br_holidays_new.txt +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/bday/holidays/br_holidays_old.txt +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/bday/holidays/brholidays.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/clock.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/fwd.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/interpolator.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/ipca/__init__.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/ipca/historical.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/ipca/projected.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/py.typed +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/rmd.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/selic/__init__.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/selic/probabilities.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/tn/__init__.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/tn/auctions.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/tn/benchmark.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/tn/lft.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/tn/ltn.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/tn/ntnb.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/tn/ntnb1.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/tn/ntnbprinc.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/tn/ntnc.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/tn/ntnf.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/tn/pre.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyield/tn/utils.py +0 -0
- {pyield-0.46.8 → pyield-0.47.1}/pyproject.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyield
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.47.1
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.47.1"
|
|
@@ -11,32 +11,31 @@ from pyield.selic.cpm import data as copom_options
|
|
|
11
11
|
from pyield.tn import lft, ltn, ntnb, ntnb1, ntnbprinc, ntnc, ntnf, pre
|
|
12
12
|
|
|
13
13
|
__all__ = [
|
|
14
|
+
"Interpolator",
|
|
14
15
|
"__version__",
|
|
15
16
|
"anbima",
|
|
16
|
-
"bc",
|
|
17
17
|
"b3",
|
|
18
|
-
"
|
|
19
|
-
"tn",
|
|
18
|
+
"bc",
|
|
20
19
|
"bday",
|
|
20
|
+
"copom_options",
|
|
21
21
|
"di1",
|
|
22
|
-
"forwards",
|
|
23
22
|
"forward",
|
|
23
|
+
"forwards",
|
|
24
24
|
"futures",
|
|
25
|
-
"copom_options",
|
|
26
|
-
"Interpolator",
|
|
27
|
-
"today",
|
|
28
|
-
"now",
|
|
29
25
|
"lft",
|
|
30
26
|
"ltn",
|
|
27
|
+
"now",
|
|
31
28
|
"ntnb",
|
|
32
|
-
"ntnbprinc",
|
|
33
29
|
"ntnb1",
|
|
30
|
+
"ntnbprinc",
|
|
34
31
|
"ntnc",
|
|
35
32
|
"ntnf",
|
|
33
|
+
"ipca",
|
|
36
34
|
"pre",
|
|
37
35
|
"rmd",
|
|
38
|
-
"bday",
|
|
39
36
|
"selic",
|
|
37
|
+
"tn",
|
|
38
|
+
"today",
|
|
40
39
|
]
|
|
41
40
|
|
|
42
41
|
# Configura o logger do pacote principal com um NullHandler
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import functools
|
|
2
|
-
import io
|
|
3
2
|
import logging
|
|
4
3
|
from enum import Enum
|
|
5
4
|
from typing import Literal
|
|
@@ -55,11 +54,8 @@ def _carregar_arquivo_github(url_arquivo: str) -> pl.DataFrame:
|
|
|
55
54
|
# Garante que a requisição foi sucesso (200 OK), senão levanta erro
|
|
56
55
|
response.raise_for_status()
|
|
57
56
|
|
|
58
|
-
# 2.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
# 3. O Polars lê o buffer como se fosse um arquivo local
|
|
62
|
-
return pl.read_parquet(file_buffer)
|
|
57
|
+
# 2. O Polars lê o buffer como se fosse um arquivo local
|
|
58
|
+
return pl.read_parquet(response.content)
|
|
63
59
|
|
|
64
60
|
|
|
65
61
|
@functools.lru_cache(maxsize=8)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from pyield.b3 import di1
|
|
2
|
+
from pyield.b3.derivatives_intraday import derivatives_intraday_fetch
|
|
3
|
+
from pyield.b3.di_over import di_over
|
|
4
|
+
from pyield.b3.futures import (
|
|
5
|
+
futures,
|
|
6
|
+
futures_available_dates,
|
|
7
|
+
futures_enrich,
|
|
8
|
+
futures_intraday,
|
|
9
|
+
)
|
|
10
|
+
from pyield.b3.price_report import (
|
|
11
|
+
price_report_extract,
|
|
12
|
+
price_report_fetch,
|
|
13
|
+
price_report_read,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"di_over",
|
|
18
|
+
"di1",
|
|
19
|
+
"futures",
|
|
20
|
+
"futures_available_dates",
|
|
21
|
+
"futures_enrich",
|
|
22
|
+
"futures_intraday",
|
|
23
|
+
"derivatives_intraday_fetch",
|
|
24
|
+
"price_report_extract",
|
|
25
|
+
"price_report_fetch",
|
|
26
|
+
"price_report_read",
|
|
27
|
+
]
|
pyield-0.46.8/pyield/b3/intraday_derivatives.py → pyield-0.47.1/pyield/b3/derivatives_intraday.py
RENAMED
|
@@ -111,7 +111,7 @@ def _processar_colunas_intraday(df: pl.DataFrame) -> pl.DataFrame:
|
|
|
111
111
|
)
|
|
112
112
|
|
|
113
113
|
|
|
114
|
-
def
|
|
114
|
+
def derivatives_intraday_fetch(contract_code: str) -> pl.DataFrame:
|
|
115
115
|
"""Busca cotações intraday brutas de derivativos da B3.
|
|
116
116
|
|
|
117
117
|
Faz a chamada ao endpoint ``DerivativeQuotation`` e devolve um DataFrame
|
|
@@ -160,11 +160,9 @@ def fetch_intraday_derivatives(contract_code: str) -> pl.DataFrame:
|
|
|
160
160
|
if not dados_json:
|
|
161
161
|
return pl.DataFrame()
|
|
162
162
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
.
|
|
167
|
-
atualizado_as=clock.now() - dt.timedelta(minutes=15),
|
|
168
|
-
)
|
|
169
|
-
.sort("codigo_negociacao")
|
|
163
|
+
df = _converter_json_intraday(dados_json)
|
|
164
|
+
df = _processar_colunas_intraday(df)
|
|
165
|
+
df = df.with_columns(
|
|
166
|
+
atualizado_as=clock.now() - dt.timedelta(minutes=15),
|
|
170
167
|
)
|
|
168
|
+
return df.sort("codigo_negociacao")
|
|
@@ -4,7 +4,7 @@ import pyield._internal.converters as cv
|
|
|
4
4
|
from pyield import b3, bday, interpolator
|
|
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
|
-
from pyield.b3.futures import
|
|
7
|
+
from pyield.b3.futures import futures_available_dates as _listar_datas
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
def data(
|
|
@@ -62,7 +62,7 @@ def data(
|
|
|
62
62
|
else:
|
|
63
63
|
datas_lista = [datas_convertidas]
|
|
64
64
|
|
|
65
|
-
df = b3.futures(date=datas_lista, contract_code="DI1"
|
|
65
|
+
df = b3.futures(date=datas_lista, contract_code="DI1")
|
|
66
66
|
if df.is_empty():
|
|
67
67
|
return df
|
|
68
68
|
|
|
@@ -195,7 +195,7 @@ def interpolate_rates(
|
|
|
195
195
|
|
|
196
196
|
# Carrega dataset de taxas DI usando datas já convertidas do df_entrada
|
|
197
197
|
datas_unicas = df_entrada["data_referencia"].drop_nulls().unique().sort().to_list()
|
|
198
|
-
df_ref = b3.futures(date=datas_unicas, contract_code="DI1"
|
|
198
|
+
df_ref = b3.futures(date=datas_unicas, contract_code="DI1")
|
|
199
199
|
# Retorna Series vazia se nenhuma taxa for encontrada
|
|
200
200
|
if df_ref.is_empty():
|
|
201
201
|
return pl.Series(dtype=pl.Float64)
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import polars as pl
|
|
2
|
+
|
|
3
|
+
import pyield._internal.converters as cv
|
|
4
|
+
from pyield._internal.types import ArrayLike, DateLike, any_is_empty
|
|
5
|
+
from pyield.b3._validar_pregao import data_negociacao_valida
|
|
6
|
+
from pyield.b3.futures import historical, intraday
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def futures_enrich(
|
|
10
|
+
df: pl.DataFrame,
|
|
11
|
+
contract_code: str,
|
|
12
|
+
) -> pl.DataFrame:
|
|
13
|
+
"""Enriquece DataFrame bruto do Price Report (PR) da B3.
|
|
14
|
+
|
|
15
|
+
Aceita um DataFrame com colunas no schema original da B3
|
|
16
|
+
(ex.: ``TradDt``, ``TckrSymb``) ou já renomeadas para o padrão
|
|
17
|
+
PYield. Adiciona data de vencimento, dias úteis/corridos e
|
|
18
|
+
colunas derivadas (dv01, taxa_forward) conforme o contrato.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
df: DataFrame com dados do PR da B3.
|
|
22
|
+
contract_code: Código do contrato futuro
|
|
23
|
+
(ex.: "DI1", "DOL").
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
DataFrame Polars enriquecido e ordenado.
|
|
27
|
+
"""
|
|
28
|
+
return historical.enrich(df, contract_code)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def futures(
|
|
32
|
+
date: DateLike | ArrayLike,
|
|
33
|
+
contract_code: str,
|
|
34
|
+
) -> pl.DataFrame:
|
|
35
|
+
"""Busca dados de um contrato futuro da B3 para a data de referência.
|
|
36
|
+
|
|
37
|
+
Dados obtidos do dataset PR cacheado no GitHub (disponível desde 2018).
|
|
38
|
+
Para dados do pregão corrente, use ``futures_intraday``.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
date: Data de referência para consulta ou coleção de datas.
|
|
42
|
+
Quando uma coleção é fornecida, os dados são buscados para cada
|
|
43
|
+
data individualmente e concatenados. Datas inválidas (feriados,
|
|
44
|
+
fins de semana, futuras) são silenciosamente ignoradas.
|
|
45
|
+
contract_code: Código do contrato futuro na B3. Contratos
|
|
46
|
+
disponíveis no cache histórico:
|
|
47
|
+
- Juros: DI1, DDI, FRC, FRO, DAP
|
|
48
|
+
- Moedas: DOL, WDO
|
|
49
|
+
- Índices: IND, WIN
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
DataFrame Polars com os dados do contrato informado.
|
|
53
|
+
|
|
54
|
+
Examples:
|
|
55
|
+
>>> df = futures("31-05-2024", "DI1")
|
|
56
|
+
>>> df = futures("31-05-2024", "DAP")
|
|
57
|
+
|
|
58
|
+
Lista de datas:
|
|
59
|
+
|
|
60
|
+
>>> df = futures(["29-05-2024", "31-05-2024"], "DI1")
|
|
61
|
+
>>> df["data_referencia"].unique().sort().to_list()
|
|
62
|
+
[datetime.date(2024, 5, 29), datetime.date(2024, 5, 31)]
|
|
63
|
+
|
|
64
|
+
Véspera de Natal e Ano Novo não têm pregão:
|
|
65
|
+
|
|
66
|
+
>>> futures("24-12-2024", "DI1").is_empty()
|
|
67
|
+
True
|
|
68
|
+
>>> futures("31-12-2024", "DI1").is_empty()
|
|
69
|
+
True
|
|
70
|
+
|
|
71
|
+
Data futura e fim de semana retornam DataFrame vazio:
|
|
72
|
+
|
|
73
|
+
>>> import datetime as dt
|
|
74
|
+
>>> amanha = dt.date.today() + dt.timedelta(days=1)
|
|
75
|
+
>>> futures(amanha, "DI1").is_empty()
|
|
76
|
+
True
|
|
77
|
+
>>> futures("04-01-2025", "DI1").is_empty() # sábado
|
|
78
|
+
True
|
|
79
|
+
|
|
80
|
+
"""
|
|
81
|
+
if any_is_empty(date, contract_code):
|
|
82
|
+
return pl.DataFrame()
|
|
83
|
+
|
|
84
|
+
dados_convertidos = cv.converter_datas(date)
|
|
85
|
+
if isinstance(dados_convertidos, pl.Series):
|
|
86
|
+
datas_validas = []
|
|
87
|
+
for d in dados_convertidos:
|
|
88
|
+
if d is not None and data_negociacao_valida(d):
|
|
89
|
+
datas_validas.append(d)
|
|
90
|
+
return historical._buscar_do_cache(datas_validas, contract_code)
|
|
91
|
+
|
|
92
|
+
if not data_negociacao_valida(dados_convertidos):
|
|
93
|
+
return pl.DataFrame()
|
|
94
|
+
|
|
95
|
+
return historical.historical(dados_convertidos, contract_code)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def futures_intraday(
|
|
99
|
+
contract_code: str,
|
|
100
|
+
) -> pl.DataFrame:
|
|
101
|
+
"""Busca dados intraday de contratos futuros da B3.
|
|
102
|
+
|
|
103
|
+
Retorna os dados mais recentes do pregão corrente, com atraso
|
|
104
|
+
aproximado de 15 minutos. Para dados históricos consolidados,
|
|
105
|
+
use ``futures``.
|
|
106
|
+
|
|
107
|
+
Args:
|
|
108
|
+
contract_code: Código do contrato futuro na B3
|
|
109
|
+
(ex.: 'DI1', 'DAP', 'DOL').
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
DataFrame Polars com dados intraday. Retorna DataFrame vazio
|
|
113
|
+
fora do horário de pregão.
|
|
114
|
+
|
|
115
|
+
Notes:
|
|
116
|
+
As colunas com prefixo ``preco_`` aparecem para contratos cotados
|
|
117
|
+
por preço (ex.: DOL, IND). As com prefixo ``taxa_`` aparecem para
|
|
118
|
+
contratos cotados por taxa (ex.: DI1, DAP, DDI, FRC, FRO).
|
|
119
|
+
"""
|
|
120
|
+
if not contract_code:
|
|
121
|
+
return pl.DataFrame()
|
|
122
|
+
|
|
123
|
+
return intraday.intraday(contract_code)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def futures_available_dates(contract_code: str) -> pl.Series:
|
|
127
|
+
"""Retorna as datas de negociação disponíveis no dataset cacheado.
|
|
128
|
+
|
|
129
|
+
Args:
|
|
130
|
+
contract_code: Código do contrato futuro na B3 (ex.: DI1, DOL).
|
|
131
|
+
|
|
132
|
+
Returns:
|
|
133
|
+
Series ordenada de datas (Date) para as quais há dados de ajuste.
|
|
134
|
+
|
|
135
|
+
Examples:
|
|
136
|
+
>>> from pyield.b3.futures import futures_available_dates
|
|
137
|
+
>>> futures_available_dates("DI1").head(3)
|
|
138
|
+
shape: (3,)
|
|
139
|
+
Series: 'data_referencia' [date]
|
|
140
|
+
[
|
|
141
|
+
2018-01-02
|
|
142
|
+
2018-01-03
|
|
143
|
+
2018-01-04
|
|
144
|
+
]
|
|
145
|
+
"""
|
|
146
|
+
return historical.listar_datas_disponiveis(contract_code)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
__all__ = [
|
|
150
|
+
"futures",
|
|
151
|
+
"futures_available_dates",
|
|
152
|
+
"futures_intraday",
|
|
153
|
+
]
|
|
@@ -2,6 +2,10 @@ import polars as pl
|
|
|
2
2
|
|
|
3
3
|
from pyield import bday
|
|
4
4
|
|
|
5
|
+
# Lista de contratos que negociam por taxa (juros/cupom).
|
|
6
|
+
# Nestes contratos, as colunas OHLC são taxas e precisam ser divididas por 100.
|
|
7
|
+
CONTRATOS_TAXA = {"DI1", "DAP", "DDI", "FRC", "FRO"}
|
|
8
|
+
|
|
5
9
|
_MAPA_MESES: dict[str, int] = {
|
|
6
10
|
"F": 1,
|
|
7
11
|
"G": 2,
|