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

未关闭 适合新手
#495 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
66/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python

调研方向

阅读 financepy/products/bonds/bond.py 中的默认约定以及受影响的债券测试,尤其是 tests/unit/test_bond_portfolio.py::test_11。检查定价和风险方法如何设置默认值,并复现票息日期之间的往返过程。完成标准:默认约定保持一致,往返过程得到测试覆盖,并且如果现有的 US_TREASURY 预期应保留,就将其明确写出。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Python
星标
3.2k
派生
457
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

domokane/FinancePy 的其他 Issue

查看 domokane/FinancePy 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。