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

オープン 初心者向け
#495 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
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 はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

domokane/FinancePy のほかの issue

domokane/FinancePy の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。