PYield 0.13.1__tar.gz → 0.13.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.
Files changed (37) hide show
  1. {pyield-0.13.1 → pyield-0.13.2}/PKG-INFO +1 -1
  2. pyield-0.13.2/pyield/__about__.py +1 -0
  3. {pyield-0.13.1 → pyield-0.13.2}/pyield/bonds/lft.py +4 -3
  4. {pyield-0.13.1 → pyield-0.13.2}/pyield/bonds/ltn.py +4 -3
  5. {pyield-0.13.1 → pyield-0.13.2}/pyield/bonds/ntnb.py +25 -20
  6. {pyield-0.13.1 → pyield-0.13.2}/pyield/bonds/ntnf.py +43 -54
  7. {pyield-0.13.1 → pyield-0.13.2}/pyield/fetchers/anbima.py +6 -50
  8. {pyield-0.13.1 → pyield-0.13.2}/pyproject.toml +1 -1
  9. pyield-0.13.1/pyield/__about__.py +0 -1
  10. {pyield-0.13.1 → pyield-0.13.2}/LICENSE +0 -0
  11. {pyield-0.13.1 → pyield-0.13.2}/README.md +0 -0
  12. {pyield-0.13.1 → pyield-0.13.2}/pyield/__init__.py +0 -0
  13. {pyield-0.13.1 → pyield-0.13.2}/pyield/bday.py +0 -0
  14. {pyield-0.13.1 → pyield-0.13.2}/pyield/bonds/__init__.py +0 -0
  15. {pyield-0.13.1 → pyield-0.13.2}/pyield/bonds/utils.py +0 -0
  16. {pyield-0.13.1 → pyield-0.13.2}/pyield/date_converter.py +0 -0
  17. {pyield-0.13.1 → pyield-0.13.2}/pyield/di.py +0 -0
  18. {pyield-0.13.1 → pyield-0.13.2}/pyield/fetchers/__init__.py +0 -0
  19. {pyield-0.13.1 → pyield-0.13.2}/pyield/fetchers/futures_data/__init__.py +0 -0
  20. {pyield-0.13.1 → pyield-0.13.2}/pyield/fetchers/futures_data/common.py +0 -0
  21. {pyield-0.13.1 → pyield-0.13.2}/pyield/fetchers/futures_data/historical.py +0 -0
  22. {pyield-0.13.1 → pyield-0.13.2}/pyield/fetchers/futures_data/intraday.py +0 -0
  23. {pyield-0.13.1 → pyield-0.13.2}/pyield/fetchers/futures_data/xml.py +0 -0
  24. {pyield-0.13.1 → pyield-0.13.2}/pyield/fetchers/indicators.py +0 -0
  25. {pyield-0.13.1 → pyield-0.13.2}/pyield/fetchers/projections.py +0 -0
  26. {pyield-0.13.1 → pyield-0.13.2}/pyield/holidays/__init__.py +0 -0
  27. {pyield-0.13.1 → pyield-0.13.2}/pyield/holidays/br_holidays_new.txt +0 -0
  28. {pyield-0.13.1 → pyield-0.13.2}/pyield/holidays/br_holidays_old.txt +0 -0
  29. {pyield-0.13.1 → pyield-0.13.2}/pyield/holidays/holidays_manager.py +0 -0
  30. {pyield-0.13.1 → pyield-0.13.2}/pyield/interpolator.py +0 -0
  31. {pyield-0.13.1 → pyield-0.13.2}/pyield/py.typed +0 -0
  32. {pyield-0.13.1 → pyield-0.13.2}/tests/__init__.py +0 -0
  33. {pyield-0.13.1 → pyield-0.13.2}/tests/data/SPRD231222.zip +0 -0
  34. {pyield-0.13.1 → pyield-0.13.2}/tests/data/SPRD240426.zip +0 -0
  35. {pyield-0.13.1 → pyield-0.13.2}/tests/test_bday.py +0 -0
  36. {pyield-0.13.1 → pyield-0.13.2}/tests/test_futures.py +0 -0
  37. {pyield-0.13.1 → pyield-0.13.2}/tests/test_futures_xml.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PYield
