PYield 0.16.0__tar.gz → 0.16.2__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.16.0 → pyield-0.16.2}/PKG-INFO +1 -1
- pyield-0.16.2/pyield/__about__.py +1 -0
- {pyield-0.16.0 → pyield-0.16.2}/pyield/bday.py +2 -2
- {pyield-0.16.0 → pyield-0.16.2}/pyield/bonds/ltn.py +1 -1
- {pyield-0.16.0 → pyield-0.16.2}/pyield/data/di.py +5 -6
- {pyield-0.16.0 → pyield-0.16.2}/pyield/interpolator.py +8 -4
- {pyield-0.16.0 → pyield-0.16.2}/pyproject.toml +1 -1
- pyield-0.16.0/pyield/__about__.py +0 -1
- {pyield-0.16.0 → pyield-0.16.2}/LICENSE +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/README.md +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/pyield/__init__.py +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/pyield/bonds/__init__.py +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/pyield/bonds/bond_tools.py +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/pyield/bonds/lft.py +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/pyield/bonds/ntnb.py +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/pyield/bonds/ntnf.py +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/pyield/data/__init__.py +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/pyield/data/anbima.py +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/pyield/data/data_cache.py +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/pyield/data/futures_data/__init__.py +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/pyield/data/futures_data/common.py +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/pyield/data/futures_data/historical.py +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/pyield/data/futures_data/intraday.py +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/pyield/data/futures_data/xml.py +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/pyield/data/indicators.py +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/pyield/data/projections.py +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/pyield/date_converter.py +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/pyield/holidays/__init__.py +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/pyield/holidays/br_holidays_new.txt +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/pyield/holidays/br_holidays_old.txt +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/pyield/holidays/holidays_manager.py +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/pyield/py.typed +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/tests/__init__.py +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/tests/data/SPRD231222.zip +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/tests/data/SPRD240426.zip +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/tests/test_bday.py +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/tests/test_futures.py +0 -0
- {pyield-0.16.0 → pyield-0.16.2}/tests/test_futures_xml.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.16.2"
|
|
@@ -116,11 +116,11 @@ def offset(
|
|
|
116
116
|
`Series` of offset dates.
|
|
117
117
|
|
|
118
118
|
Examples:
|
|
119
|
-
>>> date = "
|
|
119
|
+
>>> date = "23-12-2023" # Saturday before Christmas
|
|
120
120
|
>>> bday.offset(date, 0)
|
|
121
121
|
Timestamp('2023-12-26')
|
|
122
122
|
|
|
123
|
-
>>> date = "
|
|
123
|
+
>>> date = "22-12-2023" # Friday before Christmas
|
|
124
124
|
>>> bday.offset(date, 0)
|
|
125
125
|
Timestamp('2023-12-22') # No offset because it's a business day
|
|
126
126
|
|
|
@@ -152,7 +152,7 @@ def historical_premium(
|
|
|
152
152
|
ltn_rates = df_anbima.query("MaturityDate == @maturity")["IndicativeRate"]
|
|
153
153
|
if ltn_rates.empty:
|
|
154
154
|
return float("NaN")
|
|
155
|
-
ltn_rate = ltn_rates.iloc[0]
|
|
155
|
+
ltn_rate = float(ltn_rates.iloc[0])
|
|
156
156
|
|
|
157
157
|
# Retrieve DI rate for the reference date and maturity
|
|
158
158
|
di_rate = di.rate(trade_date=reference_date, expiration=maturity)
|
|
@@ -113,8 +113,6 @@ def rate(
|
|
|
113
113
|
"""
|
|
114
114
|
# Convert input dates to consistent format
|
|
115
115
|
trade_date = dc.convert_date(trade_date)
|
|
116
|
-
expiration = dc.convert_date(expiration)
|
|
117
|
-
|
|
118
116
|
# Adjust expiration date to the nearest business day
|
|
119
117
|
expiration = bday.offset(expiration, 0)
|
|
120
118
|
|
|
@@ -132,6 +130,10 @@ def rate(
|
|
|
132
130
|
if df_exp.empty and not interpolate:
|
|
133
131
|
return float("NaN")
|
|
134
132
|
|
|
133
|
+
if expiration in df_exp["ExpirationDate"]:
|
|
134
|
+
# Return the rate if an exact match is found
|
|
135
|
+
return float(df_exp["SettlementRate"].iloc[0])
|
|
136
|
+
|
|
135
137
|
# Perform flat forward interpolation if required
|
|
136
138
|
ff_interpolator = interpolator.Interpolator(
|
|
137
139
|
method="flat_forward",
|
|
@@ -139,8 +141,5 @@ def rate(
|
|
|
139
141
|
known_rates=df["SettlementRate"],
|
|
140
142
|
)
|
|
141
143
|
|
|
142
|
-
# Calculate business days between trade date and expiration date
|
|
143
|
-
bdays = bday.count(trade_date, expiration)
|
|
144
|
-
|
|
145
144
|
# Return the interpolated rate for the calculated business days
|
|
146
|
-
return ff_interpolator(
|
|
145
|
+
return ff_interpolator(bday.count(trade_date, expiration))
|
|
@@ -11,6 +11,7 @@ class Interpolator:
|
|
|
11
11
|
method: Literal["flat_forward", "linear"],
|
|
12
12
|
known_bdays: pd.Series | list,
|
|
13
13
|
known_rates: pd.Series | list,
|
|
14
|
+
extrapolate: bool = False,
|
|
14
15
|
):
|
|
15
16
|
"""
|
|
16
17
|
Initialize the Interpolator with given atributes.
|
|
@@ -19,6 +20,7 @@ class Interpolator:
|
|
|
19
20
|
method (Literal["flat_forward", "linear"]): Interpolation method.
|
|
20
21
|
known_bdays (pd.Series | pd.Index | list): Series of known business days.
|
|
21
22
|
known_rates (pd.Series | pd.Index | list): Series of known interest rates.
|
|
23
|
+
extrapolate (bool, optional): Whether to extrapolate beyond the known data.
|
|
22
24
|
|
|
23
25
|
Raises:
|
|
24
26
|
ValueError: If known_bdays and known_rates do not have the same length.
|
|
@@ -43,6 +45,7 @@ class Interpolator:
|
|
|
43
45
|
self.method = method
|
|
44
46
|
self.known_bdays = known_bdays
|
|
45
47
|
self.known_rates = known_rates
|
|
48
|
+
self.extrapolate = extrapolate
|
|
46
49
|
self._set_known_bdays_and_rates()
|
|
47
50
|
|
|
48
51
|
def _set_known_bdays_and_rates(self) -> None:
|
|
@@ -105,17 +108,18 @@ class Interpolator:
|
|
|
105
108
|
# Check for edge cases
|
|
106
109
|
if bday < self._known_bdays[0]:
|
|
107
110
|
return self._known_rates[0]
|
|
108
|
-
elif bday > self._known_bdays[-1]:
|
|
109
|
-
return self._known_rates[-1]
|
|
110
111
|
elif bday in self._known_bdays:
|
|
111
112
|
return self._known_rates[self._known_bdays.index(bday)]
|
|
113
|
+
elif bday > self._known_bdays[-1]:
|
|
114
|
+
if self.extrapolate:
|
|
115
|
+
return self._known_rates[-1]
|
|
116
|
+
else:
|
|
117
|
+
return float("NaN")
|
|
112
118
|
|
|
113
119
|
if self.method == "flat_forward":
|
|
114
120
|
return self._flat_forward(bday)
|
|
115
121
|
elif self.method == "linear":
|
|
116
122
|
return self._linear(bday)
|
|
117
|
-
else:
|
|
118
|
-
raise ValueError(f"Unknown interpolation method: {self.method}.")
|
|
119
123
|
|
|
120
124
|
def __call__(self, bday: int) -> float:
|
|
121
125
|
"""
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.16.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
|