PYield 0.22.1__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.
- {pyield-0.22.1 → pyield-0.22.2}/PKG-INFO +1 -1
- pyield-0.22.2/pyield/__about__.py +1 -0
- {pyield-0.22.1 → pyield-0.22.2}/pyield/bonds/bond_tools.py +3 -4
- {pyield-0.22.1 → pyield-0.22.2}/pyield/bonds/ltn.py +61 -1
- {pyield-0.22.1 → pyield-0.22.2}/pyield/bonds/ntnf.py +94 -3
- {pyield-0.22.1 → pyield-0.22.2}/pyproject.toml +1 -1
- pyield-0.22.1/pyield/__about__.py +0 -1
- {pyield-0.22.1 → pyield-0.22.2}/LICENSE +0 -0
- {pyield-0.22.1 → pyield-0.22.2}/README.md +0 -0
- {pyield-0.22.1 → pyield-0.22.2}/pyield/__init__.py +0 -0
- {pyield-0.22.1 → pyield-0.22.2}/pyield/anbima.py +0 -0
- {pyield-0.22.1 → pyield-0.22.2}/pyield/b3_futures/__init__.py +0 -0
- {pyield-0.22.1 → pyield-0.22.2}/pyield/b3_futures/common.py +0 -0
- {pyield-0.22.1 → pyield-0.22.2}/pyield/b3_futures/historical.py +0 -0
- {pyield-0.22.1 → pyield-0.22.2}/pyield/b3_futures/intraday.py +0 -0
- {pyield-0.22.1 → pyield-0.22.2}/pyield/b3_futures/xml.py +0 -0
- {pyield-0.22.1 → pyield-0.22.2}/pyield/bday.py +0 -0
- {pyield-0.22.1 → pyield-0.22.2}/pyield/bonds/__init__.py +0 -0
- {pyield-0.22.1 → pyield-0.22.2}/pyield/bonds/lft.py +0 -0
- {pyield-0.22.1 → pyield-0.22.2}/pyield/bonds/ntnb.py +0 -0
- {pyield-0.22.1 → pyield-0.22.2}/pyield/conftest.py +0 -0
- {pyield-0.22.1 → pyield-0.22.2}/pyield/data_cache.py +0 -0
- {pyield-0.22.1 → pyield-0.22.2}/pyield/date_converter.py +0 -0
- {pyield-0.22.1 → pyield-0.22.2}/pyield/di.py +0 -0
- {pyield-0.22.1 → pyield-0.22.2}/pyield/holidays/__init__.py +0 -0
- {pyield-0.22.1 → pyield-0.22.2}/pyield/holidays/br_holidays_new.txt +0 -0
- {pyield-0.22.1 → pyield-0.22.2}/pyield/holidays/br_holidays_old.txt +0 -0
- {pyield-0.22.1 → pyield-0.22.2}/pyield/holidays/brholidays.py +0 -0
- {pyield-0.22.1 → pyield-0.22.2}/pyield/indicators.py +0 -0
- {pyield-0.22.1 → pyield-0.22.2}/pyield/interpolator.py +0 -0
- {pyield-0.22.1 → pyield-0.22.2}/pyield/projections.py +0 -0
- {pyield-0.22.1 → pyield-0.22.2}/pyield/py.typed +0 -0
- {pyield-0.22.1 → pyield-0.22.2}/pyield/tools.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.22.2"
|
|
@@ -73,9 +73,8 @@ def di_spreads(reference_date: str | pd.Timestamp) -> pd.DataFrame:
|
|
|
73
73
|
business day according to the Brazilian calendar.
|
|
74
74
|
|
|
75
75
|
Returns:
|
|
76
|
-
pd.DataFrame: DataFrame containing the bond type,
|
|
77
|
-
|
|
78
|
-
bond type and maturity date.
|
|
76
|
+
pd.DataFrame: DataFrame containing the bond type, maturity date and the
|
|
77
|
+
calculated spread in basis points.
|
|
79
78
|
"""
|
|
80
79
|
# Fetch DI rates for the reference date
|
|
81
80
|
reference_date = dc.convert_input_dates(reference_date)
|
|
@@ -105,5 +104,5 @@ def di_spreads(reference_date: str | pd.Timestamp) -> pd.DataFrame:
|
|
|
105
104
|
|
|
106
105
|
# Prepare and return the final sorted DataFrame
|
|
107
106
|
df_spreads = df_spreads.sort_values(["BondType", "MaturityDate"], ignore_index=True)
|
|
108
|
-
select_columns = ["BondType", "
|
|
107
|
+
select_columns = ["BondType", "MaturityDate", "DISpread"]
|
|
109
108
|
return df_spreads[select_columns].copy()
|
|
@@ -17,6 +17,24 @@ def rates(reference_date: str | pd.Timestamp) -> pd.DataFrame:
|
|
|
17
17
|
|
|
18
18
|
Returns:
|
|
19
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
|
+
|
|
20
38
|
"""
|
|
21
39
|
ltn_rates = anbima.rates(reference_date, "LTN")
|
|
22
40
|
if ltn_rates.empty:
|
|
@@ -33,9 +51,29 @@ def maturities(reference_date: str | pd.Timestamp) -> pd.Series:
|
|
|
33
51
|
|
|
34
52
|
Returns:
|
|
35
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
|
+
|
|
36
72
|
"""
|
|
37
73
|
df_rates = rates(reference_date)
|
|
38
|
-
|
|
74
|
+
s_maturities = df_rates["MaturityDate"]
|
|
75
|
+
s_maturities.name = None
|
|
76
|
+
return s_maturities
|
|
39
77
|
|
|
40
78
|
|
|
41
79
|
def price(
|
|
@@ -94,6 +132,23 @@ def di_spreads(reference_date: str | pd.Timestamp) -> pd.DataFrame:
|
|
|
94
132
|
|
|
95
133
|
Returns:
|
|
96
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
|
|
97
152
|
"""
|
|
98
153
|
# Fetch DI Spreads for the reference date
|
|
99
154
|
df = bt.di_spreads(reference_date)
|
|
@@ -142,6 +197,11 @@ def historical_premium(
|
|
|
142
197
|
Returns:
|
|
143
198
|
float: The premium of the LTN bond over the DI Future rate for the given date.
|
|
144
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
|
+
|
|
145
205
|
"""
|
|
146
206
|
# Convert input dates to a consistent format
|
|
147
207
|
reference_date = dc.convert_input_dates(reference_date)
|
|
@@ -31,6 +31,16 @@ def rates(reference_date: str | pd.Timestamp) -> pd.DataFrame:
|
|
|
31
31
|
|
|
32
32
|
Returns:
|
|
33
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
|
|
34
44
|
"""
|
|
35
45
|
ntnf_rates = anbima.rates(reference_date, "NTN-F")
|
|
36
46
|
if ntnf_rates.empty:
|
|
@@ -47,9 +57,22 @@ def maturities(reference_date: str | pd.Timestamp) -> pd.Series:
|
|
|
47
57
|
|
|
48
58
|
Returns:
|
|
49
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
|
+
|
|
50
71
|
"""
|
|
51
72
|
df_rates = rates(reference_date)
|
|
52
|
-
|
|
73
|
+
s_maturities = df_rates["MaturityDate"]
|
|
74
|
+
s_maturities.name = None
|
|
75
|
+
return s_maturities
|
|
53
76
|
|
|
54
77
|
|
|
55
78
|
def _check_maturity_date(maturity: pd.Timestamp) -> None:
|
|
@@ -299,11 +322,25 @@ def di_spreads(reference_date: str | pd.Timestamp) -> pd.DataFrame:
|
|
|
299
322
|
|
|
300
323
|
Returns:
|
|
301
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
|
+
|
|
302
336
|
"""
|
|
303
337
|
# Fetch DI Spreads for the reference date
|
|
304
338
|
df = bt.di_spreads(reference_date)
|
|
305
|
-
df
|
|
306
|
-
|
|
339
|
+
df = (
|
|
340
|
+
df.query("BondType == 'NTN-F'")
|
|
341
|
+
.sort_values(["MaturityDate"])
|
|
342
|
+
.reset_index(drop=True)
|
|
343
|
+
)
|
|
307
344
|
return df[["MaturityDate", "DISpread"]]
|
|
308
345
|
|
|
309
346
|
|
|
@@ -390,6 +427,19 @@ def di_net_spread( # noqa
|
|
|
390
427
|
|
|
391
428
|
Returns:
|
|
392
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
|
|
393
443
|
"""
|
|
394
444
|
# Create an interpolator for the DI rates using the flat-forward method
|
|
395
445
|
settlement = dc.convert_input_dates(settlement)
|
|
@@ -433,6 +483,47 @@ def premium(
|
|
|
433
483
|
di_expirations: pd.Series,
|
|
434
484
|
di_rates: pd.Series,
|
|
435
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
|
+
"""
|
|
436
527
|
ntnf_maturity = dc.convert_input_dates(ntnf_maturity)
|
|
437
528
|
settlement = dc.convert_input_dates(settlement)
|
|
438
529
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.22.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
|