3
- Version: 0.13.1
3
+ Version: 0.13.2
4
4
  Summary: A Python library for analysis of fixed income instruments in Brazil
5
5
  Keywords: fixed-income, brazil, finance, analysis, bonds
6
6
  Author-Email: Carlos Carvalho <cr.cj@outlook.com>
@@ -0,0 +1 @@
1
+ __version__ = "0.13.2"
@@ -21,15 +21,16 @@ def anbima_data(reference_date: str | pd.Timestamp) -> pd.DataFrame:
21
21
 
22
22
  def indicative_rates(reference_date: str | pd.Timestamp) -> pd.Series:
23
23
  """
24
- Fetch LFT Anbima indicative rates for the given reference date.
24
+ Fetch the bond indicative rates for the given reference date.
25
25
 
26
26
  Args:
27
27
  reference_date (str | pd.Timestamp): The reference date for fetching the data.
28
28
 
29
29
  Returns:
30
- pd.Series: A Series containing the rates indexed by maturity date.
30
+ pd.Series: A Series containing the bond rates indexed by maturity date.
31
31
  """
32
- return an.get_anbima_rates(reference_date, "LFT")
32
+ df = an.anbima_rates(reference_date, "LFT")
33
+ return df.set_index("MaturityDate")["IndicativeRate"]
33
34
 
34
35
 
35
36
  def maturities(reference_date: str | pd.Timestamp) -> list[pd.Timestamp]:
@@ -23,15 +23,16 @@ def anbima_data(reference_date: str | pd.Timestamp) -> pd.DataFrame:
23
23
 
24
24
  def indicative_rates(reference_date: str | pd.Timestamp) -> pd.Series:
25
25
  """
26
- Fetch LTN Anbima indicative rates for the given reference date.
26
+ Fetch the bond indicative rates for the given reference date.
27
27
 
28
28
  Args:
29
29
  reference_date (str | pd.Timestamp): The reference date for fetching the data.
30
30
 
31
31
  Returns:
32
- pd.Series: A Series containing the rates indexed by maturity date.
32
+ pd.Series: A Series containing the bond rates indexed by maturity date.
33
33
  """
34
- return an.get_anbima_rates(reference_date, "LTN")
34
+ df = an.anbima_rates(reference_date, "LTN")
35
+ return df.set_index("MaturityDate")["IndicativeRate"]
35
36
 
36
37
 
37
38
  def maturities(reference_date: str | pd.Timestamp) -> list[pd.Timestamp]:
@@ -36,15 +36,16 @@ def anbima_data(reference_date: str | pd.Timestamp) -> pd.DataFrame:
36
36
 
37
37
  def indicative_rates(reference_date: str | pd.Timestamp) -> pd.Series:
38
38
  """
39
- Fetch NTN-B Anbima indicative rates for the given reference date.
39
+ Fetch the bond indicative rates for the given reference date.
40
40
 
41
41
  Args:
42
42
  reference_date (str | pd.Timestamp): The reference date for fetching the data.
43
43
 
44
44
  Returns:
45
- pd.Series: A Series containing the rates indexed by maturity date.
45
+ pd.Series: A Series containing the bond rates indexed by maturity date.
46
46
  """
47
- return an.get_anbima_rates(reference_date, "NTN-B")
47
+ df = an.anbima_rates(reference_date, "NTN-B")
48
+ return df.set_index("MaturityDate")["IndicativeRate"]
48
49
 
49
50
 
50
51
  def maturities(reference_date: str | pd.Timestamp) -> list[pd.Timestamp]:
