Serving the Quantitative Finance Community

 
krs
Topic Author
Posts: 38
Joined: August 20th, 2019, 12:40 pm

Lewis Formula

June 26th, 2021, 10:33 pm

Hi all,

am I allowed to change the limits of the following integral:

integral ( Z ) dk from i/2 to infinity + i/2, where i is an imaginary number. Function Z is also complex. Can I just integrate it over 0 to infinity??

thank you,
 
User avatar
Alan
Posts: 2958
Joined: December 19th, 2001, 4:01 am
Location: California
Contact:

Re: Lewis Formula

June 27th, 2021, 3:25 pm

The problem is your word "just". If that's all you do, the answer is "no". What you can do is one of two things:

The first is to change dummy integration variable from k to x via [$]k = x + i/2[$]. Then, the x-integral will have your desired limits.

The second is to translate the integration contour to new ones where [$]\mbox{Im} \, k = 0[$] or [$]\mbox{Im} \, k = i[$]. This needs to be done carefully using the Residue Theorem because (since my name is on it), I will guess your [$]Z_k[$] has poles at [$]k = 0,i[$].   Details are found in my paper here in the section `Contour variations'. This also results in integrals from 0 to [$]\infty[$].
 
krs
Topic Author
Posts: 38
Joined: August 20th, 2019, 12:40 pm

Re: Lewis Formula

June 29th, 2021, 9:10 am

Thank you, Lewis! :)

I'll go with the first approach by changing variable. 

One more issue: when I am running local optimization algorithms, I am getting the solution on the boundary, when using differential evolution, I get a better solution.

I am trying to calibrate the Heston model in two steps: 

1) use Alos et al approximation, run differential evolution and use this solution as an initial guess to run a local optimization calibration problem (again on approximated option price formula)

2) take the above results as an initial guess to match exact option prices (using Lewis formula)

the objective function is RMSE on call option prices.

Why am I getting upper/lower bound values as a solution?

Thank you,
K
 
User avatar
Alan
Posts: 2958
Joined: December 19th, 2001, 4:01 am
Location: California
Contact:

Re: Lewis Formula

June 29th, 2021, 4:31 pm

You're welcome. 

If the SDE for the variance rate is written [$]dV = (\omega - \theta \, V) dt + \xi \sqrt{V} dW[$], then
using that notation, please explain what you mean by "on the boundary". 
 
User avatar
Cuchulainn
Posts: 20252
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Re: Lewis Formula

June 29th, 2021, 7:23 pm

"boundary" has many meanings,
(e.g. DE has box constraints... just a guess)
 
User avatar
Alan
Posts: 2958
Joined: December 19th, 2001, 4:01 am
Location: California
Contact:

Re: Lewis Formula

June 29th, 2021, 7:41 pm

my guess is that K is referring to a violation of the (unnecessary) Feller condition, but we'll see ...
 
User avatar
Cuchulainn
Posts: 20252
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Re: Lewis Formula

June 29th, 2021, 7:48 pm

my guess is that K is referring to a violation of the (unnecessary) Feller condition, but we'll see ...
Another guess..
Then downstream (?) this is a constrained optimisation problem and DE wasn't built for that I suspect .. my guess we are in KKT territory (inequality constraint))
if so, you can introduce slack variables to form equality constraints.

// I thought 'K' was strike, got it now :-)
 
krs
Topic Author
Posts: 38
Joined: August 20th, 2019, 12:40 pm

Re: Lewis Formula

June 29th, 2021, 10:30 pm

Hi all,

K is not 'strike' :D

I am using DE with Feller condition as constraint, and this is always satisfied. I take the solution of differential evolution as an initial guess for SLSQP (sequential least-square program). I am using the Scipy library, and scipy.minimize('SLSQP') is a modified version of the Levenberg-Marquardt algorithm and it allows bounds on the decision variables.

Without introducing bounds, I was getting v_0 (initial variance) less than 0. It is not desirable, therefore, I introduced bounds on the decision variables. Lower bound being 0.001 for all the variables, except for the correlation parameter. I see that the DE solution is good (in terms of calibration error, Feller condition and positive values, except for correlation), however, with SLSQP, 4 out of 5 parameters hit a lower bound in the optimal solution. 0.001 (for omega, theta and V_0, and -1 for rho)

Why??

maybe I should call it a 'corner point' solution.

thank you! :)
Krish

PS: always making sure that Feller condition is satisfied, whether running local or global optimization algorithm.
 
User avatar
Alan
Posts: 2958
Joined: December 19th, 2001, 4:01 am
Location: California
Contact:

Re: Lewis Formula

June 30th, 2021, 2:05 am

Have never used SLSQP. Assuming it is trustworthy, try both of these things at once:
1. Increase xmax until you have very accurate results, say 12+ good digits for Heston values using my reference values  here
2. Do the optimization with volatility tracking; i.e., fix a plausible long-run variance [$]V_L[$]  and use that to set  [$]\omega = \theta \, V_L[$] each time the objective functions is recomputed because of a parameter step.

Report back. 

p.s. Don't try to enforce the Feller condition. It is frequently violated in calibrations.
 
User avatar
Cuchulainn
Posts: 20252
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Re: Lewis Formula

June 30th, 2021, 11:53 am

I have a number of questions and remarks later but the most general formulation is important

min [$]f(x)[$]

1. inequality constraints [$]g(x) \leq 0[$]
2. equality constraints [$]h(x) = 0[$]
2. boundary constraints [$]L \leq x \leq U[$]

Is your problem the same or slightly different?

I have used DE with but not with1,2. Price, Storm and Lampinen (DE) 2005 suggest using penalty functions for 1,2.
Joerg Kienitz and Daniel Wetterau (2012) discuss SQP in much detail + Matlab (DW is a SQP specialist) where they accommodate 1,2 by defining the Lagrange function. Does your scipyy code do the same?

BTW did you run DE to completion just to get the correct answers?
 
User avatar
Cuchulainn
Posts: 20252
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Re: Lewis Formula

June 30th, 2021, 12:36 pm

typo above (we cannot edit a post after 15 minutes.. bah)

should be

"3. boundary constraints"

"I have used DE with 3".
 
User avatar
Cuchulainn
Posts: 20252
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Re: Lewis Formula

July 1st, 2021, 10:04 am

Here is sample Python code I wrote for SLSQP and SHGO ( global optimizer) that might be useful in the current context. I have used equality and inequality constraints. With SHGO

1. global minimum
2. set of local minima
3. no initial guess needed (obviating the DE part)

If you can give the precise input data to your problem I can try it with my code.
# SHGO.py
# DJD
# minimize f(x) = abs(x1-2) + abs(x2-2), x = (x1,x2)
#
# g(x) = x1 - x2^2 >= 0 parabola
# h(x) = x1^2 + x2^2 -1 = 0 circle
#
# Global minimum = (sqrt(2)/2, sqrt(2)/2)
#
# Also eggholder function


from scipy.optimize import minimize_scalar, minimize, shgo, brute, fmin
import math
import numpy as np

#Constrained methods
print("constrained optimisation")
fun = lambda x: math.fabs(x[0] - 2) + math.fabs(x[1] - 2)

#choice 1
cons1 = {'type': 'ineq', 'fun': lambda x: x[0] - pow(x[1],2)}
cons2 = {'type': 'eq', 'fun': lambda x: pow(x[0],2) + pow(x[1],2) - 1.0 }
cons = [cons1, cons2]

# SLSQP method
x0 = [2,0]
bnds = [(0,None), (0,None)]

v = minimize(fun,x0, method='SLSQP', bounds = bnds, constraints = cons)    
print(v)
#print(fun(v[0], v[1]))


# SHGO (Simplicial Homology Global Optimisation)
result = shgo(fun, bounds = bnds, constraints = cons, sampling_method ='simplicial')
print("global minimum  ", result.x)   
print("success?  ", result.success) 
print(result.fun) 
print("local minima  ", result.xl)   
print("values at local minima  ", result.funl)   

# Several local minima
def eggholder(xc):
    x = xc[0]; y = xc[1]
    return (-(y+ 47.0)*np.sin(np.sqrt(abs(0.5*x + y+47.0)))
            - x*np.sin(np.sqrt(abs(x- (y+47.0))))
           )

bnds = [(-512,512), (-512,512)]

#choice 1 (ineq always g(x) >= 0)
cons1 = {'type': 'ineq', 'fun': lambda x: x + 1}
cons2 = {'type': 'ineq', 'fun': lambda x: 3.0 - x}
cons = [cons1, cons2]

# SHGO method

#result = shgo(fun, bounds = bnds, constraints = cons, sampling_method ='sobol')
result = shgo(eggholder, bounds = bnds, n = 64, sampling_method ='sobol')
print("global minimum  ", result.x)   
print("success?  ", result.success) 
print(result.fun) 
print("local minima  ", result.xl)   
print("values at local minima  ", result.funl)   

 
User avatar
Cuchulainn
Posts: 20252
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Re: Lewis Formula

July 1st, 2021, 10:13 am

$$$$I tried SHGO on the nasty eggholder function (see my code) as stress test. I reckon Heston is a bit easier.
You can run the code as is and examine the output.

Image
 
krs
Topic Author
Posts: 38
Joined: August 20th, 2019, 12:40 pm

Re: Lewis Formula

July 1st, 2021, 11:24 am

Hi all, thank you very much for your useful inputs.

I think I am having issues with the integral. I am following this article, Lewis formula is equation 16. 

https://www.degruyter.com/document/doi/ ... 58_ref_023

This is different from the formula in the book by Lewis and in a paper cited by the authors, they mentioned Baustian et.al work where it is shown that Lewis formula is equivalent to the Heston option pricing formula.

As a first step, I checked the validity of the transformed function (H_hat) that I implemented in Python, it is equal to 1 at k=0 and at time-to-maturity = 0.

Then I tried to match the reference prices that Alan has shared. I used the same set of parameters to see if the option pricing formula I have written in Python returns the same values as reported on the web. No luck.

I found that the integral formulas (in the book and in the article I am following) are not exactly the same, limits are different and a 2 is missing in the denominator (strike part).

I am not sure that H_hat is an even function because authors are integrating with limits [i/2, inf + i/2], in other references, integral limits are [-inf +i/2, inf +i/2]. Not sure that classical integration properties can be applied in complex space. 

I am using scipy.integrate.quad to evaluate the integral in the Lewis formula. It returns the real part of the integral, and this function works only with real limits. I also tried to integrate with the limits provided in the book or in Baustian's article, and I find that from [-inf +i/2,0], the integral is not converging. 

 Reading about singularity and other properties of this option pricing formula. I am also reading about the strip of regularity. 

How do you compute such integrals?

thank you,
Krish 
 
User avatar
Cuchulainn
Posts: 20252
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Re: Lewis Formula

July 1st, 2021, 1:30 pm

Not sure that classical integration properties can be applied in complex space.
Depends. In general scipy.quad is based on Fortran QUADPACK which is for real functions only AFAIK(??? quadpy useful see code 101)

One of my MSc students has something to say maybe on these integrals (see eq. 3.42) using FFT and trapezoid rule

https://www.datasim.nl/blogs/29/msc-the ... nance-2020
import quadpy
import numpy

val, err = quadpy.quad(lambda x: numpy.exp(1j * x), 0, 1)
print(val)

# correctly gives (0.8414709848078964+0.4596976941318605j)