gpt4 book ai didi

python - QuantLib-Python 中的现金结算掉期期权定价

转载 作者:行者123 更新时间:2023-11-28 17:01:38 24 4
gpt4 key购买 nike

我正在尝试使用 swigged python 版本在 QuantLib 中为现金结算的掉期期权定价,代码如下:

import QuantLib as ql
# QL session
today = ql.Date(2, ql.January, 2019)
ql.Settings.instance().evaluationDate = today
# Underlying swap definition
curve = ql.YieldTermStructureHandle(ql.FlatForward(today, 0.03, ql.Actual365Fixed()))
libor_3m = ql.USDLibor(ql.Period('3M'), curve)
calendar = ql.UnitedStates()
effective = calendar.advance(today, 1, ql.Years)
maturity = calendar.advance(effective, 4, ql.Years)
fixed_schedule = ql.Schedule(effective, maturity, ql.Period('6M'), calendar,
ql.ModifiedFollowing, ql.ModifiedFollowing,
ql.DateGeneration.Forward, False)
float_schedule = ql.Schedule (effective, maturity, ql.Period('3M'), calendar,
ql.ModifiedFollowing, ql.ModifiedFollowing,
ql.DateGeneration.Forward, False)
notional = 1e6
swap = ql.VanillaSwap(ql.VanillaSwap.Payer, notional, fixed_schedule, 0.03,
ql.Actual365Fixed(), float_schedule, libor_3m, 0.,
ql.Actual360())
# Swaption definition
swaption = ql.Swaption(swap, ql.EuropeanExercise(effective), ql.Settlement.Cash)
engine = ql.BlackSwaptionEngine(curve, ql.QuoteHandle(ql.SimpleQuote(0.1)))
swaption.setPricingEngine(engine)
swaption.NPV()

在现金结算的情况下,代码在 Settlement::checkTypeAndMethodConsistency 上失败,抛出异常:

"invalid settlement method for cash settlement"

如果在 swaption 实例化中将 ql.Settlement.Cash 替换为 ql.Settlement.Physical,则相同的代码可以正常工作。

有没有办法从 Python 设置结算方式?我看到 Python 中只有两个可用的构造函数,没有一个接受 settlementMethod 参数:

Possible C/C++ prototypes are:
SwaptionPtr::SwaptionPtr(VanillaSwapPtr const &,boost::shared_ptr<Exercise > const &,Settlement::Type)
SwaptionPtr::SwaptionPtr(VanillaSwapPtr const &,boost::shared_ptr<Exercise > const &)

最佳答案

SWIG 接口(interface)尚未更新以反射(reflect)底层库中的更改(您可能想为此在 https://github.com/lballabio/QuantLib-SWIG/issues 上打开一个问题)。

与此同时,使用 QuantLib 1.13 应该可以。

关于python - QuantLib-Python 中的现金结算掉期期权定价,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54012065/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com