PYield 0.17.2__tar.gz → 0.17.4__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.17.2 → pyield-0.17.4}/PKG-INFO +1 -1
- pyield-0.17.4/pyield/__about__.py +1 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyield/__init__.py +2 -1
- {pyield-0.17.2 → pyield-0.17.4}/pyield/bonds/ntnb.py +15 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyield/bonds/ntnf.py +15 -0
- pyield-0.17.4/pyield/calculators.py +54 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyproject.toml +1 -1
- pyield-0.17.2/pyield/__about__.py +0 -1
- {pyield-0.17.2 → pyield-0.17.4}/LICENSE +0 -0
- {pyield-0.17.2 → pyield-0.17.4}/README.md +0 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyield/bday.py +0 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyield/bonds/__init__.py +0 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyield/bonds/bond_tools.py +0 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyield/bonds/lft.py +0 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyield/bonds/ltn.py +0 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyield/data/__init__.py +0 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyield/data/anbima.py +0 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyield/data/data_cache.py +0 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyield/data/di.py +0 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyield/data/futures_data/__init__.py +0 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyield/data/futures_data/common.py +0 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyield/data/futures_data/historical.py +0 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyield/data/futures_data/intraday.py +0 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyield/data/futures_data/xml.py +0 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyield/data/indicators.py +0 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyield/data/projections.py +0 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyield/date_converter.py +0 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyield/holidays/__init__.py +0 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyield/holidays/br_holidays_new.txt +0 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyield/holidays/br_holidays_old.txt +0 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyield/holidays/holidays_manager.py +0 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyield/interpolator.py +0 -0
- {pyield-0.17.2 → pyield-0.17.4}/pyield/py.typed +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.17.4"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from . import bday
|
|
1
|
+
from . import bday, calculators
|
|
2
2
|
from .__about__ import __version__
|
|
3
3
|
from .bonds import lft, ltn, ntnb, ntnf
|
|
4
4
|
from .data import anbima, di, futures, indicator, projection
|
|
@@ -17,4 +17,5 @@ __all__ = [
|
|
|
17
17
|
"lft",
|
|
18
18
|
"Interpolator",
|
|
19
19
|
"di",
|
|
20
|
+
"calculators",
|
|
20
21
|
]
|
|
@@ -430,3 +430,18 @@ def bei_rates(
|
|
|
430
430
|
"BEI",
|
|
431
431
|
]
|
|
432
432
|
return df[cols_reordered].copy()
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
def duration(
|
|
436
|
+
settlement: str | pd.Timestamp,
|
|
437
|
+
maturity: str | pd.Timestamp,
|
|
438
|
+
rate: float,
|
|
439
|
+
) -> float:
|
|
440
|
+
settlement = dc.convert_date(settlement)
|
|
441
|
+
maturity = dc.convert_date(maturity)
|
|
442
|
+
|
|
443
|
+
df = cash_flows(settlement, maturity)
|
|
444
|
+
df["BY"] = bday.count(settlement, df["PaymentDate"]) / 252
|
|
445
|
+
df["DCF"] = df["CashFlow"] / (1 + rate) ** df["BY"]
|
|
446
|
+
np_duration = (df["DCF"] * df["BY"]).sum() / df["DCF"].sum()
|
|
447
|
+
return float(np_duration)
|
|
@@ -491,3 +491,18 @@ def historical_premium(
|
|
|
491
491
|
factor_di = (1 + di_ytm) ** (1 / 252)
|
|
492
492
|
|
|
493
493
|
return float((factor_ntnf - 1) / (factor_di - 1))
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
def duration(
|
|
497
|
+
settlement: str | pd.Timestamp,
|
|
498
|
+
maturity: str | pd.Timestamp,
|
|
499
|
+
rate: float,
|
|
500
|
+
) -> float:
|
|
501
|
+
settlement = dc.convert_date(settlement)
|
|
502
|
+
maturity = dc.convert_date(maturity)
|
|
503
|
+
|
|
504
|
+
df = cash_flows(settlement, maturity)
|
|
505
|
+
df["BY"] = bday.count(settlement, df["PaymentDate"]) / 252
|
|
506
|
+
df["DCF"] = df["CashFlow"] / (1 + rate) ** df["BY"]
|
|
507
|
+
np_duration = (df["DCF"] * df["BY"]).sum() / df["DCF"].sum()
|
|
508
|
+
return float(np_duration)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pandas as pd
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def forward_rates(
|
|
6
|
+
bdays: pd.Series,
|
|
7
|
+
zero_rates: pd.Series,
|
|
8
|
+
groupby_dates: pd.Series | None = None,
|
|
9
|
+
) -> pd.Series:
|
|
10
|
+
"""Calculates forward rates from zero rates.
|
|
11
|
+
|
|
12
|
+
Args:
|
|
13
|
+
bdays (pd.Series): Number of business days corresponding to the zero rates.
|
|
14
|
+
zero_rates (pd.Series): Zero rates corresponding to the business days.
|
|
15
|
+
groupby_dates (pd.Series | None, optional): Optional grouping criteria to
|
|
16
|
+
segment calculations. If not provided, calculations will not be grouped.
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
pd.Series: Series of calculated forward rates with the last rate set to the last
|
|
20
|
+
zero rate in the input series.
|
|
21
|
+
"""
|
|
22
|
+
# Reset Series indexes to avoid misalignment issues during calculations
|
|
23
|
+
bdays = bdays.reset_index(drop=True)
|
|
24
|
+
zero_rates = zero_rates.reset_index(drop=True)
|
|
25
|
+
if groupby_dates is not None:
|
|
26
|
+
groupby_dates = groupby_dates.reset_index(drop=True)
|
|
27
|
+
|
|
28
|
+
# Create a DataFrame to work with the given series
|
|
29
|
+
df = pd.DataFrame({"bdays": bdays, "zero_rates": zero_rates})
|
|
30
|
+
|
|
31
|
+
# If no groupby_dates is provided, create a dummy column to group the DataFrame
|
|
32
|
+
if groupby_dates is not None:
|
|
33
|
+
df["groupby_dates"] = groupby_dates
|
|
34
|
+
else:
|
|
35
|
+
df["groupby_dates"] = 0
|
|
36
|
+
|
|
37
|
+
# Sort by the groupby_dates and bdays columns to ensure proper chronological order
|
|
38
|
+
df.sort_values(by=["groupby_dates", "bdays"], inplace=True)
|
|
39
|
+
|
|
40
|
+
# Calculate the next zero rate and business day for each group
|
|
41
|
+
df["next_rate"] = df.groupby("groupby_dates")["zero_rates"].shift(-1)
|
|
42
|
+
df["next_bday"] = df.groupby("groupby_dates")["bdays"].shift(-1)
|
|
43
|
+
|
|
44
|
+
# Calculate the forward rates using the formula
|
|
45
|
+
factor1 = (1 + df["next_rate"]) ** (df["next_bday"] / 252)
|
|
46
|
+
factor2 = (1 + df["zero_rates"]) ** (df["bdays"] / 252)
|
|
47
|
+
factor3 = 252 / (df["next_bday"] - df["bdays"])
|
|
48
|
+
fwd_rates = (factor1 / factor2) ** factor3 - 1
|
|
49
|
+
|
|
50
|
+
# Replace the last forward rate with the last zero rate
|
|
51
|
+
mask = df["zero_rates"].notnull() & (fwd_rates.isnull())
|
|
52
|
+
fwd_rates = np.where(mask, df["zero_rates"], fwd_rates)
|
|
53
|
+
|
|
54
|
+
return pd.Series(fwd_rates).astype("Float64")
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.17.2"
|
|
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
|