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

Abierto Apto para principiantes
#495 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
66/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python

Línea de trabajo

Lee la convención predeterminada en financepy/products/bonds/bond.py y las pruebas de bonos afectadas, especialmente tests/unit/test_bond_portfolio.py::test_11. Comprueba cómo los métodos de valoración y riesgo establecen sus valores predeterminados y reproduce el recorrido de ida y vuelta entre fechas de cupón. El trabajo estará terminado cuando las convenciones predeterminadas sean coherentes, el recorrido de ida y vuelta esté cubierto y la expectativa existente de US_TREASURY sea explícita si debe mantenerse.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
3.2k
Forks
457
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de domokane/FinancePy

Todos los issues de domokane/FinancePy

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.