![](/img/trans.png)
[英]Python Quantlib : How to deal with RuntimeError 'addFixing(date, value)'
[英]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
盡管vega
是american_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.