【问题标题】:Compare QuantLib bond pricing with Excel functions YIELD and PRICE when doing stress testing在进行压力测试时将 QuantLib 债券定价与 Excel 函数 YIELD 和 PRICE 进行比较
【发布时间】:2021-11-19 20:40:11
【问题描述】:

我在 Excel 和 Python Quantlib 中计算了债券价格并强调了债券价格(令人震惊的收益率)。如下表所示,产生了奇怪的结果:Excel 和 Quantlib 之间的基本债券价格非常匹配,但压力债券价格有更多的差距(相对差异为 1.5%)。收益率也显示出一些差距。 你能提供一些cmets吗?

Excel 代码:

    Base Bond Price=PRICE("2021-8-19","2025-8-19",4.5%,YIELD("2021-8-19","2025-8- 
   19",4.5%,95,100,4,0),100,4,0)

    Stress Bond Price=PRICE("2021-8-19","2025-8-19",4.5%,YIELD("2021-8-19","2025-8- 
   19",4.5%,95,100,4,0)+662/10000,100,4,0)

Python 代码:

    import datetime
    import QuantLib as ql
    settlement_date = ql.Date(19,8,2021)
    valuation_date = ql.Date(19,8,2021)
    issue_date = ql.Date(19,8,2021)
    maturity_date = ql.Date(19,8,2025)
    tenor = ql.Period(4)
    calendar = ql.UnitedStates()
    business_convention = ql.Following
    date_generation = ql.DateGeneration.Backward
    end_month = False
    face_value = 100
    coupon_rate = 450/10000
    day_count = ql.Thirty360(ql.Thirty360.USA)
    redemption_value = 100
    schedule = ql.Schedule(issue_date, maturity_date, tenor, calendar, business_convention, business_convention, date_generation, end_month)
    bond = ql.FixedRateBond(settlement_date-valuation_date, face_value, schedule, [coupon_rate], day_count, business_convention, redemption_value, issue_date)
    target_price = 95
    bond_yield = bond.bondYield(target_price, day_count, ql.Compounded, 4, ql.Date(), 1.0e-8,1000)
    bond_price = bond.cleanPrice(bond_yield, day_count, ql.Compounded, 4)
    STRESS = 662
    stress_bond_yield = bond_yield+STRESS/10000
    
    stress_bond_price = bond.cleanPrice(stress_bond_yield, day_count, ql.Compounded, 4)
    excel_base_bond_price = 99.50
    excel_stress_bond_price = 75.02971569
    print('Base bond price from excel is', excel_base_bond_price )
    print('Base bond price from Quantlib is', bond_price)
    print('Stressed bond price from excel is',excel_stress_bond_price)
    print('Stressed bond price from Quantlib is',stress_bond_price)

【问题讨论】:

  • 不确定区别,但如果我复制/粘贴您的 Excel 公式,我会得到非常不同的结果:Price=95, Stress=75.02971569
  • 除了价格,您从 Excel 和 QuantLib 获得的收益是多少?
  • @RonRosenfeld,谢谢。我已经更新了我的帖子。
  • @LuigiBallabio,谢谢。请参阅我更新的帖子,其中包含产量比较表。收益率也显示出一些差距。奇怪的是基本债券价格匹配良好,但它们的收益率有 1.51% 的相对差异。

标签: excel quantlib


【解决方案1】:

你需要添加

ql.Settings.instance().evaluationDate = valuation_date

在计算之前。如果您不这样做,您将计算截至今天而不是估值日期的收益率和价格。一旦你这样做了,收益和价格就会更好地匹配。

【讨论】:

  • 非常感谢。现在可以了。
猜你喜欢
  • 2011-07-10
  • 1970-01-01
  • 2013-02-22
  • 2021-01-01
  • 1970-01-01
  • 2022-07-06
  • 1970-01-01
  • 2011-04-28
  • 1970-01-01
相关资源
最近更新 更多