Search code examples
python-3.xquantlibvolatility

QuantLib parametrization stochastic volaltility


I was trying to replicate this paper (which is about to the Heston Model) using QuantLib tool (python 3.5).

Following the Python Quantlib Cookbook I was able to setup the parameters of page 12 from the paper. Quantlib´s result is 0.0497495 which is slightly different from paper´s result (0.049521147).

So, my question is what is the cause of this difference? Is it possible that day account have something to do here?

Code following Cookbook with papers´s parameters:

from QuantLib import *
import numpy as np
import math 

#parameters
strike_price = 2
payoff = PlainVanillaPayoff(Option.Call, strike_price)

#option data
maturity_date = Date(16, 4, 2028)
spot_price = 1
strike_price = 2
volatility = 0.16 # the historical vols for a year
dividend_rate = 0.000
option_type = Option.Call

risk_free_rate = 0.000
day_count = Actual365Fixed()
calendar = UnitedStates()
calculation_date = Date(16, 4, 2018)
Settings.instance().evaluationDate = calculation_date

# construct the European Option
payoff = PlainVanillaPayoff(option_type, strike_price)
exercise = EuropeanExercise(maturity_date)
european_option = VanillaOption(payoff, exercise)

# construct the Heston process
v0 = 0.16 #volatility*volatility # spot variance
kappa = 1
theta = 0.16
sigma = 2
rho = -0.8
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))
heston_process = HestonProcess(flat_ts, dividend_yield,spot_handle, 
                               v0, kappa,theta, sigma, rho)
engine = AnalyticHestonEngine(HestonModel(heston_process),0.01, 1000)
european_option.setPricingEngine(engine)
h_price = european_option.NPV()
print("The Heston model price is",h_price)

PD: I used QuantLib engine to double check my code (I must say I have no experience using QuantLib). I get the paper´s result using my code.


Solution

  • The difference is partly, but not entirely due to the day counter.

    If you use day_count = SimpleDayCounter(), leaving all else the same the QuantLib result becomes 0.04964543.

    The rest of the difference is because you set the "relative tolerance" in the AnalyticHestonEngine to 0.01. If you set it to a smaller value, e.g. to 0.001, you get an answer of 0.04951948, which is consistent with the answer obtained in the paper of 0.0495.