QuantLib: 空期限结构已设置到此指数实例。

huangapple go评论69阅读模式
英文:

QuantLib: null term structure set to this instance of index

问题

我在使用QuantLib-Python并尝试使用Hull-White 1-Factor模型来定价利率上限。

import QuantLib as ql

sigma = 0.35
a = 0.1

today = ql.Date(18, ql.May, 2023)
ql.Settings.instance().setEvaluationDate(today)
day_count = ql.ActualActual(ql.ActualActual.ISDA)

forward_rate = 0.075
forward_curve = ql.FlatForward(today, ql.QuoteHandle(ql.SimpleQuote(forward_rate)), day_count)
initialTermStructure = ql.YieldTermStructureHandle(forward_curve)

calendar = ql.NullCalendar()
convention = ql.ModifiedFollowing

index = ql.IborIndex('custom index', ql.Period('3m'), 0, ql.USDCurrency(), 
                    calendar, convention, True, day_count)

start_date = ql.Date(18, ql.May, 2023)
end_date = ql.Date(18, ql.May, 2024)
period = ql.Period(3, ql.Months)

schedule = ql.Schedule(start_date, end_date, period, calendar, convention, convention, ql.DateGeneration.Forward, False)

nominal = 1000000
strike = 0.07

index_leg = ql.IborLeg([nominal], schedule, index)

cap = ql.Cap(index_leg, [strike])
model = ql.HullWhite(initialTermStructure, a, sigma)
engine = ql.AnalyticCapFloorEngine(model, initialTermStructure)
cap.setPricingEngine(engine)
cap.NPV()

看起来我可能做错了些什么。

将null期限结构设置为此自定义指数3M的实例
Actual/Actual (ISDA)

我该如何解决这个错误?

英文:

I'm playing around with QuantLib-Python and trying to price an interest rate cap using Hull-White 1-Factor model.

import QuantLib as ql

sigma = 0.35
a = 0.1

today = ql.Date(18, ql.May, 2023)
ql.Settings.instance().setEvaluationDate(today)
day_count = ql.ActualActual(ql.ActualActual.ISDA)

forward_rate = 0.075
forward_curve = ql.FlatForward(today, ql.QuoteHandle(ql.SimpleQuote(forward_rate)), day_count)
initialTermStructure = ql.YieldTermStructureHandle(forward_curve)

calendar = ql.NullCalendar()
convention = ql.ModifiedFollowing

index = ql.IborIndex('custom index', ql.Period('3m'), 0, ql.USDCurrency(), 
                    calendar, convention, True, day_count)

start_date = ql.Date(18, ql.May, 2023)
end_date = ql.Date(18, ql.May, 2024)
period = ql.Period(3, ql.Months)

schedule = ql.Schedule(start_date, end_date, period, calendar, convention, convention, ql.DateGeneration.Forward, False)

nominal = 1000000
strike = 0.07

index_leg = ql.IborLeg([nominal], schedule, index)

cap = ql.Cap(index_leg, [strike])
model = ql.HullWhite(initialTermStructure, a, sigma)
engine = ql.AnalyticCapFloorEngine(model, initialTermStructure)
cap.setPricingEngine(engine)
cap.NPV()

It seems like I'm doing something the wrong way

> null term structure set to this instance of custom index3M
> Actual/Actual (ISDA)

How can I troubleshoot this error?

答案1

得分: 0

这将使其工作。

英文:

It turns out that

index = ql.IborIndex('custom index', ql.Period('3m'), 0, ql.USDCurrency(),calendar, convention, True, day_count, initialTermStructure)

will make it work.

huangapple
  • 本文由 发表于 2023年5月20日 23:36:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76296007.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定