@@ -65,7 +66,7 @@ def maturities(reference_date: str | pd.Timestamp) -> list[pd.Timestamp]:
65
66
  def _coupon_dates_map(
66
67
  start: str | pd.Timestamp,
67
68
  end: str | pd.Timestamp,
68
- ) -> pd.Series:
69
+ ) -> list[pd.Timestamp]:
69
70
  """
70
71
  Generate a map of all possible coupon dates between the start and end dates.
71
72
  The dates are inclusive. Coupon payments are made on the 15th of February, May,
@@ -87,20 +88,21 @@ def _coupon_dates_map(
87
88
  first_coupon_date = pd.Timestamp(f"{reference_year}-02-01")
88
89
 
89
90
  # Generate coupon dates
90
- dates = pd.date_range(start=first_coupon_date, end=end, freq="3MS")
91
+ coupon_dates = pd.date_range(start=first_coupon_date, end=end, freq="3MS")
91
92
 
92
93
  # Offset dates by 14 in order to have day 15 of the month
93
- dates += pd.Timedelta(days=14)
94
+ coupon_dates += pd.Timedelta(days=14)
94
95
 
95
96
  # First coupon date must be after the reference date
96
- dates = dates[dates >= start]
97
- return pd.Series(dates).reset_index(drop=True)
97
+ coupon_dates = coupon_dates[coupon_dates >= start]
98
+ coupon_dates = pd.Series(coupon_dates).reset_index(drop=True)
99
+ return coupon_dates.to_list()
98
100
 
99
101
 
100
102
  def coupon_dates(
101
- start: str | pd.Timestamp,
103
+ settlement: str | pd.Timestamp,
102
104
  maturity: str | pd.Timestamp,
103
- ) -> pd.Series:
105
+ ) -> list[pd.Timestamp]:
104
106
  """
105
107
  Generate all remaining coupon dates between a given date and the maturity date.
106
108
  The dates are inclusive. Coupon payments are made on the 15th of February, May,
