QuantLib Python中评估日处于两个定盘日之间时浮息债定价遇'negative time given'错误求助及示例需求
QuantLib Python中评估日处于两个定盘日之间时浮息债定价遇'negative time given'错误求助及示例需求
我现在想用QuantLib在Python里给浮息债定价,目前遇到了卡壳的问题,情况如下:
我有两条收益率曲线:一条OIS零息曲线用来做贴现,一条3M Euribor零息曲线作为浮息的定盘曲线,评估日设为2019-11-25。我的3M Euribor曲线起始日是2020-02-27,一开始运行代码时,会提示缺少2019-08-26的定盘价,这个逻辑我能理解——毕竟评估日处于两个定盘日之间;但当我手动添加这个定盘价之后,又弹出了**"negative time given"**的错误。
有没有大佬能给个可行的示例,演示当评估日处于两个定盘日之间时,怎么用IBOR类的定盘曲线+贴现零息曲线来给浮息债定价呀?
以下是我目前的代码:
import Quantlib as ql import numpy as np dates_ois = [ql.Date(25,11,2019), ...] rates_ois = [-0.0045, ...] dates_3M = [ql.Date(27,2,2020), ...] rates_3M = [-0.004, ...] reference_date = ql.Date(25,11,2019) calendar=ql.TARGET() dcc_ois = ql.Acutal360() dcc_3M = ql.Actual360() interpolation = ql.Linear() compounding = ql.Compounded frequency = ql.Annual curve_ois = ql.ZeroCurve(dates_ois, rates_ois, dcc_ois, calendar, interpolation, compounding, frequency) curve_ois_handle = ql.YieldTermStructureHandle(curve_ois) curve_3M = ql.ZeroCurve(dates_3M, rates_3M, dcc_3M, calendar, interpolation, compounding, frequency) curve_3M_handle = ql.YieldTermStructureHandle(curve_3M) nominal = 100 issue_date = ql.Date(28,5,2019) maturity = ql.Date(5,1,2027) tenor = ql.Period('3M') end_of_month = False schedule = ql.Schedule(issue_date, maturity, tenor, calendar, ql.ModifiedFollowing, ql.ModifiedFollowing, ql.DateGeneration.Forward, end_of_month) settlement_days = 0 euribor3M = ql.Euribor3M(curve_3M_handle) dcc_bond = ql.Actual360() floater = ql.FloatingRateBond(settlement_days, nominal, schedule, euribor3M, dcc_bond) pricing_engine = ql.DiscoundingBondEngine(curve_ois_handle) floater.setPricingEngine(pricing_engine) print(floater.NPV())
遇到的两次错误:
- 未添加手动定盘价时:提示
Missing Euribor3M Actual/360 fixing for August 26th, 2019 - 添加以下定盘价代码后:
fixing_date = ql.Date(26,8,2019) fixing_value = -0.004 euribor3M.addFixing(fixing_date, fixing_value)
弹出错误:negative time given (-0.252778)
备注:内容来源于stack exchange,提问作者Maria Reinhardt
相关产品推荐
相关产品推荐

