PYield 0.24.2__tar.gz → 0.25.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.24.2 → pyield-0.25.0}/PKG-INFO +1 -1
- pyield-0.25.0/pyield/__about__.py +1 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyield/bonds/bond_tools.py +1 -1
- {pyield-0.24.2 → pyield-0.25.0}/pyield/bonds/ntnb.py +1 -1
- {pyield-0.24.2 → pyield-0.25.0}/pyield/di.py +49 -18
- pyield-0.24.2/pyield/__about__.py +0 -1
- {pyield-0.24.2 → pyield-0.25.0}/.gitignore +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/LICENSE +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/README.md +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyield/__init__.py +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyield/anbima.py +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyield/b3_futures/__init__.py +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyield/b3_futures/common.py +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyield/b3_futures/historical.py +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyield/b3_futures/intraday.py +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyield/b3_futures/xml.py +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyield/bday.py +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyield/bonds/__init__.py +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyield/bonds/lft.py +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyield/bonds/ltn.py +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyield/bonds/ntnf.py +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyield/conftest.py +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyield/data_cache.py +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyield/date_converter.py +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyield/holidays/__init__.py +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyield/holidays/br_holidays_new.txt +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyield/holidays/br_holidays_old.txt +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyield/holidays/brholidays.py +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyield/indicators.py +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyield/interpolator.py +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyield/projections.py +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyield/py.typed +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyield/tools.py +0 -0
- {pyield-0.24.2 → pyield-0.25.0}/pyproject.toml +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.25.0"
|
|
@@ -78,7 +78,7 @@ def pre_spreads(reference_date: DateScalar) -> pd.DataFrame:
|
|
|
78
78
|
# Fetch DI rates for the reference date
|
|
79
79
|
converted_date = dc.convert_input_dates(reference_date)
|
|
80
80
|
di = DIFutures(trade_dates=converted_date, month_start=True)
|
|
81
|
-
df_di = di.
|
|
81
|
+
df_di = di.df
|
|
82
82
|
if "SettlementRate" not in df_di.columns:
|
|
83
83
|
raise ValueError("DI rates data is missing the 'SettlementRate' column.")
|
|
84
84
|
|
|
@@ -490,7 +490,7 @@ def bei_rates(
|
|
|
490
490
|
Get the DI Futures settlement rates for the same reference date to be used as
|
|
491
491
|
reference for the nominal rates:
|
|
492
492
|
>>> di = yd.DIFutures("05-09-2024")
|
|
493
|
-
>>> df_di = di.
|
|
493
|
+
>>> df_di = di.df
|
|
494
494
|
|
|
495
495
|
Calculate the BEI rates considering the settlement at the reference date:
|
|
496
496
|
>>> yd.ntnb.bei_rates(
|
|
@@ -17,17 +17,19 @@ class DIFutures:
|
|
|
17
17
|
NTN-F bond maturities.
|
|
18
18
|
|
|
19
19
|
Args:
|
|
20
|
-
|
|
20
|
+
trade_dates (DateScalar | DateArray | None): The trade date(s) to retrieve the
|
|
21
|
+
DI contract data. If None, the latest available historical trade date is
|
|
22
|
+
used.
|
|
21
23
|
month_start (bool): If True, adjusts the expiration dates to the start
|
|
22
24
|
of the month.
|
|
23
|
-
|
|
25
|
+
pre_filter (bool): If True, filters the DI contracts to match only
|
|
24
26
|
expirations with existing prefixed TN bond maturities (LTN and NTN-F).
|
|
25
27
|
all_columns (bool): If True, returns all available columns in the DI dataset.
|
|
26
28
|
|
|
27
29
|
Examples:
|
|
28
30
|
To create a `DIFutures` instance and retrieve data:
|
|
29
|
-
>>>
|
|
30
|
-
>>> df =
|
|
31
|
+
>>> dif = yd.DIFutures(trade_dates="16-10-2024", month_start=True)
|
|
32
|
+
>>> df = dif.df # Retrieve DI contract dataframe for the specified date
|
|
31
33
|
>>> df.iloc[:5, :5] # Show the first five rows and columns
|
|
32
34
|
TradeDate ExpirationDate TickerSymbol BDaysToExp OpenContracts
|
|
33
35
|
0 2024-10-16 2024-11-01 DI1X24 12 1744269
|
|
@@ -37,7 +39,7 @@ class DIFutures:
|
|
|
37
39
|
4 2024-10-16 2025-03-01 DI1H25 94 344056
|
|
38
40
|
|
|
39
41
|
You can also retrieve forward rates for the DI contracts:
|
|
40
|
-
>>>
|
|
42
|
+
>>> dif.forwards.iloc[:5] # Show the first five rows
|
|
41
43
|
TradeDate ExpirationDate SettlementRate ForwardRate
|
|
42
44
|
0 2024-10-16 2024-11-01 0.10653 0.10653
|
|
43
45
|
1 2024-10-16 2024-12-01 0.1091 0.110726
|
|
@@ -62,19 +64,42 @@ class DIFutures:
|
|
|
62
64
|
self,
|
|
63
65
|
trade_dates: DateScalar | DateArray | None = None,
|
|
64
66
|
month_start: bool = False,
|
|
65
|
-
|
|
67
|
+
pre_filter: bool = False,
|
|
66
68
|
all_columns: bool = True,
|
|
67
69
|
):
|
|
68
70
|
"""
|
|
69
|
-
Initialize the DIFutures instance with
|
|
71
|
+
Initialize the DIFutures instance with the specified parameters.
|
|
72
|
+
|
|
73
|
+
Note:
|
|
74
|
+
The DI contract DataFrame is not loaded during initialization. It will be
|
|
75
|
+
automatically loaded the first time the df() method is accessed.
|
|
70
76
|
"""
|
|
77
|
+
self._df = pd.DataFrame()
|
|
78
|
+
self._dirty = True # Attribute to track if the df needs updating
|
|
79
|
+
|
|
71
80
|
self.trade_dates = trade_dates
|
|
72
81
|
self.month_start = month_start
|
|
73
|
-
self.
|
|
82
|
+
self.pre_filter = pre_filter
|
|
74
83
|
self.all_columns = all_columns
|
|
75
84
|
|
|
76
85
|
@property
|
|
77
|
-
def
|
|
86
|
+
def df(self) -> pd.DataFrame:
|
|
87
|
+
"""
|
|
88
|
+
The DI contracts DataFrame for the instance's trade dates and applied filters.
|
|
89
|
+
|
|
90
|
+
If the internal state is marked as 'dirty', the DataFrame will be (re)loaded
|
|
91
|
+
before returning, ensuring that the returned data reflects the latest attribute
|
|
92
|
+
values.
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
pd.DataFrame: The DI contract data.
|
|
96
|
+
"""
|
|
97
|
+
if self._dirty:
|
|
98
|
+
self._df = self._update_df()
|
|
99
|
+
self._dirty = False
|
|
100
|
+
return self._df
|
|
101
|
+
|
|
102
|
+
def _update_df(self) -> pd.DataFrame:
|
|
78
103
|
"""Retrieve DI contract DataFrame for the initialized trade date."""
|
|
79
104
|
df = (
|
|
80
105
|
get_di_dataset()
|
|
@@ -93,7 +118,7 @@ class DIFutures:
|
|
|
93
118
|
if "DaysToExpiration" in df.columns:
|
|
94
119
|
df.drop(columns=["DaysToExpiration"], inplace=True)
|
|
95
120
|
|
|
96
|
-
if self.
|
|
121
|
+
if self._pre_filter:
|
|
97
122
|
df_pre = (
|
|
98
123
|
get_anbima_dataset()
|
|
99
124
|
.query("BondType in ['LTN', 'NTN-F']")
|
|
@@ -106,7 +131,7 @@ class DIFutures:
|
|
|
106
131
|
df_pre["MaturityDate"] = bday.offset(df_pre["MaturityDate"], 0)
|
|
107
132
|
df_pre = df_pre.rename(
|
|
108
133
|
columns={
|
|
109
|
-
"ReferenceDate": "
|
|
134
|
+
"ReferenceDate": "TradeDate",
|
|
110
135
|
"MaturityDate": "ExpirationDate",
|
|
111
136
|
}
|
|
112
137
|
)
|
|
@@ -130,6 +155,7 @@ class DIFutures:
|
|
|
130
155
|
"MaxRate",
|
|
131
156
|
"CloseRate",
|
|
132
157
|
"SettlementRate",
|
|
158
|
+
"SettlementPrice",
|
|
133
159
|
]
|
|
134
160
|
df = df[cols].copy()
|
|
135
161
|
|
|
@@ -152,7 +178,7 @@ class DIFutures:
|
|
|
152
178
|
- ForwardRate: The forward rate calculated between successive expiration
|
|
153
179
|
dates.
|
|
154
180
|
"""
|
|
155
|
-
df = self.
|
|
181
|
+
df = self.df
|
|
156
182
|
if df.empty:
|
|
157
183
|
return pd.DataFrame()
|
|
158
184
|
|
|
@@ -278,7 +304,7 @@ class DIFutures:
|
|
|
278
304
|
if not interpolate and extrapolate:
|
|
279
305
|
raise ValueError("Extrapolation is not allowed without interpolation.")
|
|
280
306
|
|
|
281
|
-
df = self.
|
|
307
|
+
df = self.df
|
|
282
308
|
|
|
283
309
|
if df.empty:
|
|
284
310
|
return float("NaN")
|
|
@@ -329,6 +355,8 @@ class DIFutures:
|
|
|
329
355
|
elif isinstance(trade_dates, pd.Series):
|
|
330
356
|
self._trade_dates = trade_dates.drop_duplicates().sort_values().to_list()
|
|
331
357
|
|
|
358
|
+
self._dirty = True
|
|
359
|
+
|
|
332
360
|
@property
|
|
333
361
|
def month_start(self) -> bool:
|
|
334
362
|
"""
|
|
@@ -346,9 +374,10 @@ class DIFutures:
|
|
|
346
374
|
@month_start.setter
|
|
347
375
|
def month_start(self, value: bool):
|
|
348
376
|
self._month_start = value
|
|
377
|
+
self._dirty = True
|
|
349
378
|
|
|
350
379
|
@property
|
|
351
|
-
def
|
|
380
|
+
def pre_filter(self) -> bool:
|
|
352
381
|
"""
|
|
353
382
|
Filters DI Futures to match prefixed TN bond maturities.
|
|
354
383
|
|
|
@@ -359,11 +388,12 @@ class DIFutures:
|
|
|
359
388
|
bool: Whether the contracts are filtered to match prefixed TN bond
|
|
360
389
|
maturities from the ANBIMA dataset.
|
|
361
390
|
"""
|
|
362
|
-
return self.
|
|
391
|
+
return self._pre_filter
|
|
363
392
|
|
|
364
|
-
@
|
|
365
|
-
def
|
|
366
|
-
self.
|
|
393
|
+
@pre_filter.setter
|
|
394
|
+
def pre_filter(self, value: bool):
|
|
395
|
+
self._pre_filter = value
|
|
396
|
+
self._dirty = True
|
|
367
397
|
|
|
368
398
|
@property
|
|
369
399
|
def all_columns(self) -> bool:
|
|
@@ -372,3 +402,4 @@ class DIFutures:
|
|
|
372
402
|
@all_columns.setter
|
|
373
403
|
def all_columns(self, value: bool):
|
|
374
404
|
self._all_columns = value
|
|
405
|
+
self._dirty = True
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.24.2"
|
|
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
|