PYield 0.22.0__tar.gz → 0.22.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 (33) hide show
  1. {pyield-0.22.0 → pyield-0.22.2}/PKG-INFO +1 -1
  2. pyield-0.22.2/pyield/__about__.py +1 -0
  3. {pyield-0.22.0 → pyield-0.22.2}/pyield/bonds/bond_tools.py +7 -6
  4. {pyield-0.22.0 → pyield-0.22.2}/pyield/bonds/ltn.py +65 -3
  5. {pyield-0.22.0 → pyield-0.22.2}/pyield/bonds/ntnf.py +98 -5
  6. {pyield-0.22.0 → pyield-0.22.2}/pyproject.toml +1 -1
  7. pyield-0.22.0/pyield/__about__.py +0 -1
  8. {pyield-0.22.0 → pyield-0.22.2}/LICENSE +0 -0
  9. {pyield-0.22.0 → pyield-0.22.2}/README.md +0 -0
  10. {pyield-0.22.0 → pyield-0.22.2}/pyield/__init__.py +0 -0
  11. {pyield-0.22.0 → pyield-0.22.2}/pyield/anbima.py +0 -0
  12. {pyield-0.22.0 → pyield-0.22.2}/pyield/b3_futures/__init__.py +0 -0
  13. {pyield-0.22.0 → pyield-0.22.2}/pyield/b3_futures/common.py +0 -0
  14. {pyield-0.22.0 → pyield-0.22.2}/pyield/b3_futures/historical.py +0 -0
  15. {pyield-0.22.0 → pyield-0.22.2}/pyield/b3_futures/intraday.py +0 -0
  16. {pyield-0.22.0 → pyield-0.22.2}/pyield/b3_futures/xml.py +0 -0
  17. {pyield-0.22.0 → pyield-0.22.2}/pyield/bday.py +0 -0
  18. {pyield-0.22.0 → pyield-0.22.2}/pyield/bonds/__init__.py +0 -0
  19. {pyield-0.22.0 → pyield-0.22.2}/pyield/bonds/lft.py +0 -0
  20. {pyield-0.22.0 → pyield-0.22.2}/pyield/bonds/ntnb.py +0 -0
  21. {pyield-0.22.0 → pyield-0.22.2}/pyield/conftest.py +0 -0
  22. {pyield-0.22.0 → pyield-0.22.2}/pyield/data_cache.py +0 -0
  23. {pyield-0.22.0 → pyield-0.22.2}/pyield/date_converter.py +0 -0
  24. {pyield-0.22.0 → pyield-0.22.2}/pyield/di.py +0 -0
  25. {pyield-0.22.0 → pyield-0.22.2}/pyield/holidays/__init__.py +0 -0
  26. {pyield-0.22.0 → pyield-0.22.2}/pyield/holidays/br_holidays_new.txt +0 -0
  27. {pyield-0.22.0 → pyield-0.22.2}/pyield/holidays/br_holidays_old.txt +0 -0
  28. {pyield-0.22.0 → pyield-0.22.2}/pyield/holidays/brholidays.py +0 -0
  29. {pyield-0.22.0 → pyield-0.22.2}/pyield/indicators.py +0 -0
  30. {pyield-0.22.0 → pyield-0.22.2}/pyield/interpolator.py +0 -0
  31. {pyield-0.22.0 → pyield-0.22.2}/pyield/projections.py +0 -0
  32. {pyield-0.22.0 → pyield-0.22.2}/pyield/py.typed +0 -0
  33. {pyield-0.22.0 → pyield-0.22.2}/pyield/tools.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PYield
3
- Version: 0.22.0
3
+ Version: 0.22.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.22.2"
@@ -3,8 +3,9 @@ from typing import overload
3
3
  import numpy as np
4
4
  import pandas as pd
5
5
 
6
- from pyield import anbima, di
6
+ from pyield import anbima
7
7
  from pyield import date_converter as dc
8
+ from pyield.di import DIFutures
8
9
 
9
10
 
10
11
  @overload
@@ -72,13 +73,13 @@ def di_spreads(reference_date: str | pd.Timestamp) -> pd.DataFrame:
72
73
  business day according to the Brazilian calendar.
73
74
 
74
75
  Returns:
75
- pd.DataFrame: DataFrame containing the bond type, reference date, maturity
76
- date, and the calculated spread in basis points. The data is sorted by
77
- bond type and maturity date.
76
+ pd.DataFrame: DataFrame containing the bond type, maturity date and the
77
+ calculated spread in basis points.
78
78
  """
79
79
  # Fetch DI rates for the reference date
80
80
  reference_date = dc.convert_input_dates(reference_date)
81
- df_di = di.data(reference_date, adj_expirations=True)
81
+ di = DIFutures(reference_date, adj_expirations=True)
82
+ df_di = di.data()
82
83
  if "SettlementRate" not in df_di.columns:
83
84
  raise ValueError("DI rates data is missing the 'SettlementRate' column.")
84
85
 
@@ -103,5 +104,5 @@ def di_spreads(reference_date: str | pd.Timestamp) -> pd.DataFrame:
103
104
 
104
105
  # Prepare and return the final sorted DataFrame
105
106
  df_spreads = df_spreads.sort_values(["BondType", "MaturityDate"], ignore_index=True)
106
- select_columns = ["BondType", "ReferenceDate", "MaturityDate", "DISpread"]
107
+ select_columns = ["BondType", "MaturityDate", "DISpread"]
107
108
  return df_spreads[select_columns].copy()
@@ -1,8 +1,9 @@
1
1
  import pandas as pd
2
2
 
3
- from pyield import anbima, bday, di
3
+ from pyield import anbima, bday
4
4
  from pyield import date_converter as dc
5
5
  from pyield.bonds import bond_tools as bt
6
+ from pyield.di import DIFutures
6
7
 
7
8
  FACE_VALUE = 1000
8
9
 
@@ -16,6 +17,24 @@ def rates(reference_date: str | pd.Timestamp) -> pd.DataFrame:
16
17
 
17
18
  Returns:
18
19
  pd.DataFrame: DataFrame with columns "MaturityDate" and "IndicativeRate".
20
+
21
+ Examples:
22
+ >>> yd.ltn.rates("22-08-2024")
23
+ MaturityDate IndicativeRate
24
+ 0 2024-10-01 0.104444
25
+ 1 2025-01-01 0.107555
26
+ 2 2025-04-01 0.111592
27
+ 3 2025-07-01 0.11387
28
+ 4 2025-10-01 0.115483
29
+ 5 2026-01-01 0.116013
30
+ 6 2026-04-01 0.116294
31
+ 7 2026-07-01 0.116743
32
+ 8 2026-10-01 0.116767
33
+ 9 2027-07-01 0.116982
34
+ 10 2028-01-01 0.117289
35
+ 11 2028-07-01 0.117948
36
+ 12 2030-01-01 0.118746
37
+
19
38
  """
20
39
  ltn_rates = anbima.rates(reference_date, "LTN")
21
40
  if ltn_rates.empty:
@@ -32,9 +51,29 @@ def maturities(reference_date: str | pd.Timestamp) -> pd.Series:
32
51
 
33
52
  Returns:
34
53
  pd.Series: A Series of bond maturities available for the reference date.
54
+
55
+ Examples:
56
+ >>> yd.ltn.maturities("22-08-2024")
57
+ 0 2024-10-01
58
+ 1 2025-01-01
59
+ 2 2025-04-01
60
+ 3 2025-07-01
61
+ 4 2025-10-01
62
+ 5 2026-01-01
63
+ 6 2026-04-01
64
+ 7 2026-07-01
65
+ 8 2026-10-01
66
+ 9 2027-07-01
67
+ 10 2028-01-01
68
+ 11 2028-07-01
69
+ 12 2030-01-01
70
+ dtype: datetime64[ns]
71
+
35
72
  """
36
73
  df_rates = rates(reference_date)
37
- return df_rates["MaturityDate"]
74
+ s_maturities = df_rates["MaturityDate"]
75
+ s_maturities.name = None
76
+ return s_maturities
38
77
 
39
78
 
40
79
  def price(
@@ -93,6 +132,23 @@ def di_spreads(reference_date: str | pd.Timestamp) -> pd.DataFrame:
93
132
 
94
133
  Returns:
95
134
  pd.DataFrame: DataFrame with the columns "MaturityDate" and "DISpread" (in bps).
135
+
136
+ Examples:
137
+ >>> yd.ltn.di_spreads("22-08-2024")
138
+ MaturityDate DISpread
139
+ 0 2024-10-01 -3.06
140
+ 1 2025-01-01 -9.95
141
+ 2 2025-04-01 -8.28
142
+ 3 2025-07-01 -6.1
143
+ 4 2025-10-01 -2.57
144
+ 5 2026-01-01 -1.57
145
+ 6 2026-04-01 -0.86
146
+ 7 2026-07-01 2.83
147
+ 8 2026-10-01 4.17
148
+ 9 2027-07-01 3.72
149
+ 10 2028-01-01 6.19
150
+ 11 2028-07-01 8.68
151
+ 12 2030-01-01 14.96
96
152
  """
