PYield 0.35.0__tar.gz → 0.35.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.35.0 → pyield-0.35.1}/PKG-INFO +1 -1
- pyield-0.35.1/pyield/__about__.py +1 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/b3/di1.py +45 -73
- {pyield-0.35.0 → pyield-0.35.1}/pyield/tpf/tools.py +1 -1
- pyield-0.35.0/pyield/__about__.py +0 -1
- {pyield-0.35.0 → pyield-0.35.1}/.gitignore +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/LICENSE +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/README.md +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/__init__.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/anbima/__init__.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/anbima/ettj.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/anbima/ima.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/anbima/imaq.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/anbima/ipca.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/anbima/tpf.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/b3/__init__.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/b3/di_over.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/b3/futures/__init__.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/b3/futures/common.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/b3/futures/historical.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/b3/futures/intraday.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/b3/futures/xml.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/bc/__init__.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/bc/auction.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/bc/bcdata.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/bc/ptax.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/bc/repo.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/bc/trades_intraday.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/bc/trades_monthly.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/bc/vna.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/bday.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/conftest.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/data_cache.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/date_converter.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/fwd.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/holidays/__init__.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/holidays/br_holidays_new.txt +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/holidays/br_holidays_old.txt +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/holidays/brholidays.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/ibge/__init__.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/ibge/ipca.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/interpolator.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/py.typed +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/retry.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/tpf/__init__.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/tpf/lft.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/tpf/ltn.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/tpf/ntnb.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/tpf/ntnc.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyield/tpf/ntnf.py +0 -0
- {pyield-0.35.0 → pyield-0.35.1}/pyproject.toml +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.35.1"
|
|
@@ -15,7 +15,7 @@ TIMEZONE_BZ = ZoneInfo("America/Sao_Paulo")
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
def data(
|
|
18
|
-
|
|
18
|
+
dates: DateScalar | DateArray,
|
|
19
19
|
month_start: bool = False,
|
|
20
20
|
pre_filter: bool = False,
|
|
21
21
|
all_columns: bool = True,
|
|
@@ -27,9 +27,7 @@ def data(
|
|
|
27
27
|
(to month start) and optional filtering based on LTN and NTN-F bond maturities.
|
|
28
28
|
|
|
29
29
|
Args:
|
|
30
|
-
|
|
31
|
-
If the date is invalid, a holiday, in the future, or None, an empty
|
|
32
|
-
DataFrame is returned with appropriate logging.
|
|
30
|
+
dates (DateScalar): The trade dates for which to retrieve DI contract data.
|
|
33
31
|
month_start (bool, optional): If True, adjusts all expiration dates to the
|
|
34
32
|
first day of their respective month (e.g., 2025-02-01 becomes
|
|
35
33
|
2025-01-01). Defaults to False.
|
|
@@ -43,12 +41,12 @@ def data(
|
|
|
43
41
|
|
|
44
42
|
Returns:
|
|
45
43
|
pd.DataFrame: A DataFrame containing the DI futures contract data for the
|
|
46
|
-
specified
|
|
47
|
-
if no data is found
|
|
44
|
+
specified dates, sorted by trade dates and expiration dates.
|
|
45
|
+
Returns an empty DataFrame if no data is found
|
|
48
46
|
|
|
49
47
|
Examples:
|
|
50
48
|
>>> from pyield import di1
|
|
51
|
-
>>> df = di1.data(
|
|
49
|
+
>>> df = di1.data(dates="16-10-2024", month_start=True)
|
|
52
50
|
>>> df.iloc[:5, :5] # Show the first five rows and columns
|
|
53
51
|
TradeDate ExpirationDate TickerSymbol BDaysToExp OpenContracts
|
|
54
52
|
0 2024-10-16 2024-11-01 DI1X24 12 1744269
|
|
@@ -57,31 +55,25 @@ def data(
|
|
|
57
55
|
3 2024-10-16 2025-02-01 DI1G25 74 279491
|
|
58
56
|
4 2024-10-16 2025-03-01 DI1H25 94 344056
|
|
59
57
|
"""
|
|
60
|
-
if date:
|
|
61
|
-
date = dc.convert_input_dates(date)
|
|
62
|
-
bz_today = dt.now(TIMEZONE_BZ).date()
|
|
63
|
-
if date.date() > bz_today:
|
|
64
|
-
logger.warning(f"DI date ({date}) after current date {bz_today}")
|
|
65
|
-
logger.warning("Returning empty DataFrame.")
|
|
66
|
-
return pd.DataFrame()
|
|
67
|
-
else:
|
|
68
|
-
logger.info("No date specified. Returning empty DataFrame.")
|
|
69
|
-
return pd.DataFrame()
|
|
70
|
-
# Return an empty DataFrame if the trade date is a holiday
|
|
71
|
-
if not bday.is_business_day(date):
|
|
72
|
-
logger.warning("Specified date is not a business day.")
|
|
73
|
-
logger.warning("Returning empty DataFrame.")
|
|
74
|
-
return pd.DataFrame()
|
|
75
58
|
|
|
76
|
-
|
|
77
|
-
|
|
59
|
+
dates = dc.convert_input_dates(dates)
|
|
60
|
+
# Force dates to be a Series for consistency
|
|
61
|
+
dates = pd.Series(dates) if isinstance(dates, pd.Timestamp) else dates
|
|
62
|
+
# Remove duplicates and sort dates
|
|
63
|
+
dates = dates.drop_duplicates().sort_values().reset_index(drop=True)
|
|
78
64
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
65
|
+
df = get_cached_dataset("DI").query("TradeDate in @dates").reset_index(drop=True)
|
|
66
|
+
|
|
67
|
+
today = dt.now(TIMEZONE_BZ)
|
|
68
|
+
last_bday = bday.last_business_day()
|
|
69
|
+
is_trading_day = today.date() == last_bday.date()
|
|
70
|
+
if is_trading_day and last_bday in df["TradeDate"]:
|
|
71
|
+
logger.info("Trying to get DI Futures data for today.")
|
|
72
|
+
df_intraday = b3.futures(contract_code="DI1", date=last_bday)
|
|
73
|
+
df = pd.concat([df, df_intraday]).reset_index(drop=True)
|
|
82
74
|
|
|
83
75
|
if df.empty:
|
|
84
|
-
logger.warning("No DI Futures data found for the specified
|
|
76
|
+
logger.warning("No DI Futures data found for the specified dates.")
|
|
85
77
|
logger.warning("Returning empty DataFrame.")
|
|
86
78
|
return pd.DataFrame()
|
|
87
79
|
|
|
@@ -92,24 +84,35 @@ def data(
|
|
|
92
84
|
df_pre = (
|
|
93
85
|
get_cached_dataset("TPF")
|
|
94
86
|
.query("BondType in ['LTN', 'NTN-F']")
|
|
95
|
-
.
|
|
87
|
+
.drop_duplicates(subset=["ReferenceDate", "MaturityDate"])
|
|
88
|
+
.sort_values(["ReferenceDate", "MaturityDate"])
|
|
89
|
+
.reset_index(drop=True)[["ReferenceDate", "MaturityDate", "BondType"]]
|
|
96
90
|
)
|
|
91
|
+
# Assure that the MaturityDate is a business day
|
|
92
|
+
df_pre["MaturityDate"] = bday.offset(df_pre["MaturityDate"], 0)
|
|
97
93
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
94
|
+
# Rename columns for merging
|
|
95
|
+
df_pre = df_pre.rename(
|
|
96
|
+
columns={"ReferenceDate": "TradeDate", "MaturityDate": "ExpirationDate"}
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
df = pd.merge_asof(
|
|
100
|
+
df, df_pre, on="TradeDate", by="ExpirationDate", direction="backward"
|
|
101
|
+
)
|
|
102
102
|
|
|
103
|
-
#
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
.
|
|
103
|
+
# BondType was used as flag to filter the maturities
|
|
104
|
+
df = (
|
|
105
|
+
df.query("BondType.notna()")
|
|
106
|
+
.drop(columns=["BondType"])
|
|
107
107
|
.reset_index(drop=True)
|
|
108
108
|
)
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
if df.empty:
|
|
111
|
+
logger.warning(
|
|
112
|
+
"No DI Futures data found for the specified dates after pre-filtering."
|
|
113
|
+
"Returning empty DataFrame."
|
|
114
|
+
)
|
|
115
|
+
return pd.DataFrame()
|
|
113
116
|
|
|
114
117
|
if month_start:
|
|
115
118
|
df["ExpirationDate"] = df["ExpirationDate"].dt.to_period("M").dt.to_timestamp()
|
|
@@ -139,33 +142,6 @@ def data(
|
|
|
139
142
|
return df.sort_values(by=["TradeDate", "ExpirationDate"]).reset_index(drop=True)
|
|
140
143
|
|
|
141
144
|
|
|
142
|
-
def _find_nearest_date(
|
|
143
|
-
target_date: pd.Timestamp, date_series: pd.Series
|
|
144
|
-
) -> pd.Timestamp:
|
|
145
|
-
"""Finds the date in a Series closest to the target date.
|
|
146
|
-
|
|
147
|
-
Args:
|
|
148
|
-
target_date (pd.Timestamp): The reference date.
|
|
149
|
-
date_series (pd.Series): A Series of dates to search within.
|
|
150
|
-
|
|
151
|
-
Returns:
|
|
152
|
-
pd.Timestamp: The date from `date_series` that is closest in time
|
|
153
|
-
to `target_date`. Returns pd.NaT if the series is empty or
|
|
154
|
-
target_date is None.
|
|
155
|
-
"""
|
|
156
|
-
if date_series.empty or target_date is None:
|
|
157
|
-
return pd.NaT
|
|
158
|
-
# The result will be a Series of positive Timedeltas (durations)
|
|
159
|
-
abs_differences = (date_series - target_date).abs()
|
|
160
|
-
|
|
161
|
-
# Find the index of the minimum difference in the differences Series
|
|
162
|
-
# idxmin() returns the index label where the minimum value occurs
|
|
163
|
-
closest_index = abs_differences.idxmin()
|
|
164
|
-
|
|
165
|
-
# Use the found index to get the corresponding date from the original Series
|
|
166
|
-
return date_series.loc[closest_index] # or date_series[closest_index]
|
|
167
|
-
|
|
168
|
-
|
|
169
145
|
def interpolate_rates(
|
|
170
146
|
dates: DateScalar | DateArray,
|
|
171
147
|
expirations: DateScalar | DateArray,
|
|
@@ -230,11 +206,7 @@ def interpolate_rates(
|
|
|
230
206
|
dfi["irate"] = dfi["irate"].astype("Float64")
|
|
231
207
|
|
|
232
208
|
# Load DI rates dataset filtered by the provided reference dates
|
|
233
|
-
dfr = (
|
|
234
|
-
get_cached_dataset("DI")
|
|
235
|
-
.query("TradeDate in @dfi['tdate'].unique()")
|
|
236
|
-
.reset_index(drop=True)
|
|
237
|
-
)
|
|
209
|
+
dfr = data(dates=dates)
|
|
238
210
|
|
|
239
211
|
# Return an empty DataFrame if no rates are found
|
|
240
212
|
if dfr.empty:
|
|
@@ -314,7 +286,7 @@ def interpolate_rate(
|
|
|
314
286
|
return float("NaN")
|
|
315
287
|
|
|
316
288
|
# Get the DI contract DataFrame
|
|
317
|
-
df = data(
|
|
289
|
+
df = data(dates=date)
|
|
318
290
|
|
|
319
291
|
if df.empty:
|
|
320
292
|
return float("NaN")
|
|
@@ -77,7 +77,7 @@ def pre_spreads(date: DateScalar) -> pd.DataFrame:
|
|
|
77
77
|
"""
|
|
78
78
|
# Fetch DI rates for the reference date
|
|
79
79
|
converted_date = dc.convert_input_dates(date)
|
|
80
|
-
df_di = di1.data(
|
|
80
|
+
df_di = di1.data(dates=converted_date, month_start=True)
|
|
81
81
|
if "SettlementRate" not in df_di.columns or df_di.empty:
|
|
82
82
|
raise ValueError("DI data is missing the 'SettlementRate' column or is empty.")
|
|
83
83
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.35.0"
|
|
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
|
|
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
|