简体   繁体   English

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

[英]Cash-settled swaptions pricing in QuantLib-Python

I am trying to price a cash-settled swaption in QuantLib using the swigged python version, the code is as follows: 我试图使用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()

The code fails on Settlement::checkTypeAndMethodConsistency in the cash-settled case, throwing the exception: 在现金结算的情况下,代码在Settlement::checkTypeAndMethodConsistency上失败,抛出异常:

"invalid settlement method for cash settlement"

The same code works fine if you replace ql.Settlement.Cash by ql.Settlement.Physical in the swaption instantiation. 如果在ql.Settlement.Cash实例化中用ql.Settlement.Physical替换ql.Settlement.Cash ,则相同的代码可以正常工作。

Is there a way to set the settlement method from Python? 有没有办法从Python设置结算方法? I see only two constructors available from Python and none takes a settlementMethod argument: 我看到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 &)

The SWIG interface has not yet been updated to reflect the changes in the underlying library (you might want to open an issue at https://github.com/lballabio/QuantLib-SWIG/issues for that). SWIG界面尚未更新以反映底层库中的更改(您可能希望在https://github.com/lballabio/QuantLib-SWIG/issues上打开一个问题)。

In the meantime, using QuantLib 1.13 should work. 与此同时,使用QuantLib 1.13应该可行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM