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 | pl.DataFrame: DataFrame with columns "PaymentDate" and "CashFlow". | 
Examples:
>>> from pyield import ntnf
>>> ntnf.cash_flows("15-05-2024", "01-01-2027")
shape: (6, 2)
┌─────────────┬────────────┐
│ PaymentDate ┆ CashFlow   │
│ ---         ┆ ---        │
│ date        ┆ f64        │
╞═════════════╪════════════╡
│ 2024-07-01  ┆ 48.80885   │
│ 2025-01-01  ┆ 48.80885   │
│ 2025-07-01  ┆ 48.80885   │
│ 2026-01-01  ┆ 48.80885   │
│ 2026-07-01  ┆ 48.80885   │
│ 2027-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 | pl.DataFrame: DataFrame with columns "MaturityDate" and "IndicativeRate". | 
Examples:
>>> from pyield import ntnf
>>> ntnf.data("23-08-2024")
shape: (6, 14)
┌───────────────┬──────────┬───────────┬───────────────┬───┬──────────┬──────────┬────────────────┬─────────┐
│ ReferenceDate ┆ BondType ┆ SelicCode ┆ IssueBaseDate ┆ … ┆ BidRate  ┆ AskRate  ┆ IndicativeRate ┆ DIRate  │
│ ---           ┆ ---      ┆ ---       ┆ ---           ┆   ┆ ---      ┆ ---      ┆ ---            ┆ ---     │
│ date          ┆ str      ┆ i64       ┆ date          ┆   ┆ f64      ┆ f64      ┆ f64            ┆ f64     │
╞═══════════════╪══════════╪═══════════╪═══════════════╪═══╪══════════╪══════════╪════════════════╪═════════╡
│ 2024-08-23    ┆ NTN-F    ┆ 950199    ┆ 2014-01-10    ┆ … ┆ 0.107864 ┆ 0.107524 ┆ 0.107692       ┆ 0.10823 │
│ 2024-08-23    ┆ NTN-F    ┆ 950199    ┆ 2016-01-15    ┆ … ┆ 0.11527  ┆ 0.114948 ┆ 0.115109       ┆ 0.11467 │
│ 2024-08-23    ┆ NTN-F    ┆ 950199    ┆ 2018-01-05    ┆ … ┆ 0.116468 ┆ 0.11621  ┆ 0.116337       ┆ 0.1156  │
│ 2024-08-23    ┆ NTN-F    ┆ 950199    ┆ 2020-01-10    ┆ … ┆ 0.117072 ┆ 0.116958 ┆ 0.117008       ┆ 0.11575 │
│ 2024-08-23    ┆ NTN-F    ┆ 950199    ┆ 2022-01-07    ┆ … ┆ 0.116473 ┆ 0.116164 ┆ 0.116307       ┆ 0.11554 │
│ 2024-08-23    ┆ NTN-F    ┆ 950199    ┆ 2024-01-05    ┆ … ┆ 0.116662 ┆ 0.116523 ┆ 0.116586       ┆ 0.11531 │
└───────────────┴──────────┴───────────┴───────────────┴───┴──────────┴──────────┴────────────────┴─────────┘
Source code in pyield/tn/ntnf.py
              
            di_net_spread(settlement, ntnf_maturity, ntnf_rate, di_expirations, di_rates)
    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 | FloatArray | A Series of DI rates. | required | 
| di_expirations | DateArray | A list or Series of DI expiration dates. | required | 
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 = ["2025-01-01", "2030-01-01", "2035-01-01"]
>>> di_rates = [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
              | 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 |  | 
            di_spreads(date, bps=False)
    Calcula o DI Spread para títulos prefixados (LTN e NTN-F) em uma data de referência.
Definição do spread (forma bruta): DISpread_raw = IndicativeRate - SettlementRate
Quando bps=False a coluna retorna essa diferença em formato decimal
(ex: 0.000439 ≈ 4.39 bps). Quando bps=True o valor é automaticamente
multiplicado por 10_000 e exibido diretamente em basis points.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
| date | DateScalar | Data de referência para buscar as taxas. | required | 
| bps | bool | Se True, retorna DISpread já convertido em basis points. Default False. | False | 
Returns:
| Type | Description | 
|---|---|
| DataFrame | pl.DataFrame com colunas: - BondType - MaturityDate - DISpread (decimal ou bps conforme parâmetro) | 
Raises:
| Type | Description | 
|---|---|
| ValueError | Se os dados de DI não possuem 'SettlementRate' ou estão vazios. | 
Examples:
>>> from pyield import ntnf
>>> ntnf.di_spreads("30-05-2025", bps=True)
shape: (5, 3)
┌──────────┬──────────────┬──────────┐
│ BondType ┆ MaturityDate ┆ DISpread │
│ ---      ┆ ---          ┆ ---      │
│ str      ┆ date         ┆ f64      │
╞══════════╪══════════════╪══════════╡
│ NTN-F    ┆ 2027-01-01   ┆ -3.31    │
│ NTN-F    ┆ 2029-01-01   ┆ 14.21    │
│ NTN-F    ┆ 2031-01-01   ┆ 21.61    │
│ NTN-F    ┆ 2033-01-01   ┆ 11.51    │
│ NTN-F    ┆ 2035-01-01   ┆ 22.0     │
└──────────┴──────────────┴──────────┘
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 date-like object. | required | 
| maturity | DateScalar | The maturity date in 'DD-MM-YYYY' format or a date-like object. | 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 | pl.Series: A Series of NTN-F bond maturities available for the reference date. | 
Examples:
>>> from pyield import ntnf
>>> ntnf.maturities("23-08-2024")
shape: (6,)
Series: 'MaturityDate' [date]
[
    2025-01-01
    2027-01-01
    2029-01-01
    2031-01-01
    2033-01-01
    2035-01-01
]
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 | pl.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-2027")
shape: (6,)
Series: '' [date]
[
    2024-07-01
    2025-01-01
    2025-07-01
    2026-01-01
    2026-07-01
    2027-01-01
]
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 | DateScalar | Series with the expiration dates for the DI. | required | 
| di_rates | FloatArray | 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 = ["2025-01-01", "2030-01-01", "2035-01-01"]
>>> di_rates = [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.0099602679927115
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
              | 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 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 |  | 
            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 | DateArray | The LTN known maturities. | required | 
| ltn_rates | FloatArray | The LTN known rates. | required | 
| ntnf_maturities | DateArray | The NTN-F known maturities. | required | 
| ntnf_rates | FloatArray | 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 | pl.DataFrame: DataFrame with columns "MaturityDate", "BDToMat" 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"],
... )
shape: (6, 3)
┌──────────────┬─────────┬──────────┐
│ MaturityDate ┆ BDToMat ┆ SpotRate │
│ ---          ┆ ---     ┆ ---      │
│ date         ┆ i64     ┆ f64      │
╞══════════════╪═════════╪══════════╡
│ 2025-01-01   ┆ 83      ┆ 0.108837 │
│ 2027-01-01   ┆ 584     ┆ 0.119981 │
│ 2029-01-01   ┆ 1083    ┆ 0.122113 │
│ 2031-01-01   ┆ 1584    ┆ 0.122231 │
│ 2033-01-01   ┆ 2088    ┆ 0.121355 │
│ 2035-01-01   ┆ 2587    ┆ 0.121398 │
└──────────────┴─────────┴──────────┘
Source code in pyield/tn/ntnf.py
              | 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 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 |  |