NTN-F
cash_flows(settlement, maturity, adj_payment_dates=False)
Generate the cash flows for the NTN-F bond between the settlement (exclusive) and maturity dates (inclusive). The cash flows are the coupon payments and the final payment at maturity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
settlement
|
DateScalar
|
The date (exclusive) for starting the cash flows. |
required |
maturity
|
DateScalar
|
The maturity date of the bond. |
required |
adj_payment_dates
|
bool
|
If True, adjust the payment dates to the next business day. |
False
|
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: DataFrame with columns "PaymentDate" and "CashFlow". |
Examples:
>>> from pyield import ntnf
>>> ntnf.cash_flows("15-05-2024", "01-01-2025")
PaymentDate CashFlow
0 2024-07-01 48.80885
1 2025-01-01 1048.80885
Source code in pyield/tn/ntnf.py
data(date)
Fetch the bond indicative rates for the given reference date.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
date
|
DateScalar
|
The reference date for fetching the data. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: DataFrame with columns "MaturityDate" and "IndicativeRate". |
Examples:
>>> from pyield import ntnf
>>> ntnf.data("23-08-2024")
ReferenceDate BondType MaturityDate IndicativeRate Price
0 2024-08-23 NTN-F 2025-01-01 0.107692 1011.189166
1 2024-08-23 NTN-F 2027-01-01 0.115109 985.834842
2 2024-08-23 NTN-F 2029-01-01 0.116337 964.126325
3 2024-08-23 NTN-F 2031-01-01 0.117008 945.416939
4 2024-08-23 NTN-F 2033-01-01 0.116307 934.776692
5 2024-08-23 NTN-F 2035-01-01 0.116586 923.239406
Source code in pyield/tn/ntnf.py
di_net_spread(settlement, ntnf_maturity, ntnf_rate, di_expirations, di_rates, initial_guess=None)
Calculate the net DI spread for a bond given the YTM and the DI rates.
This function determines the spread over the DI curve that equates the present value of the bond's cash flows to its market price. It interpolates the DI rates to match the bond's cash flow payment dates and uses the Brent method to find the spread (in bps) that zeroes the difference between the bond's market price and its discounted cash flows.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
settlement
|
DateScalar
|
The settlement date to calculate the spread. |
required |
ntnf_maturity
|
DateScalar
|
The bond maturity date. |
required |
ntnf_rate
|
float
|
The yield to maturity (YTM) of the bond. |
required |
di_rates
|
Series
|
A Series of DI rates. |
required |
di_expirations
|
Series
|
A list or Series of DI expiration dates. |
required |
initial_guess
|
float
|
An initial guess for the spread. Defaults to None. A good initial guess is the DI gross spread for the bond. |
None
|
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The net DI spread in decimal format (e.g., 0.0012 for 12 bps). |
Examples:
Obs: only some of the DI rates will be used in the example.
>>> exp_dates = pd.to_datetime(["2025-01-01", "2030-01-01", "2035-01-01"])
>>> di_rates = pd.Series([0.10823, 0.11594, 0.11531])
>>> spread = di_net_spread(
... settlement="23-08-2024",
... ntnf_maturity="01-01-2035",
... ntnf_rate=0.116586,
... di_expirations=exp_dates,
... di_rates=di_rates,
... )
>>> round(spread * 10_000, 2) # Convert to bps for display
12.13
Source code in pyield/tn/ntnf.py
di_spreads(date)
Calculates the DI spread for the NTN-F based on ANBIMA's indicative rates.
This function fetches the indicative rates for the NTN-F bonds and the DI futures rates and calculates the spread between these rates in basis points.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
date
|
DateScalar
|
The reference date for the spread calculation. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: DataFrame with columns "MaturityDate", "DISpread". |
Examples:
>>> from pyield import ntnf
>>> df_spreads = ntnf.di_spreads("23-08-2024")
>>> df_spreads["DISpread"] = df_spreads["DISpread"] * 10_000 # Convert to bps
>>> df_spreads
MaturityDate DISpread
0 2025-01-01 -5.38
1 2027-01-01 4.39
2 2029-01-01 7.37
3 2031-01-01 12.58
4 2033-01-01 7.67
5 2035-01-01 12.76
Source code in pyield/tn/ntnf.py
duration(settlement, maturity, rate)
Calculate the Macaulay duration for an NTN-F bond in business years.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
settlement
|
DateScalar
|
The settlement date to calculate the duration. |
required |
maturity
|
DateScalar
|
The maturity date of the bond. |
required |
rate
|
float
|
The yield to maturity (YTM) used to discount the cash flows. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The Macaulay duration in business business years. |
Examples:
>>> from pyield import ntnf
>>> ntnf.duration("02-09-2024", "01-01-2035", 0.121785)
6.32854218039796
Source code in pyield/tn/ntnf.py
dv01(settlement, maturity, rate)
Calculate the DV01 (Dollar Value of 01) for an NTN-F in R$.
Represents the price change in R$ for a 1 basis point (0.01%) increase in yield.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
settlement
|
DateScalar
|
The settlement date in 'DD-MM-YYYY' format or a pandas Timestamp. |
required |
maturity
|
DateScalar
|
The maturity date in 'DD-MM-YYYY' format or a pandas Timestamp. |
required |
rate
|
float
|
The discount rate used to calculate the present value of the cash flows, which is the yield to maturity (YTM) of the NTN-F. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The DV01 value, representing the price change for a 1 basis point increase in yield. |
Examples:
Source code in pyield/tn/ntnf.py
maturities(date)
Fetch the NTN-F bond maturities available for the given reference date.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
date
|
DateScalar
|
The reference date for fetching the data. |
required |
Returns:
Type | Description |
---|---|
Series
|
pd.Series: A Series of NTN-F bond maturities available for the reference date. |
Examples:
>>> from pyield import ntnf
>>> ntnf.maturities("23-08-2024")
0 2025-01-01
1 2027-01-01
2 2029-01-01
3 2031-01-01
4 2033-01-01
5 2035-01-01
dtype: datetime64[ns]
Source code in pyield/tn/ntnf.py
payment_dates(settlement, maturity)
Generate all remaining coupon dates between a settlement date and a maturity date. The dates are exclusive for the settlement date and inclusive for the maturity date. Coupon payments are made on the 1st of January and July. The NTN-F bond is determined by its maturity date.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
settlement
|
DateScalar
|
The settlement date. |
required |
maturity
|
DateScalar
|
The maturity date. |
required |
Returns:
Type | Description |
---|---|
Series
|
pd.Series: A Series containing the coupon dates between the settlement (exclusive) and maturity (inclusive) dates. |
Examples:
>>> from pyield import ntnf
>>> ntnf.payment_dates("15-05-2024", "01-01-2025")
0 2024-07-01
1 2025-01-01
dtype: datetime64[ns]
Source code in pyield/tn/ntnf.py
premium(settlement, ntnf_maturity, ntnf_rate, di_expirations, di_rates)
Calculate the premium of an NTN-F bond over DI rates.
This function computes the premium of an NTN-F bond by comparing its implied discount factor with that of the DI curve. It determines the net premium based on the difference between the discount factors of the bond's yield-to-maturity (YTM) and the interpolated DI rates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
settlement
|
DateScalar
|
The settlement date to calculate the premium. |
required |
ntnf_maturity
|
DateScalar
|
The maturity date of the NTN-F bond. |
required |
ntnf_rate
|
float
|
The yield to maturity (YTM) of the NTN-F bond. |
required |
di_expirations
|
Series
|
Series containing the expiration dates for DI rates. |
required |
di_rates
|
Series
|
Series containing the DI rates corresponding to the expiration dates. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The premium of the NTN-F bond over the DI curve, expressed as a |
float
|
factor. |
Examples:
>>> # Obs: only some of the DI rates will be used in the example.
>>> exp_dates = pd.to_datetime(["2025-01-01", "2030-01-01", "2035-01-01"])
>>> di_rates = pd.Series([0.10823, 0.11594, 0.11531])
>>> premium(
... settlement="23-08-2024",
... ntnf_maturity="01-01-2035",
... ntnf_rate=0.116586,
... di_expirations=exp_dates,
... di_rates=di_rates,
... )
1.0099602136954626
Notes
- The function adjusts coupon payment dates to business days and calculates the present value of cash flows for the NTN-F bond using DI rates.
Source code in pyield/tn/ntnf.py
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
|
price(settlement, maturity, rate)
Calculate the NTN-F price using Anbima rules, which corresponds to the present value of the cash flows discounted at the given yield to maturity rate (YTM).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
settlement
|
DateScalar
|
The settlement date to calculate the price. |
required |
maturity
|
DateScalar
|
The maturity date of the bond. |
required |
rate
|
float
|
The discount rate (yield to maturity) used to calculate the present value of the cash flows. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The NTN-F price using Anbima rules. |
References
- https://www.anbima.com.br/data/files/A0/02/CC/70/8FEFC8104606BDC8B82BA2A8/Metodologias%20ANBIMA%20de%20Precificacao%20Titulos%20Publicos.pdf
- The semi-annual coupon is set to 48.81, which represents a 10% annual coupon rate compounded semi-annually and rounded to 5 decimal places as per Anbima rules.
Examples:
Source code in pyield/tn/ntnf.py
spot_rates(settlement, ltn_maturities, ltn_rates, ntnf_maturities, ntnf_rates, show_coupons=False)
Calculate the spot rates (zero coupon rates) for NTN-F bonds using the bootstrap method.
The bootstrap method is a process used to determine spot rates from the yields of a series of bonds. It involves iteratively solving for the spot rates that discount each bond's cash flows to its current price. It uses the LTN rates, which are zero coupon bonds, up to the last LTN maturity available. For maturities after the last LTN maturity, it calculates the spot rates using the bootstrap method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
settlement
|
DateScalar
|
The settlement date for the spot rates calculation. |
required |
ltn_maturities
|
Series
|
The LTN known maturities. |
required |
ltn_rates
|
Series
|
The LTN known rates. |
required |
ntnf_maturities
|
Series
|
The NTN-F known maturities. |
required |
ntnf_rates
|
Series
|
The NTN-F known rates. |
required |
show_coupons
|
bool
|
If True, show also July rates corresponding to the coupon payments. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: DataFrame with columns "BDToMat", "MaturityDate" and "SpotRate". "BDToMat" is the business days from the settlement date to the maturities. |
Examples:
>>> from pyield import ntnf, ltn
>>> df_ltn = ltn.data("03-09-2024")
>>> df_ntnf = ntnf.data("03-09-2024")
>>> ntnf.spot_rates(
... settlement="03-09-2024",
... ltn_maturities=df_ltn["MaturityDate"],
... ltn_rates=df_ltn["IndicativeRate"],
... ntnf_maturities=df_ntnf["MaturityDate"],
... ntnf_rates=df_ntnf["IndicativeRate"],
... )
MaturityDate BDToMat SpotRate
0 2025-01-01 83 0.108837
1 2027-01-01 584 0.119981
2 2029-01-01 1083 0.122113
3 2031-01-01 1584 0.122231
4 2033-01-01 2088 0.121355
5 2035-01-01 2587 0.121398
Source code in pyield/tn/ntnf.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
|