最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

finance - Quantlib Python Floating Rate Bond negative time given - Stack Overflow

programmeradmin3浏览0评论

I want to price a floating rate bond in Quantlib in Python. I have a zero curve with dates and OIS zero-rates and I have a curve with euribor 3M zero-rates that are fixed every month. I need both those curves for the floater. My reference date is for example 2019-11-25 and I would like to evaluate the bond on that day. Let's say my euribor 3M curve starts with 2020-02-27, then I'll get an error, that an additional fixing is needed for 2019-08-26 which makes sense. However, when I do add that fixing, I'll get the error "negative time given". So does anyone have an example for pricing a floating rate bond, using a fixing curve (any IBOR kind of curve) and a discounting/zeroCurve where the evaluation date is between two fixing dates??

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)

calender=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, compunding, frequency)
curve_ois_handle = ql.YieldTermStructureHandle(curve_ois)
curve_3M = q.ZeroCurve(dates_3M, rates3M, 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())

For this code I get the error message "Missing Euribor3M Actual/360 fixing for August 26th, 2019". This makes sense, as I want to evaluate the price on November 25th, 2019 but the next fixing takes place on November 26th, 2019 and is valid until February 27th, 2020, which is the first date in my euribor curve. However, when I do

fixing_date = ql.Date(26,8,2019)
fixing_value = -0.004
euribor3M.addFixing(dixing_date, fixing_value)

I get the error message "nagative time (-0.252778) given."

I want to price a floating rate bond in Quantlib in Python. I have a zero curve with dates and OIS zero-rates and I have a curve with euribor 3M zero-rates that are fixed every month. I need both those curves for the floater. My reference date is for example 2019-11-25 and I would like to evaluate the bond on that day. Let's say my euribor 3M curve starts with 2020-02-27, then I'll get an error, that an additional fixing is needed for 2019-08-26 which makes sense. However, when I do add that fixing, I'll get the error "negative time given". So does anyone have an example for pricing a floating rate bond, using a fixing curve (any IBOR kind of curve) and a discounting/zeroCurve where the evaluation date is between two fixing dates??

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)

calender=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, compunding, frequency)
curve_ois_handle = ql.YieldTermStructureHandle(curve_ois)
curve_3M = q.ZeroCurve(dates_3M, rates3M, 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())

For this code I get the error message "Missing Euribor3M Actual/360 fixing for August 26th, 2019". This makes sense, as I want to evaluate the price on November 25th, 2019 but the next fixing takes place on November 26th, 2019 and is valid until February 27th, 2020, which is the first date in my euribor curve. However, when I do

fixing_date = ql.Date(26,8,2019)
fixing_value = -0.004
euribor3M.addFixing(dixing_date, fixing_value)

I get the error message "nagative time (-0.252778) given."

Share Improve this question edited yesterday Maria Reinhardt asked yesterday Maria ReinhardtMaria Reinhardt 431 silver badge5 bronze badges 3
  • I meant that the euribor 3M rates are fixed every THREE months of course … – Maria Reinhardt Commented yesterday
  • May you post your code? It would make it easier to diagnose the problem. – Luigi Ballabio Commented yesterday
  • @LuigiBallabio I just edited my post, it contains my code now. – Maria Reinhardt Commented yesterday
Add a comment  | 

2 Answers 2

Reset to default 1

The Euribor curve should also start on the reference date. The Euribor fixing from November 26th, 2019 to February 27th, 2020 is forecast by the curve by taking the ratio of the discount factors at those two dates, which in turn are deduced from the zero rates you're passing. The error is raised when the curve tries to calculate the discount factors on November 26th and finds out it can't.

Ok, now I added the reference date at the beginning of dates_3M (and a rate at the beginning of rates_3M). I still get the error, that ql wants the fixing for August 26 2019, which I give him with the addFixing method and now I do get a dirty price and clean price. However, when I do

for c in floater.cashflows():
  print(c.date(), c.amount)

I get the error "Missing Euribor3M Actual/360 fixing for May 24th, 2019. So do I have to make a addFixing for that as well?

发布评论

评论列表(0)

  1. 暂无评论