繁体   English   中英

QuantLib for Python RuntimeError:未提供vega

[英]QuantLib for Python RuntimeError: vega not provided

使用二项式定价引擎和Cox-Rubinstein模型为普通的美国普通期权定价。 尝试检索Vega时,出现主题错误:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/opt/conda/lib/python3.6/site-packages/QuantLib.py", line 10506, in vega
    return _QuantLib.VanillaOption_vega(self)
RuntimeError: vega not provided

尽管vegaamerican_option一种方法:

>>> dir(american_option)  # scroll to the right -->
['NPV', '__class__', '__del__', '__delattr__', '__deref__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__nonzero__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__swig_destroy__', '__weakref__', 'asObservable', 'delta', 'dividendRho', 'errorEstimate', 'freeze', 'gamma', 'impliedVolatility', 'isExpired', 'priceCurve', 'recalculate', 'rho', 'setPricingEngine', 'strikeSensitivity', 'theta', 'thetaPerDay', 'this', 'thisown', 'unfreeze', 'vega']

这是基于几个在线示例的代码:

>>> from QuantLib import *
>>> maturity_date = Date(15, 1, 2016)
>>> spot_price = 127.62
>>> strike_price = 130
>>> volatility = 0.20 # the historical vols for a year
>>> dividend_rate =  0.0163
>>> option_type = Option.Call
>>> risk_free_rate = 0.001
>>> day_count = Actual365Fixed()
>>> calendar = UnitedStates()
>>> calculation_date = Date(8, 5, 2015)
>>> Settings.instance().evaluationDate = calculation_date
>>> payoff = PlainVanillaPayoff(option_type, strike_price)
>>> settlement = calculation_date
>>> am_exercise = AmericanExercise(settlement, maturity_date)
>>> american_option = VanillaOption(payoff, am_exercise)
>>> spot_handle = QuoteHandle(
...             SimpleQuote(spot_price)
...         )
>>> flat_ts = YieldTermStructureHandle(
...     FlatForward(calculation_date,
...                 risk_free_rate,
...                 day_count)
... )
>>> dividend_yield = YieldTermStructureHandle(
...     FlatForward(calculation_date,
...                 dividend_rate,
...                 day_count)
... )
>>> flat_vol_ts = BlackVolTermStructureHandle(
...     BlackConstantVol(calculation_date,
...                      calendar,
...                      volatility,
...                      day_count)
... )
>>> bsm_process = BlackScholesMertonProcess(spot_handle,
...                                         dividend_yield,
...                                         flat_ts,
...                                         flat_vol_ts)
>>> 
>>> 
>>> binomial_engine = BinomialVanillaEngine(bsm_process, "crr", 100)
>>> american_option.setPricingEngine(binomial_engine)
>>> print(american_option.vega())

版本:

>>> import QuantLib
>>> print(QuantLib.__version__)
1.11

Python 3.6.3 |Anaconda, Inc.| (default, Oct 13 2017, 12:02:49)

问题是为什么不提供vega? 是什么导致错误?

VanillaOption类声明了vega方法,但后者只能在所选引擎对其进行计算后返回结果。

通常,使用解析公式的引擎能够廉价地返回希腊语,因为它们也具有解析表达式。 像您所使用的那样,基于二项式树的引擎没有一种简单的方法来计算vega。 为了提供它,它应该执行昂贵的操作(即,在波动的情况下进行重新计算并以数值方式获得vega),因此它摆脱了困境,让您明确地执行昂贵的计算。

在这种情况下,您可以通过增加波动率,计算新的期权价格并通过数值计算导数来计算vega。

我对此进行了详细说明,并在此视频中提供了一些基本示例。

暂无
暂无

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

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