Bond.yield_to_maturity defaults to US_TREASURY while price and risk methods default to UK_DMO

Aperta Adatta ai principianti
#495 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
66/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python

Direzione di ricerca

Leggi la convenzione predefinita in financepy/products/bonds/bond.py e i test sulle obbligazioni interessati, in particolare tests/unit/test_bond_portfolio.py::test_11. Verifica come i metodi di pricing e rischio impostano i valori predefiniti e riproduci il percorso di andata e ritorno tra le date delle cedole. Il lavoro è completato quando le convenzioni predefinite sono coerenti, il percorso di andata e ritorno è coperto e l’aspettativa esistente per US_TREASURY è esplicita, se deve rimanere.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bond.yield_to_maturity uses convention=YTMCalcType.US_TREASURY by default, but clean_price_from_ytm, dirty_price_from_ytm, modified_duration, macaulay_duration, dollar_duration, dv01, convexity_from_ytm and theta all default to YTMCalcType.UK_DMO. With default arguments, a price-to-yield round trip does not return the yield you started from, and a yield from yield_to_maturity is then fed into risk measures that assume a different convention.

The two conventions differ in how the fractional first period is discounted (simple interest for US_TREASURY, compounded for UK_DMO), so the gap shows up whenever settlement is between coupon dates.

from financepy.utils import Date, FrequencyTypes, DayCountTypes
from financepy.products.bonds.bond import Bond

bond = Bond(Date(15, 5, 2020), Date(15, 5, 2030), 0.05,
            FrequencyTypes.SEMI_ANNUAL, DayCountTypes.THIRTY_E_360)
settle = Date(15, 8, 2025)

clean = bond.clean_price_from_ytm(settle, 0.06)   # default UK_DMO
ytm = bond.yield_to_maturity(settle, clean)        # default US_TREASURY
print(f"{ytm:.6f}")                                # 0.059973, not 0.060000

So the default round trip is off by about 2.7 bp for this bond. On a coupon date, the two agree.

Is the different default intended? If not, the smallest fix is to make yield_to_maturity default to UK_DMO, like the other Bond methods. I tried that locally: 184 of the 185 bond unit tests pass. The one that changes is tests/unit/test_bond_portfolio.py::test_11, which pins the US_TREASURY default (0.7639% becomes 0.7640%). It would need to pass convention=YTMCalcType.US_TREASURY explicitly to keep testing that value.

Since this changes the default output for existing users, I wanted to check before opening a PR. I'm happy to send it, or to go the other way (for example, a note in the docstring) if you prefer.

Lingua principale
Python
Stelle
3.2k
Fork
457
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di domokane/FinancePy

Tutte le issue di domokane/FinancePy

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.