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

Đang mở Phù hợp với người mới
#495 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
66/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend, fintech-quant

Hướng nghiên cứu

Đọc quy ước mặc định trong financepy/products/bonds/bond.py và các bài kiểm thử trái phiếu bị ảnh hưởng, đặc biệt là tests/unit/test_bond_portfolio.py::test_11. Kiểm tra cách các phương thức định giá và rủi ro đặt giá trị mặc định, rồi tái hiện lượt đi và về giữa các ngày trả coupon. Hoàn tất khi các quy ước mặc định nhất quán, lượt đi và về được kiểm thử và kỳ vọng US_TREASURY hiện có được nêu rõ nếu cần giữ nguyên.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
3.2k
Fork
457
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của domokane/FinancePy

Tất cả issue của domokane/FinancePy

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.