英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论