PYield 0.26.7__tar.gz → 0.27.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.26.7 → pyield-0.27.0}/PKG-INFO +1 -1
- pyield-0.27.0/pyield/__about__.py +1 -0
- {pyield-0.26.7 → pyield-0.27.0}/pyield/__init__.py +8 -3
- {pyield-0.26.7/pyield → pyield-0.27.0/pyield/anbima}/ima.py +5 -4
- pyield-0.27.0/pyield/anbima/imaq.py +142 -0
- pyield-0.26.7/pyield/anbima.py → pyield-0.27.0/pyield/anbima/tpf.py +61 -10
- pyield-0.27.0/pyield/b3_futures/__init__.py +74 -0
- {pyield-0.26.7 → pyield-0.27.0}/pyield/tpf/lft.py +3 -2
- {pyield-0.26.7 → pyield-0.27.0}/pyield/tpf/ltn.py +3 -2
- {pyield-0.26.7 → pyield-0.27.0}/pyield/tpf/ntnb.py +3 -2
- {pyield-0.26.7 → pyield-0.27.0}/pyield/tpf/ntnf.py +4 -3
- {pyield-0.26.7 → pyield-0.27.0}/pyield/tpf/tools.py +3 -3
- pyield-0.26.7/pyield/__about__.py +0 -1
- {pyield-0.26.7 → pyield-0.27.0}/.gitignore +0 -0
- {pyield-0.26.7 → pyield-0.27.0}/LICENSE +0 -0
- {pyield-0.26.7 → pyield-0.27.0}/README.md +0 -0
- {pyield-0.26.7/pyield/b3_futures → pyield-0.27.0/pyield/anbima}/__init__.py +0 -0
- {pyield-0.26.7 → pyield-0.27.0}/pyield/b3_futures/common.py +0 -0
- {pyield-0.26.7 → pyield-0.27.0}/pyield/b3_futures/di.py +0 -0
- {pyield-0.26.7 → pyield-0.27.0}/pyield/b3_futures/historical.py +0 -0
- {pyield-0.26.7 → pyield-0.27.0}/pyield/b3_futures/intraday.py +0 -0
- {pyield-0.26.7 → pyield-0.27.0}/pyield/b3_futures/xml.py +0 -0
- {pyield-0.26.7 → pyield-0.27.0}/pyield/bc/auction.py +0 -0
- {pyield-0.26.7 → pyield-0.27.0}/pyield/bday.py +0 -0
- {pyield-0.26.7 → pyield-0.27.0}/pyield/conftest.py +0 -0
- {pyield-0.26.7 → pyield-0.27.0}/pyield/data_cache.py +0 -0
- {pyield-0.26.7 → pyield-0.27.0}/pyield/date_converter.py +0 -0
- {pyield-0.26.7 → pyield-0.27.0}/pyield/holidays/__init__.py +0 -0
- {pyield-0.26.7 → pyield-0.27.0}/pyield/holidays/br_holidays_new.txt +0 -0
- {pyield-0.26.7 → pyield-0.27.0}/pyield/holidays/br_holidays_old.txt +0 -0
- {pyield-0.26.7 → pyield-0.27.0}/pyield/holidays/brholidays.py +0 -0
- {pyield-0.26.7 → pyield-0.27.0}/pyield/indicators.py +0 -0
- {pyield-0.26.7 → pyield-0.27.0}/pyield/interpolator.py +0 -0
- {pyield-0.26.7 → pyield-0.27.0}/pyield/projections.py +0 -0
- {pyield-0.26.7 → pyield-0.27.0}/pyield/py.typed +0 -0
- {pyield-0.26.7 → pyield-0.27.0}/pyield/tools.py +0 -0
- {pyield-0.26.7 → pyield-0.27.0}/pyield/tpf/__init__.py +0 -0
- {pyield-0.26.7 → pyield-0.27.0}/pyproject.toml +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.27.0"
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
from pyield import
|
|
1
|
+
from pyield import bday
|
|
2
2
|
from pyield.__about__ import __version__
|
|
3
|
+
from pyield.anbima.ima import ima
|
|
4
|
+
from pyield.anbima.imaq import imaq
|
|
5
|
+
from pyield.anbima.tpf import anbima_tpf_data, anbima_tpf_rates, tpf_pre_maturities
|
|
3
6
|
from pyield.b3_futures import futures
|
|
4
7
|
from pyield.b3_futures.di import DIFutures
|
|
5
8
|
from pyield.bc.auction import auctions
|
|
6
|
-
from pyield.ima import ima
|
|
7
9
|
from pyield.indicators import indicator
|
|
8
10
|
from pyield.interpolator import Interpolator
|
|
9
11
|
from pyield.projections import projection
|
|
@@ -12,13 +14,16 @@ from pyield.tpf import lft, ltn, ntnb, ntnf
|
|
|
12
14
|
|
|
13
15
|
__all__ = [
|
|
14
16
|
"__version__",
|
|
15
|
-
"
|
|
17
|
+
"anbima_tpf_data",
|
|
18
|
+
"anbima_tpf_rates",
|
|
19
|
+
"tpf_pre_maturities",
|
|
16
20
|
"auctions",
|
|
17
21
|
"bday",
|
|
18
22
|
"DIFutures",
|
|
19
23
|
"forward_rates",
|
|
20
24
|
"futures",
|
|
21
25
|
"ima",
|
|
26
|
+
"imaq",
|
|
22
27
|
"indicator",
|
|
23
28
|
"Interpolator",
|
|
24
29
|
"lft",
|
|
@@ -69,14 +69,14 @@ def _process_last_ima(df: pd.DataFrame) -> pd.DataFrame:
|
|
|
69
69
|
df["Date"] = pd.to_datetime(df["Date"], format="%d/%m/%Y")
|
|
70
70
|
df["Maturity"] = pd.to_datetime(df["Maturity"], format="%d/%m/%Y")
|
|
71
71
|
df["MarketQuantity"] = (1000 * df["MarketQuantity"]).astype("Int64")
|
|
72
|
+
df["MarketValue"] = (1000 * df["MarketValue"]).round(0).astype("Int64")
|
|
72
73
|
df["Price"] = df["Price"].round(6)
|
|
73
74
|
# Duration is in business days, convert to years
|
|
74
75
|
df["Duration"] /= 252
|
|
75
76
|
mduration = df["Duration"] / (1 + df["IndicativeRate"])
|
|
76
|
-
|
|
77
|
-
# Since
|
|
78
|
-
df["MarketDV01"] =
|
|
79
|
-
df["MarketValue"] = (1000 * df["MarketValue"]).round(0).astype("Int64")
|
|
77
|
+
df["DV01"] = 0.0001 * df["Price"] * mduration * df["MarketQuantity"]
|
|
78
|
+
# Since MarketDV01 is the total stock value, we round them to integer
|
|
79
|
+
df["MarketDV01"] = df["DV01"].round(0).astype("Int64")
|
|
80
80
|
# LFT DV01 is zero
|
|
81
81
|
df["MarketDV01"] = df["MarketDV01"].where(df["BondType"] != "LFT", 0)
|
|
82
82
|
return df
|
|
@@ -95,6 +95,7 @@ def _reorder_last_ima(df: pd.DataFrame) -> pd.DataFrame:
|
|
|
95
95
|
"Price",
|
|
96
96
|
"BDToMat",
|
|
97
97
|
"Duration",
|
|
98
|
+
"DV01",
|
|
98
99
|
"PMR",
|
|
99
100
|
"Convexity",
|
|
100
101
|
"TheoreticalQuantity",
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import logging
|
|
3
|
+
import re
|
|
4
|
+
import warnings
|
|
5
|
+
|
|
6
|
+
import pandas as pd
|
|
7
|
+
import requests
|
|
8
|
+
from bs4 import XMLParsedAsHTMLWarning
|
|
9
|
+
|
|
10
|
+
from pyield import date_converter as dc
|
|
11
|
+
from pyield.date_converter import DateScalar
|
|
12
|
+
|
|
13
|
+
IMA_URL = "https://www.anbima.com.br/informacoes/ima/ima-quantidade-mercado.asp"
|
|
14
|
+
COLUMN_MAPPING = {
|
|
15
|
+
"Data Referência": "Date",
|
|
16
|
+
"Título": "BondType",
|
|
17
|
+
"Data de Vencimento": "Maturity",
|
|
18
|
+
"Codigo Selic": "SelicCode",
|
|
19
|
+
"Código ISIN": "ISIN",
|
|
20
|
+
"PU (R$)": "Price",
|
|
21
|
+
"Quantidade em Mercado (1.000 Títulos)": "MarketQuantity",
|
|
22
|
+
"Valor de Mercado (R$ Mil)": "MarketValue",
|
|
23
|
+
"Variação da Quantidade (1.000 Títulos)": "QuantityVariation",
|
|
24
|
+
"Status do Titulo": "BondStatus",
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _fetch_url_tables(target_date: pd.Timestamp) -> pd.DataFrame:
|
|
29
|
+
# Warning supression for BeautifulSoup, as the text is valid HTML and not XML
|
|
30
|
+
warnings.filterwarnings("ignore", category=XMLParsedAsHTMLWarning)
|
|
31
|
+
|
|
32
|
+
target_date_str = target_date.strftime("%d/%m/%Y")
|
|
33
|
+
payload = {
|
|
34
|
+
"Tipo": "",
|
|
35
|
+
"DataRef": "",
|
|
36
|
+
"Pai": "ima",
|
|
37
|
+
"Dt_Ref_Ver": "20250117",
|
|
38
|
+
"Dt_Ref": f"{target_date_str}",
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
r = requests.post(IMA_URL, data=payload, timeout=10)
|
|
42
|
+
r.raise_for_status()
|
|
43
|
+
r.encoding = "iso-8859-1"
|
|
44
|
+
if "Não há dados disponíveis" in r.text:
|
|
45
|
+
logging.warning("No data found. Returning empty DataFrame.")
|
|
46
|
+
return pd.DataFrame()
|
|
47
|
+
|
|
48
|
+
string_io_buffer = io.StringIO(r.text)
|
|
49
|
+
|
|
50
|
+
dfs = pd.read_html(
|
|
51
|
+
string_io_buffer,
|
|
52
|
+
flavor="html5lib",
|
|
53
|
+
attrs={"width": "100%"},
|
|
54
|
+
header=0,
|
|
55
|
+
thousands=".",
|
|
56
|
+
decimal=",",
|
|
57
|
+
displayed_only=True,
|
|
58
|
+
dtype_backend="numpy_nullable",
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
df = (
|
|
62
|
+
pd.concat(dfs)
|
|
63
|
+
.query("`Data de Vencimento`.notnull()")
|
|
64
|
+
.query("Título!='Título'")
|
|
65
|
+
.drop_duplicates(subset="Código ISIN")
|
|
66
|
+
.reset_index(drop=True)
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
# Convert to CSV and then back to pandas to get automatic type conversion
|
|
70
|
+
csv_buffer = io.StringIO(df.to_csv(index=False))
|
|
71
|
+
df = pd.read_csv(csv_buffer, dtype_backend="numpy_nullable")
|
|
72
|
+
|
|
73
|
+
# Expressão regular para datas no formato dd/mm/ano
|
|
74
|
+
date_pattern = r"\b(\d{2}/\d{2}/\d{4})\b"
|
|
75
|
+
|
|
76
|
+
# Busca pela primeira data
|
|
77
|
+
match = re.search(date_pattern, r.text)
|
|
78
|
+
|
|
79
|
+
if match:
|
|
80
|
+
anbima_date_str = match.group(1)
|
|
81
|
+
anbima_date = pd.to_datetime(anbima_date_str, format="%d/%m/%Y")
|
|
82
|
+
else:
|
|
83
|
+
logging.warning("No date found. Returning empty DataFrame.")
|
|
84
|
+
return pd.DataFrame()
|
|
85
|
+
|
|
86
|
+
df["Data Referência"] = anbima_date
|
|
87
|
+
|
|
88
|
+
return df
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _process_df(df: pd.DataFrame) -> pd.DataFrame:
|
|
92
|
+
df = df.rename(columns=COLUMN_MAPPING)[COLUMN_MAPPING.values()]
|
|
93
|
+
df["Maturity"] = pd.to_datetime(df["Maturity"], format="%d/%m/%Y")
|
|
94
|
+
# Remove the thousands unit from numeric columns
|
|
95
|
+
for col in ["MarketQuantity", "MarketValue", "QuantityVariation"]:
|
|
96
|
+
df[col] = (1000 * df[col]).astype("Int64")
|
|
97
|
+
|
|
98
|
+
return df
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def imaq(date: DateScalar) -> pd.DataFrame:
|
|
102
|
+
"""
|
|
103
|
+
Fetch and process IMA market data for a given date.
|
|
104
|
+
|
|
105
|
+
This function retrieves IMA quantity market data from ANBIMA for a given date,
|
|
106
|
+
processes the data into a structured DataFrame, and returns the resulting DataFrame.
|
|
107
|
+
It handles conversion of date formats, renames columns to English, and converts
|
|
108
|
+
certain numeric columns to integer types. In the event of an error during data
|
|
109
|
+
fetching or processing, an empty DataFrame is returned.
|
|
110
|
+
|
|
111
|
+
Args:
|
|
112
|
+
date (DateScalar): A date-like object representing the target date for fetching
|
|
113
|
+
the data.
|
|
114
|
+
|
|
115
|
+
Returns:
|
|
116
|
+
pd.DataFrame: A DataFrame containing the IMA data with the following columns:
|
|
117
|
+
- Date: Reference date of the data.
|
|
118
|
+
- BondType: Type of bond.
|
|
119
|
+
- Maturity: Bond maturity date.
|
|
120
|
+
- SelicCode: Code representing the SELIC rate.
|
|
121
|
+
- ISIN: International Securities Identification Number.
|
|
122
|
+
- Price: Bond price.
|
|
123
|
+
- MarketQuantity: Market quantity (in units of 1000 bonds).
|
|
124
|
+
- MarketValue: Market value (in units of 1000 reais).
|
|
125
|
+
- QuantityVariation: Variation in quantity (in units of 1000 bonds).
|
|
126
|
+
- BondStatus: Status of the bond.
|
|
127
|
+
|
|
128
|
+
Raises:
|
|
129
|
+
Exception: Logs error and returns an empty DataFrame if any error occurs during
|
|
130
|
+
fetching or processing.
|
|
131
|
+
|
|
132
|
+
"""
|
|
133
|
+
try:
|
|
134
|
+
date = dc.convert_input_dates(date)
|
|
135
|
+
df = _fetch_url_tables(date)
|
|
136
|
+
df = _process_df(df)
|
|
137
|
+
return df
|
|
138
|
+
except Exception as e:
|
|
139
|
+
date_str = date.strftime("%d/%m/%Y")
|
|
140
|
+
logging.error(f"Error fetching IMA for {date_str}. Returning empty DataFrame.")
|
|
141
|
+
logging.error(f"Error message: {e}", exc_info=True)
|
|
142
|
+
return pd.DataFrame()
|
|
@@ -106,7 +106,25 @@ def _process_raw_df(df_raw: pd.DataFrame) -> pd.DataFrame:
|
|
|
106
106
|
return df.sort_values(["BondType", "MaturityDate"], ignore_index=True)
|
|
107
107
|
|
|
108
108
|
|
|
109
|
-
def
|
|
109
|
+
def anbima_tpf_data(
|
|
110
|
+
reference_date: DateScalar, bond_type: str | None = None
|
|
111
|
+
) -> pd.DataFrame:
|
|
112
|
+
"""Fetch and process TPF market data from ANBIMA.
|
|
113
|
+
|
|
114
|
+
This function retrieves bond market data from the ANBIMA website for a
|
|
115
|
+
specified reference date. It handles different file formats based on the date
|
|
116
|
+
and attempts to download the data from both member and non-member URLs.
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
reference_date (DateScalar): The reference date for the data.
|
|
120
|
+
bond_type (str, optional): Filter data by bond type.
|
|
121
|
+
Defaults to None, which returns data for all bond types.
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
pd.DataFrame: A DataFrame containing bond market data.
|
|
125
|
+
Returns an empty DataFrame if data is not available for the
|
|
126
|
+
specified date.
|
|
127
|
+
"""
|
|
110
128
|
# Normalize the reference date
|
|
111
129
|
reference_date = dc.convert_input_dates(reference_date)
|
|
112
130
|
file_content = _get_file_content(reference_date)
|
|
@@ -125,11 +143,30 @@ def data(reference_date: DateScalar, bond_type: str | None = None) -> pd.DataFra
|
|
|
125
143
|
return df.reset_index(drop=True)
|
|
126
144
|
|
|
127
145
|
|
|
128
|
-
def
|
|
146
|
+
def anbima_tpf_rates(
|
|
129
147
|
reference_date: DateScalar,
|
|
130
148
|
bond_type: str | None = None,
|
|
131
149
|
adj_maturities: bool = False,
|
|
132
150
|
) -> pd.DataFrame:
|
|
151
|
+
"""Retrieve indicative rates for bonds from ANBIMA data.
|
|
152
|
+
|
|
153
|
+
This function fetches indicative interest rates for bonds from ANBIMA,
|
|
154
|
+
initially attempting to retrieve data from a cached dataset. If the data
|
|
155
|
+
is not available in the cache, it fetches it directly from the ANBIMA
|
|
156
|
+
website using the :func:`data` function.
|
|
157
|
+
|
|
158
|
+
Args:
|
|
159
|
+
reference_date (DateScalar): The reference date for the rates.
|
|
160
|
+
bond_type (str, optional): Filter rates by bond type.
|
|
161
|
+
Defaults to None, which returns rates for all bond types.
|
|
162
|
+
adj_maturities (bool, optional): Adjust maturity dates to the next
|
|
163
|
+
business day. Defaults to False.
|
|
164
|
+
|
|
165
|
+
Returns:
|
|
166
|
+
pd.DataFrame: A DataFrame containing bond types, maturity dates, and
|
|
167
|
+
indicative rates. Returns an empty DataFrame if data is not
|
|
168
|
+
available for the specified date.
|
|
169
|
+
"""
|
|
133
170
|
df = get_anbima_dataset()
|
|
134
171
|
|
|
135
172
|
reference_date = dc.convert_input_dates(reference_date)
|
|
@@ -137,7 +174,7 @@ def rates(
|
|
|
137
174
|
|
|
138
175
|
if df.empty:
|
|
139
176
|
# Try to fetch the data from the Anbima website
|
|
140
|
-
df =
|
|
177
|
+
df = anbima_tpf_data(reference_date)
|
|
141
178
|
|
|
142
179
|
if df.empty:
|
|
143
180
|
# If the data is still empty, return an empty DataFrame
|
|
@@ -153,11 +190,25 @@ def rates(
|
|
|
153
190
|
return df.sort_values(["BondType", "MaturityDate"], ignore_index=True)
|
|
154
191
|
|
|
155
192
|
|
|
156
|
-
def
|
|
157
|
-
|
|
158
|
-
reference_date = dc.convert_input_dates(reference_date)
|
|
159
|
-
df.query("ReferenceDate == @reference_date", inplace=True)
|
|
160
|
-
df.query("BondType in ['LTN', 'NTN-F']", inplace=True)
|
|
161
|
-
maturity_dates = df["MaturityDate"].drop_duplicates()
|
|
193
|
+
def tpf_pre_maturities(reference_date: DateScalar) -> pd.Series:
|
|
194
|
+
"""Retrieve pre-defined maturity dates for LTN and NTN-F bonds.
|
|
162
195
|
|
|
163
|
-
|
|
196
|
+
This function fetches pre-defined maturity dates for 'LTN' (prefixadas) and
|
|
197
|
+
'NTN-F' (indexadas ao CDI) bond types from the cached ANBIMA dataset
|
|
198
|
+
for a given reference date.
|
|
199
|
+
|
|
200
|
+
Args:
|
|
201
|
+
reference_date (DateScalar): The reference date for maturity dates.
|
|
202
|
+
|
|
203
|
+
Returns:
|
|
204
|
+
pd.Series: A Series containing unique maturity dates for 'LTN' and
|
|
205
|
+
'NTN-F' bonds, sorted in ascending order.
|
|
206
|
+
"""
|
|
207
|
+
maturity_dates = (
|
|
208
|
+
anbima_tpf_rates(reference_date)
|
|
209
|
+
.query("BondType in ['LTN', 'NTN-F']")["MaturityDate"]
|
|
210
|
+
.drop_duplicates()
|
|
211
|
+
.sort_values(ignore_index=True)
|
|
212
|
+
.reset_index(drop=True)
|
|
213
|
+
)
|
|
214
|
+
return maturity_dates
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import datetime as dt
|
|
2
|
+
from typing import Literal
|
|
3
|
+
from zoneinfo import ZoneInfo
|
|
4
|
+
|
|
5
|
+
import pandas as pd
|
|
6
|
+
|
|
7
|
+
from pyield import date_converter as dc
|
|
8
|
+
from pyield.b3_futures.historical import fetch_historical_df
|
|
9
|
+
from pyield.b3_futures.intraday import fetch_intraday_df
|
|
10
|
+
from pyield.date_converter import DateScalar
|
|
11
|
+
|
|
12
|
+
TIMEZONE_BZ = ZoneInfo("America/Sao_Paulo")
|
|
13
|
+
ContractOptions = Literal["DI1", "DDI", "FRC", "DAP", "DOL", "WDO", "IND", "WIN"]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def futures(
|
|
17
|
+
contract_code: ContractOptions,
|
|
18
|
+
trade_date: DateScalar,
|
|
19
|
+
) -> pd.DataFrame:
|
|
20
|
+
"""
|
|
21
|
+
Fetches data for a specified futures contract based on type and reference date.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
contract_code (str): The B3 futures contract code identifying the derivative.
|
|
25
|
+
Supported contract codes are:
|
|
26
|
+
- "DI1": One-day Interbank Deposit Futures (Futuro de DI) from B3.
|
|
27
|
+
- "DDI": DI x U.S. Dollar Spread Futures (Futuro de Cupom Cambial) from B3.
|
|
28
|
+
- "FRC": Forward Rate Agreement (FRA) from B3.
|
|
29
|
+
- "DAP": DI x IPCA Spread Futures.
|
|
30
|
+
- "DOL": U.S. Dollar Futures from B3.
|
|
31
|
+
- "WDO": Mini U.S. Dollar Futures from B3.
|
|
32
|
+
- "IND": Ibovespa Futures from B3.
|
|
33
|
+
- "WIN": Mini Ibovespa Futures from B3.
|
|
34
|
+
trade_date (DateScalar): The date for which to fetch the data.
|
|
35
|
+
If the reference date is a string, it should be in 'DD-MM-YYYY' format.
|
|
36
|
+
|
|
37
|
+
Returns:
|
|
38
|
+
pd.DataFrame: DataFrame containing the fetched data for the specified futures
|
|
39
|
+
contract.
|
|
40
|
+
|
|
41
|
+
Raises:
|
|
42
|
+
ValueError: If the futures contract code is not recognized or supported.
|
|
43
|
+
|
|
44
|
+
Examples:
|
|
45
|
+
>>> futures("DI1", "31-05-2024")
|
|
46
|
+
TradeDate TickerSymbol ... CloseBidRate CloseRate
|
|
47
|
+
0 2024-05-31 DI1M24 ... 0.10404 0.10404
|
|
48
|
+
1 2024-05-31 DI1N24 ... 0.1039 0.10386
|
|
49
|
+
2 2024-05-31 DI1Q24 ... 0.10374 0.10374
|
|
50
|
+
3 2024-05-31 DI1U24 ... 0.10365 0.10355
|
|
51
|
+
...
|
|
52
|
+
>>> futures("DAP", "31-05-2024")
|
|
53
|
+
TradeDate TickerSymbol ... CloseBidRate CloseRate
|
|
54
|
+
0 2024-05-31 DAPM24 ... <NA> <NA>
|
|
55
|
+
1 2024-05-31 DAPN24 ... <NA> <NA>
|
|
56
|
+
2 2024-05-31 DAPQ24 ... <NA> 0.0885
|
|
57
|
+
3 2024-05-31 DAPU24 ... <NA> 0.0865
|
|
58
|
+
...
|
|
59
|
+
"""
|
|
60
|
+
selected_contract = str(contract_code).upper()
|
|
61
|
+
converted_trade_date = dc.convert_input_dates(trade_date)
|
|
62
|
+
|
|
63
|
+
# First, try to fetch historical data for the specified date
|
|
64
|
+
df = fetch_historical_df(selected_contract, converted_trade_date)
|
|
65
|
+
|
|
66
|
+
bz_today = dt.datetime.now(TIMEZONE_BZ).date()
|
|
67
|
+
# If there is no historical data available, try to fetch intraday data
|
|
68
|
+
if converted_trade_date.date() == bz_today and df.empty:
|
|
69
|
+
df = fetch_intraday_df(selected_contract)
|
|
70
|
+
|
|
71
|
+
return df
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
__all__ = ["futures", "ContractOptions"]
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import pandas as pd
|
|
2
2
|
|
|
3
|
-
from pyield import
|
|
3
|
+
from pyield import bday
|
|
4
4
|
from pyield import date_converter as dc
|
|
5
|
+
from pyield.anbima import tpf
|
|
5
6
|
from pyield.date_converter import DateScalar
|
|
6
7
|
from pyield.tpf import tools as tt
|
|
7
8
|
|
|
@@ -16,7 +17,7 @@ def rates(reference_date: DateScalar) -> pd.DataFrame:
|
|
|
16
17
|
Returns:
|
|
17
18
|
pd.DataFrame: DataFrame with columns "MaturityDate" and "IndicativeRate".
|
|
18
19
|
"""
|
|
19
|
-
lft_rates =
|
|
20
|
+
lft_rates = tpf.anbima_tpf_rates(reference_date, "LFT")
|
|
20
21
|
if lft_rates.empty:
|
|
21
22
|
return pd.DataFrame()
|
|
22
23
|
return lft_rates[["MaturityDate", "IndicativeRate"]]
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import pandas as pd
|
|
2
2
|
|
|
3
|
-
from pyield import
|
|
3
|
+
from pyield import bday
|
|
4
4
|
from pyield import date_converter as dc
|
|
5
|
+
from pyield.anbima import tpf
|
|
5
6
|
from pyield.b3_futures import di
|
|
6
7
|
from pyield.date_converter import DateScalar
|
|
7
8
|
from pyield.tpf import tools as tt
|
|
@@ -37,7 +38,7 @@ def rates(reference_date: DateScalar) -> pd.DataFrame:
|
|
|
37
38
|
12 2030-01-01 0.118746
|
|
38
39
|
|
|
39
40
|
"""
|
|
40
|
-
ltn_rates =
|
|
41
|
+
ltn_rates = tpf.anbima_tpf_rates(reference_date, "LTN")
|
|
41
42
|
if ltn_rates.empty:
|
|
42
43
|
return pd.DataFrame()
|
|
43
44
|
return ltn_rates[["MaturityDate", "IndicativeRate"]]
|
|
@@ -4,7 +4,8 @@ import pandas as pd
|
|
|
4
4
|
import pyield.date_converter as dc
|
|
5
5
|
import pyield.interpolator as ip
|
|
6
6
|
import pyield.tpf.tools as bt
|
|
7
|
-
from pyield import
|
|
7
|
+
from pyield import bday
|
|
8
|
+
from pyield.anbima import tpf
|
|
8
9
|
from pyield.date_converter import DateScalar
|
|
9
10
|
|
|
10
11
|
"""
|
|
@@ -85,7 +86,7 @@ def rates(reference_date: DateScalar) -> pd.DataFrame:
|
|
|
85
86
|
13 2060-08-15 0.060179
|
|
86
87
|
|
|
87
88
|
"""
|
|
88
|
-
ntnb_rates =
|
|
89
|
+
ntnb_rates = tpf.anbima_tpf_rates(reference_date, "NTN-B")
|
|
89
90
|
if ntnb_rates.empty:
|
|
90
91
|
return pd.DataFrame()
|
|
91
92
|
return ntnb_rates[["MaturityDate", "IndicativeRate"]]
|
|
@@ -3,9 +3,10 @@ from collections.abc import Callable
|
|
|
3
3
|
import numpy as np
|
|
4
4
|
import pandas as pd
|
|
5
5
|
|
|
6
|
-
from pyield import
|
|
6
|
+
from pyield import bday, data_cache
|
|
7
7
|
from pyield import date_converter as dc
|
|
8
8
|
from pyield import interpolator as ip
|
|
9
|
+
from pyield.anbima import tpf
|
|
9
10
|
from pyield.b3_futures import di
|
|
10
11
|
from pyield.date_converter import DateScalar
|
|
11
12
|
from pyield.tpf import tools as tt
|
|
@@ -54,7 +55,7 @@ def rates(reference_date: DateScalar) -> pd.DataFrame:
|
|
|
54
55
|
4 2033-01-01 0.116307
|
|
55
56
|
5 2035-01-01 0.116586
|
|
56
57
|
"""
|
|
57
|
-
ntnf_rates =
|
|
58
|
+
ntnf_rates = tpf.anbima_tpf_rates(reference_date, "NTN-F")
|
|
58
59
|
if ntnf_rates.empty:
|
|
59
60
|
return pd.DataFrame()
|
|
60
61
|
return ntnf_rates[["MaturityDate", "IndicativeRate"]]
|
|
@@ -92,7 +93,7 @@ def _check_maturity_date(maturity: pd.Timestamp) -> None:
|
|
|
92
93
|
Check if the maturity date is a valid NTN-F maturity date.
|
|
93
94
|
|
|
94
95
|
Args:
|
|
95
|
-
|
|
96
|
+
maturity (pd.Timestamp): The maturity date to be checked.
|
|
96
97
|
|
|
97
98
|
Raises:
|
|
98
99
|
ValueError: If the maturity date is not the 1st of January.
|
|
@@ -3,8 +3,8 @@ from typing import overload
|
|
|
3
3
|
import numpy as np
|
|
4
4
|
import pandas as pd
|
|
5
5
|
|
|
6
|
-
from pyield import anbima
|
|
7
6
|
from pyield import date_converter as dc
|
|
7
|
+
from pyield.anbima import tpf
|
|
8
8
|
from pyield.b3_futures.di import DIFutures
|
|
9
9
|
from pyield.date_converter import DateScalar
|
|
10
10
|
|
|
@@ -88,8 +88,8 @@ def pre_spreads(reference_date: DateScalar) -> pd.DataFrame:
|
|
|
88
88
|
df_di.rename(columns={"ExpirationDate": "MaturityDate"}, inplace=True)
|
|
89
89
|
|
|
90
90
|
# Fetch bond rates, filtering for LTN and NTN-F types
|
|
91
|
-
df_ltn =
|
|
92
|
-
df_ntnf =
|
|
91
|
+
df_ltn = tpf.anbima_tpf_rates(converted_date, "LTN")
|
|
92
|
+
df_ntnf = tpf.anbima_tpf_rates(converted_date, "NTN-F")
|
|
93
93
|
df_pre = pd.concat([df_ltn, df_ntnf], ignore_index=True)
|
|
94
94
|
|
|
95
95
|
# Merge bond and DI rates by maturity date to calculate spreads
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.26.7"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|