@@ -108,18 +110,20 @@ def coupon_dates(
108
110
  bond is determined by its maturity date.
109
111
 
110
112
  Args:
111
- start_date (str | pd.Timestamp): The date to start generating coupon dates.
113
+ settlement (str | pd.Timestamp): The settlement date (exlusive) to
114
+ start generating coupon dates.
112
115
  maturity_date (str | pd.Timestamp): The maturity date.
113
116
 
114
117
  Returns:
115
- list[pd.Timestamp]: List of coupon dates between start and maturity dates.
118
+ list[pd.Timestamp]: List of coupon dates between start and maturity dates
119
+ sorted in ascending order.
116
120
  """
117
121
  # Validate and normalize dates
118
- start = dc.convert_date(start)
122
+ settlement = dc.convert_date(settlement)
119
123
  maturity = dc.convert_date(maturity)
120
124
 
121
125
  # Check if maturity date is after the start date
122
- if maturity < start:
126
+ if maturity < settlement:
123
127
  raise ValueError("Maturity date must be after the start date.")
124
128
 
125
129
  # Check if the maturity date is a valid NTN-B maturity date
@@ -127,16 +131,17 @@ def coupon_dates(
127
131
  raise ValueError("NTN-B maturity must be 15/02, 15/05, 15/08, or 15/11.")
128
132
 
129
133
  # Initialize loop variables
130
- cp_date = maturity
134
+ coupon_dates = maturity
131
135
  cp_dates = []
132
136
 
133
137
  # Iterate backwards from the maturity date to the settlement date
134
- while cp_date >= start:
135
- cp_dates.append(cp_date)
138
+ while coupon_dates > settlement:
139
+ cp_dates.append(coupon_dates)
136
140
  # Move the coupon date back 6 months
137
- cp_date -= pd.DateOffset(months=6)
141
+ coupon_dates -= pd.DateOffset(months=6)
138
142
 
139
- return pd.Series(cp_dates).sort_values(ignore_index=True)
143
+ cp_dates = pd.Series(cp_dates).sort_values(ignore_index=True)
144
+ return cp_dates.to_list()
140
145
 
141
146
 
142
147
  def quotation(
@@ -175,7 +180,7 @@ def quotation(
175
180
  maturity = dc.convert_date(maturity)
176
181
 
177
182
  # Get the coupon dates between the settlement and maturity dates
178
- payment_dates = coupon_dates(settlement, maturity)
183
+ payment_dates = pd.Series(coupon_dates(settlement, maturity))
179
184
 
180
185
  # Coupon payment dates must be after the settlement date
181
186
  payment_dates = payment_dates[payment_dates > settlement]
@@ -23,6 +23,48 @@ FINAL_PMT = 1048.80885
23
23
  di_data = di.DIData()
24
24
 
25
25
 
26
+ def maturities(reference_date: str | pd.Timestamp) -> list[pd.Timestamp]:
27
+ """
28
+ Fetch the NTN-F bond maturities available for the given reference date.
29
+
30
+ Args:
31
+ reference_date (str | pd.Timestamp): The reference date for fetching the data.
32
+
33
+ Returns:
34
+ list[pd.Timestamp]: A list of NTN-F bond maturities available for the reference
35
+ date.
36
+ """
37
+ rates = indicative_rates(reference_date)
38
+ return rates.index.to_list()
39
+
40
+
41
+ def anbima_data(reference_date: str | pd.Timestamp) -> pd.DataFrame:
42
+ """
43
+ Fetch NTN-F Anbima data for the given reference date.
44
+
45
+ Args:
46
+ reference_date (str | pd.Timestamp): The reference date for fetching the data.
47
+
48
+ Returns:
49
+ pd.DataFrame: A DataFrame containing the Anbima data for the reference date.
50
+ """
51
+ return an.anbima_data(reference_date, "NTN-F")
52
+
53
+
54
+ def indicative_rates(reference_date: str | pd.Timestamp) -> pd.Series:
55
+ """
56
+ Fetch the bond indicative rates for the given reference date.
57
+
58
+ Args:
59
+ reference_date (str | pd.Timestamp): The reference date for fetching the data.
60
+
61
+ Returns:
62
+ pd.Series: A Series containing the bond rates indexed by maturity date.
63
+ """
64
+ df = an.anbima_rates(reference_date, "NTN-F")
65
+ return df.set_index("MaturityDate")["IndicativeRate"]
66
+
67
+
26
68
  def check_maturity_date(maturity: pd.Timestamp) -> None:
27
69
  """
28
70
  Check if the maturity date is a valid NTN-F maturity date.
@@ -40,7 +82,7 @@ def check_maturity_date(maturity: pd.Timestamp) -> None:
40
82
  def coupon_dates(
41
83
  settlement: str | pd.Timestamp,
42
84
  maturity: str | pd.Timestamp,
43
- ) -> pd.Series:
85
+ ) -> list[pd.Timestamp]:
44
86
  """
45
87
  Generate all remaining coupon dates between a settlement date and a maturity date.
46
88
  The dates are exclusive for the settlement date and inclusive for the maturity date.
@@ -155,59 +197,6 @@ def price(
155
197
  return ut.truncate(dcf.sum(), 6)
156
198
 
157
199
 
158
- def maturities(reference_date: str | pd.Timestamp) -> list[pd.Timestamp]:
159
- """
160
- Fetch the NTN-F bond maturities available for the given reference date.
161
-
162
- Args:
163
- reference_date (str | pd.Timestamp): The reference date for fetching the data.
164
-
165
- Returns:
166
- list[pd.Timestamp]: A list of NTN-F bond maturities available for the reference
167
- date.
168
- """
169
- rates = indicative_rates(reference_date)
170
- return rates.index.to_list()
171
-
172
-
173
- def anbima_data(reference_date: str | pd.Timestamp) -> pd.DataFrame:
174
- """
175
- Fetch NTN-F Anbima data for the given reference date.
176
-
177
- Args:
178
- reference_date (str | pd.Timestamp): The reference date for fetching the data.
179
-
180
- Returns:
181
- pd.DataFrame: A DataFrame containing the Anbima data for the reference date.
182
- """
183
- return an.anbima_data(reference_date, "NTN-F")
184
-
185
-
186
- def indicative_rates(
187
- reference_date: str | pd.Timestamp,
188
- maturity: str | pd.Timestamp | None = None,
189
- ) -> pd.Series | float:
190
- """
191
- Fetch NTN-F Anbima indicative rates for the given reference date. If a maturity date
192
- is provided, the function returns the rate for the given maturity date.
193
-
194
- Args:
195
- reference_date (str | pd.Timestamp): The reference date for fetching the data.
196
- maturity_date (str | pd.Timestamp, optional): The maturity date of the bond.
197
-
198
- Returns:
199
- pd.Series: A Series containing the rates indexed by maturity date.
200
- """
201
- rates = an.get_anbima_rates(reference_date, "NTN-F")
202
- if maturity:
203
- maturity = dc.convert_date(maturity)
204
- if maturity in rates.index:
205
- return float(rates[maturity])
206
- else:
207
- return float("nan")
208
- return rates
209
-
210
-
211
200
  def _calculate_coupons_pv(
212
201
  bootstrap_df: pd.DataFrame,
213
202
  settlement: pd.Timestamp,
@@ -190,8 +190,8 @@ class RatesData:
190
190
  ) -> pd.DataFrame:
191
191
  cls._check_for_updates()
192
192
  df = cls._df.copy()
193
- if reference_date is not None:
194
- df.query("ReferenceDate == @reference_date", inplace=True)
193
+ reference_date = dc.convert_date(reference_date)
194
+ df.query("ReferenceDate == @reference_date", inplace=True)
195
195
  if bond_type is not None:
196
196
  df.query("BondType == @bond_type", inplace=True)
197
197
 
@@ -199,7 +199,7 @@ class RatesData:
199
199
 
200
200
 
201
201
  def anbima_rates(
202
- reference_date: str | pd.Timestamp | None = None,
202
+ reference_date: str | pd.Timestamp,
203
203
  bond_type: str | None = None,
204
204
  ) -> pd.DataFrame:
205
205
  """