97
153
  # Fetch DI Spreads for the reference date
98
154
  df = bt.di_spreads(reference_date)
@@ -141,6 +197,11 @@ def historical_premium(
141
197
  Returns:
142
198
  float: The premium of the LTN bond over the DI Future rate for the given date.
143
199
  If the data is not available, returns NaN.
200
+
201
+ Example:
202
+ >>> yd.ltn.historical_premium("22-08-2024", "01-01-2030")
203
+ 1.012072
204
+
144
205
  """
145
206
  # Convert input dates to a consistent format
146
207
  reference_date = dc.convert_input_dates(reference_date)
@@ -158,7 +219,8 @@ def historical_premium(
158
219
  ltn_rate = float(ltn_rates.iloc[0])
159
220
 
160
221
  # Retrieve DI rate for the reference date and maturity
161
- di_rate = di.rate(trade_date=reference_date, expiration=maturity)
222
+ di = DIFutures(trade_date=reference_date)
223
+ di_rate = di.rate(expiration=maturity)
162
224
  if pd.isnull(di_rate): # Check if the DI rate is NaN
163
225
  return float("NaN")
164
226
 
@@ -3,9 +3,10 @@ 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
7
7
  from pyield import date_converter as dc
8
8
  from pyield.bonds import bond_tools as bt
9
+ from pyield.di import DIFutures
9
10
  from pyield.interpolator import Interpolator
10
11
 
11
12
  """
@@ -30,6 +31,16 @@ def rates(reference_date: str | pd.Timestamp) -> pd.DataFrame:
30
31
 
31
32
  Returns:
32
33
  pd.DataFrame: DataFrame with columns "MaturityDate" and "IndicativeRate".
34
+
35
+ Examples:
36
+ >>> yd.ntnf.rates("23-08-2024")
37
+ MaturityDate IndicativeRate
38
+ 0 2025-01-01 0.107692
39
+ 1 2027-01-01 0.115109
40
+ 2 2029-01-01 0.116337
41
+ 3 2031-01-01 0.117008
42
+ 4 2033-01-01 0.116307
43
+ 5 2035-01-01 0.116586
33
44
  """
34
45
  ntnf_rates = anbima.rates(reference_date, "NTN-F")
35
46
  if ntnf_rates.empty:
@@ -46,9 +57,22 @@ def maturities(reference_date: str | pd.Timestamp) -> pd.Series:
46
57
 
47
58
  Returns:
48
59
  pd.Series: A Series of NTN-F bond maturities available for the reference date.
60
+
61
+ Examples:
62
+ >>> yd.ntnf.maturities("23-08-2024")
63
+ 0 2025-01-01
64
+ 1 2027-01-01
65
+ 2 2029-01-01
66
+ 3 2031-01-01
67
+ 4 2033-01-01
68
+ 5 2035-01-01
69
+ dtype: datetime64[ns]
70
+
49
71
  """
50
72
  df_rates = rates(reference_date)
51
- return df_rates["MaturityDate"]
73
+ s_maturities = df_rates["MaturityDate"]
74
+ s_maturities.name = None
75
+ return s_maturities
52
76
 
53
77
 
54
78
  def _check_maturity_date(maturity: pd.Timestamp) -> None:
@@ -298,11 +322,25 @@ def di_spreads(reference_date: str | pd.Timestamp) -> pd.DataFrame:
298
322
 
299
323
  Returns:
300
324
  pd.DataFrame: DataFrame with columns "MaturityDate", "DISpread".
325
+
326
+ Examples:
327
+ >>> yd.ntnf.di_spreads("23-08-2024")
328
+ MaturityDate DISpread
329
+ 0 2025-01-01 -5.38
330
+ 1 2027-01-01 4.39
331
+ 2 2029-01-01 7.37
332
+ 3 2031-01-01 12.58
333
+ 4 2033-01-01 7.67
334
+ 5 2035-01-01 12.76
335
+
301
336
  """
302
337
  # Fetch DI Spreads for the reference date
303
338
  df = bt.di_spreads(reference_date)
304
- df.query("BondType == 'NTN-F'", inplace=True)
305
- df.sort_values(["MaturityDate"], ignore_index=True, inplace=True)
339
+ df = (
340
+ df.query("BondType == 'NTN-F'")
341
+ .sort_values(["MaturityDate"])
342
+ .reset_index(drop=True)
343
+ )
306
344
  return df[["MaturityDate", "DISpread"]]
307
345
 
308
346
 
@@ -389,6 +427,19 @@ def di_net_spread( # noqa
389
427
 
390
428
  Returns:
391
429
  float: The net DI spread in basis points.
430
+
431
+ Example:
432
+ # Obs: only some of the DI rates will be used in the example.
433
+ >>> exp_dates = pd.to_datetime(["2025-01-01", "2030-01-01", "2035-01-01"])
434
+ >>> di_rates = pd.Series([0.10823, 0.11594, 0.11531])
435
+ >>> di_net_spread(
436
+ ... settlement="23-08-2024",
437
+ ... ntnf_maturity="01-01-2035",
438
+ ... ntnf_rate=0.116586,
439
+ ... di_expirations=exp_dates,
440
+ ... di_rates=di_rates,
441
+ ... )
442
+ 12.13
392
443
  """
393
444
  # Create an interpolator for the DI rates using the flat-forward method
394
445
  settlement = dc.convert_input_dates(settlement)
@@ -432,6 +483,47 @@ def premium(
432
483
  di_expirations: pd.Series,
433
484
  di_rates: pd.Series,
434
485
  ) -> float:
486
+ """
487
+ Calculate the premium of an NTN-F bond over DI rates.
488
+
489
+ This function computes the premium of an NTN-F bond by comparing its implied
490
+ discount factor with that of the DI curve. It determines the net premium based
491
+ on the difference between the discount factors of the bond's yield-to-maturity
492
+ (YTM) and the interpolated DI rates.
493
+
494
+ Args:
495
+ settlement (str | pd.Timestamp): The settlement date in 'DD-MM-YYYY' format
496
+ or a pandas Timestamp.
497
+ ntnf_maturity (str | pd.Timestamp): The maturity date of the NTN-F bond in
498
+ 'DD-MM-YYYY' format or a pandas Timestamp.
499
+ ntnf_rate (float): The yield to maturity (YTM) of the NTN-F bond.
500
+ di_expirations (pd.Series): Series containing the expiration dates for DI
501
+ rates. di_rates (pd.Series): Series containing the DI rates corresponding to
502
+ the
503
+ expiration dates.
504
+
505
+ Returns:
506
+ float: The premium of the NTN-F bond over the DI curve, expressed as a
507
+ factor.
508
+
509
+ Example:
510
+ # Obs: only some of the DI rates will be used in the example.
511
+ >>> exp_dates = pd.to_datetime(["2025-01-01", "2030-01-01", "2035-01-01"])
512
+ >>> di_rates = pd.Series([0.10823, 0.11594, 0.11531])
513
+ >>> premium(
514
+ ... settlement="23-08-2024",
515
+ ... ntnf_maturity="01-01-2035",
516
+ ... ntnf_rate=0.116586,
517
+ ... di_expirations=exp_dates,
518
+ ... di_rates=di_rates,
519
+ ... )
520
+ 1.00996
521
+
522
+ Notes:
523
+ - The function adjusts coupon payment dates to business days and calculates
524
+ the present value of cash flows for the NTN-F bond using DI rates.
525
+
526
+ """
435
527
  ntnf_maturity = dc.convert_input_dates(ntnf_maturity)
436
528
  settlement = dc.convert_input_dates(settlement)
437
529
 
@@ -487,7 +579,8 @@ def historical_premium(
487
579
  df = cash_flows(reference_date, maturity, adj_payment_dates=True)
488
580
  df["BDays"] = bday.count(reference_date, df["PaymentDate"])
489
581
  df["BYears"] = df["BDays"] / 252
490
- df["DIRate"] = df["PaymentDate"].apply(lambda x: di.rate(reference_date, x))
582
+ di = DIFutures(reference_date)
583
+ df["DIRate"] = df["PaymentDate"].apply(di.rate)
491
584
 
492
585
  # Calculate the present value of the cash flows using the DI rate
493
586
  bond_price = bt.calculate_present_value(
@@ -32,7 +32,7 @@ dependencies = [
32
32
  "types-requests",
33
33
  ]
34
34
  dynamic = []
35
- version = "0.22.0"
35
+ version = "0.22.2"
36
36
 
37
37
  [project.license]
38
38
  file = "LICENSE"
@@ -1 +0,0 @@
1
- __version__ = "0.22.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