PYield 0.24.1__tar.gz → 0.24.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.24.1 → pyield-0.24.2}/PKG-INFO +1 -1
- pyield-0.24.2/pyield/__about__.py +1 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/bonds/ntnf.py +12 -1
- {pyield-0.24.1 → pyield-0.24.2}/pyield/interpolator.py +28 -40
- pyield-0.24.1/pyield/__about__.py +0 -1
- {pyield-0.24.1 → pyield-0.24.2}/.gitignore +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/LICENSE +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/README.md +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/__init__.py +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/anbima.py +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/b3_futures/__init__.py +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/b3_futures/common.py +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/b3_futures/historical.py +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/b3_futures/intraday.py +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/b3_futures/xml.py +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/bday.py +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/bonds/__init__.py +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/bonds/bond_tools.py +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/bonds/lft.py +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/bonds/ltn.py +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/bonds/ntnb.py +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/conftest.py +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/data_cache.py +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/date_converter.py +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/di.py +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/holidays/__init__.py +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/holidays/br_holidays_new.txt +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/holidays/br_holidays_old.txt +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/holidays/brholidays.py +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/indicators.py +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/projections.py +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/py.typed +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyield/tools.py +0 -0
- {pyield-0.24.1 → pyield-0.24.2}/pyproject.toml +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.24.2"
|
|
@@ -3,7 +3,7 @@ from collections.abc import Callable
|
|
|
3
3
|
import numpy as np
|
|
4
4
|
import pandas as pd
|
|
5
5
|
|
|
6
|
-
from pyield import anbima, bday, di
|
|
6
|
+
from pyield import anbima, bday, data_cache, di
|
|
7
7
|
from pyield import date_converter as dc
|
|
8
8
|
from pyield import interpolator as ip
|
|
9
9
|
from pyield.bonds import bond_tools as bt
|
|
@@ -22,6 +22,17 @@ COUPON_PMT = 48.80885
|
|
|
22
22
|
FINAL_PMT = 1048.80885
|
|
23
23
|
|
|
24
24
|
|
|
25
|
+
def reference_dates() -> pd.Series:
|
|
26
|
+
"""
|
|
27
|
+
Fetch the NTN-F bond reference dates available in the Anbima database.
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
pd.Series: A Series of NTN-F bond reference dates.
|
|
31
|
+
"""
|
|
32
|
+
df = data_cache.get_anbima_dataset().query("BondType == 'NTN-F'")
|
|
33
|
+
return df["ReferenceDate"].drop_duplicates().sort_values().reset_index(drop=True)
|
|
34
|
+
|
|
35
|
+
|
|
25
36
|
def rates(reference_date: DateScalar) -> pd.DataFrame:
|
|
26
37
|
"""
|
|
27
38
|
Fetch the bond indicative rates for the given reference date.
|
|
@@ -22,7 +22,9 @@ class Interpolator:
|
|
|
22
22
|
ValueError: If the interpolation method is not recognized
|
|
23
23
|
|
|
24
24
|
Note:
|
|
25
|
-
This class uses a 252 business days per year convention.
|
|
25
|
+
- This class uses a 252 business days per year convention.
|
|
26
|
+
- Instances of this class are **immutable**. To modify the interpolation
|
|
27
|
+
settings, create a new instance.
|
|
26
28
|
|
|
27
29
|
Examples:
|
|
28
30
|
>>> from pyield import Interpolator
|
|
@@ -43,34 +45,21 @@ class Interpolator:
|
|
|
43
45
|
def __init__(
|
|
44
46
|
self,
|
|
45
47
|
method: Literal["flat_forward", "linear"],
|
|
46
|
-
known_bdays: pd.Series | list[int],
|
|
47
|
-
known_rates: pd.Series | list[float],
|
|
48
|
+
known_bdays: pd.Series | np.ndarray | tuple[int] | list[int],
|
|
49
|
+
known_rates: pd.Series | np.ndarray | tuple[float] | list[float],
|
|
48
50
|
extrapolate: bool = False,
|
|
49
51
|
):
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if isinstance(known_bdays, pd.Series):
|
|
62
|
-
known_bdays = known_bdays.to_list()
|
|
63
|
-
if isinstance(known_rates, pd.Series):
|
|
64
|
-
known_rates = known_rates.to_list()
|
|
65
|
-
|
|
66
|
-
if len(known_bdays) != len(known_rates):
|
|
67
|
-
raise ValueError("known_bdays and known_rates must have the same length.")
|
|
68
|
-
|
|
69
|
-
df = pd.DataFrame({"bday": known_bdays, "rate": known_rates})
|
|
70
|
-
df = df.dropna().drop_duplicates(subset="bday").sort_values("bday")
|
|
71
|
-
|
|
72
|
-
self._known_bdays = df["bday"].to_list()
|
|
73
|
-
self._known_rates = df["rate"].to_list()
|
|
52
|
+
df = (
|
|
53
|
+
pd.DataFrame({"bday": known_bdays, "rate": known_rates})
|
|
54
|
+
.dropna()
|
|
55
|
+
.drop_duplicates(subset="bday")
|
|
56
|
+
.sort_values("bday", ignore_index=True)
|
|
57
|
+
)
|
|
58
|
+
self._df = df
|
|
59
|
+
self._method = method
|
|
60
|
+
self._known_bdays = tuple(df["bday"])
|
|
61
|
+
self._known_rates = tuple(df["rate"])
|
|
62
|
+
self._extrapolate = bool(extrapolate)
|
|
74
63
|
|
|
75
64
|
def _flat_forward(self, bday: int) -> float:
|
|
76
65
|
"""Performs the interest rate interpolation using the flat forward method."""
|
|
@@ -90,11 +79,6 @@ class Interpolator:
|
|
|
90
79
|
c = (bday - prev_bday) / (next_bday - prev_bday)
|
|
91
80
|
return (a * (b / a) ** c) ** (252 / bday) - 1
|
|
92
81
|
|
|
93
|
-
def _linear(self, bday: int) -> float:
|
|
94
|
-
"""Performs linear interpolation."""
|
|
95
|
-
np_float = np.interp(bday, self._known_bdays, self._known_rates)
|
|
96
|
-
return float(np_float)
|
|
97
|
-
|
|
98
82
|
def interpolate(self, bday: int) -> float:
|
|
99
83
|
"""
|
|
100
84
|
Finds the appropriate interpolation point and returns the interest rate
|
|
@@ -114,17 +98,14 @@ class Interpolator:
|
|
|
114
98
|
elif bday in self._known_bdays:
|
|
115
99
|
return self._known_rates[self._known_bdays.index(bday)]
|
|
116
100
|
elif bday > self._known_bdays[-1]:
|
|
117
|
-
if self.
|
|
118
|
-
return self._known_rates[-1]
|
|
119
|
-
else:
|
|
120
|
-
return float("NaN") # Return NaN if extrapolation is not allowed
|
|
101
|
+
return self._known_rates[-1] if self._extrapolate else float("NaN")
|
|
121
102
|
|
|
122
|
-
if self.
|
|
103
|
+
if self._method == "flat_forward":
|
|
123
104
|
return self._flat_forward(bday)
|
|
124
|
-
elif self.
|
|
125
|
-
return
|
|
105
|
+
elif self._method == "linear":
|
|
106
|
+
return float(np.interp(bday, self._known_bdays, self._known_rates))
|
|
126
107
|
else:
|
|
127
|
-
raise ValueError(f"Unknown interpolation method: {self.
|
|
108
|
+
raise ValueError(f"Unknown interpolation method: {self._method}.")
|
|
128
109
|
|
|
129
110
|
def __call__(self, bday: int) -> float:
|
|
130
111
|
"""
|
|
@@ -139,3 +120,10 @@ class Interpolator:
|
|
|
139
120
|
number of business days.
|
|
140
121
|
"""
|
|
141
122
|
return self.interpolate(bday)
|
|
123
|
+
|
|
124
|
+
def __repr__(self) -> str:
|
|
125
|
+
"""
|
|
126
|
+
Textual representation, used in terminal or scripts.
|
|
127
|
+
"""
|
|
128
|
+
|
|
129
|
+
return repr(self._df)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.24.1"
|
|
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
|