@@ -221,53 +221,9 @@ def anbima_rates(
221
221
 
222
222
  Examples:
223
223
  # Fetch ANBIMA rates for all bonds in a specific reference date
224
- >>> yd.anbima("18-06-2024")
224
+ >>> anbima_rates("18-06-2024")
225
225
  # Fetch ANBIMA data for NTN-B bonds in a specific reference date
226
- >>> yd.anbima("NTN-B", "18-06-2024")
226
+ >>> anbima_rates("NTN-B", "18-06-2024")
227
227
  """
228
- if reference_date is not None:
229
- reference_date = dc.convert_date(reference_date)
230
- return RatesData.rates(reference_date, bond_type)
231
-
232
-
233
- def get_anbima_rates(
234
- reference_date: str | pd.Timestamp,
235
- bond_type: str,
236
- ) -> pd.Series:
237
- df = anbima_rates(reference_date, bond_type)
238
- df.drop(columns=["BondType"], inplace=True)
239
- # Set MaturityDate as index
240
- df = df.set_index("MaturityDate")
241
- # Return as Series
242
- return df["IndicativeRate"]
243
-
244
228
 
245
- def get_anbima_historical_rates(
246
- bond_type: str,
247
- maturity_date: str | pd.Timestamp,
248
- ) -> pd.Series:
249
- # Normalize maturity date
250
- maturity_date = dc.convert_date(maturity_date)
251
-
252
- # Get historical rates for the given bond type
253
- df = anbima_rates(bond_type=bond_type)
254
-
255
- # Filter rates for the specified maturity date
256
- df.query("MaturityDate == @maturity_date", inplace=True)
257
-
258
- # Drop unnecessary columns and sort by reference date
259
- df.drop(columns=["BondType", "MaturityDate"], inplace=True)
260
- df.sort_values(["ReferenceDate"], ignore_index=True, inplace=True)
261
-
262
- # Set ReferenceDate as index
263
- df = df.set_index("ReferenceDate")
264
-
265
- # Set the indicative rate as the Series to return
266
- rates = df["IndicativeRate"]
267
-
268
- # Raise an error if no rates are found
269
- if rates.empty:
270
- maturity = maturity_date.strftime("%d-%m-%Y")
271
- raise ValueError(f"No rates found for {bond_type} with maturity {maturity}.")
272
-
273
- return rates
229
+ return RatesData.rates(reference_date, bond_type)
@@ -34,7 +34,7 @@ dependencies = [
34
34
  "pyarrow",
35
35
  ]
36
36
  dynamic = []
37
- version = "0.13.1"
37
+ version = "0.13.2"
38
38
 
39
39
  [project.license]
40
40
  file = "LICENSE"
@@ -1 +0,0 @@
1
- __version__ = "0.13.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