Serving the Quantitative Finance Community

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

Re: Lewis Formula

July 1st, 2021, 3:43 pm

Here's my code -- hope it helps.
LewisHestonCode.pdf
(44.61 KiB) Downloaded 116 times
 
User avatar
Alan
Posts: 2958
Joined: December 19th, 2001, 4:01 am
Location: California
Contact:

Re: Lewis Formula

July 1st, 2021, 4:22 pm

A few comments. 
- The H function I posted uses z instead of k; otherwise, the parameters are the same as my previous post.
- Mathematica documentation is online.
- Commented out stuff mostly related to using xmax=infinity; sometimes you can get away with this; sometimes not. The code here uses a finite xmax.

My advice to Krish at this point:
- First, get your H to agree with my H at various complex z. 
- Then get your (real-valued) integrand to agree with my integrand at various positive x, defined here by [$]z = x + i/2[$]
- Finally, use my xmax cutoff, and see if you can't integrate to get my reference prices to 12 digits.

I am happy to answer questions about my code. I am unlikely to search for typos in somebody else's paper.
 
krs
Topic Author
Posts: 38
Joined: August 20th, 2019, 12:40 pm

Re: Lewis Formula

July 2nd, 2021, 12:59 pm

Thanks, Cuchulainn. I am correctly using scipy.integrate.quad, did some test runs on standard cases. 

I think the problem is the formula mentioned in the article that I am following. I am now following the book by Lewis. I think the contour variation that Alan has suggested above is a useful technique to avoid numerical instabilities when computing these integrals.

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

Re: Lewis Formula

July 2nd, 2021, 1:04 pm

Thank you, Alan. I follow the steps that have you mentioned and come back with the results. Great help!

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

Re: Lewis Formula

July 2nd, 2021, 1:20 pm

Thanks, Cuchulainn. I am correctly using scipy.integrate.quad, did some test runs on standard cases. 

I think the problem is the formula mentioned in the article that I am following. I am now following the book by Lewis. I think the contour variation that Alan has suggested above is a useful technique to avoid numerical instabilities when computing these integrals.

thank you,
K
You're welcome.
If you have time it would be nice how DE/SLSQP/(SHGO?) worked out to determine 'best practice' for this problem.
 
krs
Topic Author
Posts: 38
Joined: August 20th, 2019, 12:40 pm

Re: Lewis Formula

July 2nd, 2021, 1:33 pm




You're welcome.
If you have time it would be nice how DE/SLSQP/(SHGO?) worked out to determine 'best practice' for this problem.
I'll definitely do that.
Krish
 
User avatar
Cuchulainn
Posts: 20254
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Re: Lewis Formula

July 2nd, 2021, 3:10 pm

Thanks. A general ball-park conclusion is fine.
 
User avatar
Paul
Posts: 6604
Joined: July 20th, 2001, 3:28 pm

Re: Lewis Formula

July 3rd, 2021, 8:17 am

Is no one worried that contour integration, poles, residues, branch cuts, etc. is not for amateurs?
 
User avatar
Alan
Posts: 2958
Joined: December 19th, 2001, 4:01 am
Location: California
Contact:

Re: Lewis Formula

July 3rd, 2021, 3:02 pm

Well, I have given the OP a 'cookbook' recipe: use my integrand and integrate along my preferred contour. If he follows that, all should work out without needing knowledge of the rationale. We'll see ...
 
User avatar
Cuchulainn
Posts: 20254
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Re: Lewis Formula

July 3rd, 2021, 5:36 pm

Is no one worried that contour integration, poles, residues, branch cuts, etc. is not for amateurs?
The final arbiter is the customer.
 
User avatar
Paul
Posts: 6604
Joined: July 20th, 2001, 3:28 pm

Re: Lewis Formula

July 4th, 2021, 8:50 am

Customers always need a little gentle guidance.
 
krs
Topic Author
Posts: 38
Joined: August 20th, 2019, 12:40 pm

Re: Lewis Formula

July 5th, 2021, 2:25 pm

A few comments. 
- The H function I posted uses z instead of k; otherwise, the parameters are the same as my previous post.
- Mathematica documentation is online.
- Commented out stuff mostly related to using xmax=infinity; sometimes you can get away with this; sometimes not. The code here uses a finite xmax.

My advice to Krish at this point:
- First, get your H to agree with my H at various complex z. 
- Then get your (real-valued) integrand to agree with my integrand at various positive x, defined here by [$]z = x + i/2[$]
- Finally, use my xmax cutoff, and see if you can't integrate to get my reference prices to 12 digits.

I am happy to answer questions about my code. I am unlikely to search for typos in somebody else's paper.
I can match the reference prices to 12 digits, there was an implementation bug in my code, somewhere I used an extra ' *  ' and it became an exponent operation from multiplication.  

I still have a doubt though:

the sign of 'd' is different In the original book  (equation 3.2) and in the code that you have shared. Why? and why do we consider the gamma (risk aversion) coefficient equal to 1? 
Why do you say that the Feller condition is often violated in calibration? Should I not use this as a constraint?

I am reading contour integrals so that I can work with the Heston model with jumps. Trying to understand strip of regularity. 

Many thanks for the helpful inputs. 

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

Re: Lewis Formula

July 5th, 2021, 2:46 pm

Thanks, Cuchulainn. I am correctly using scipy.integrate.quad, did some test runs on standard cases. 

I think the problem is the formula mentioned in the article that I am following. I am now following the book by Lewis. I think the contour variation that Alan has suggested above is a useful technique to avoid numerical instabilities when computing these integrals.

thank you,
K
You're welcome.
If you have time it would be nice how DE/SLSQP/(SHGO?) worked out to determine 'best practice' for this problem.
Hi, I used DE, shgo and SLSQP algorithms to optimize the parameters. I am calibrating this model to 96 option prices (all are call options). 

I am running the DE algorithm (10 iterations) and using the solution as an initial guess to run SLSQP. This is very fast, it takes like 6 seconds to run both the algorithms. And when I remove the max iteration constraint on the DE algorithm, I find that it converges in 14 iterations. 

On the other hand, the shgo is 'slow'. 

1 iteration: 1 seconds
2 iterations: 1.5 seconds
3 iterations: 2.5 seconds
4 iterations: 52 seconds
5 iterations: 800 seconds

However, the shgo converges very fast, after two iterations the value of the objective function (RMSE) is close to the final value obtained by the DE algorithm.
maybe I need to set tolerance levels to terminate the algorithm. (xtol or gtol)

I hope it helps.

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

Re: Lewis Formula

July 6th, 2021, 10:22 am

SHGO is nice because we don't need an initial guess. It produces the global minimum and all the local minimum i haven't experimented with the parameters such as the number of sampling points and the sampling method. I think your case is unconstrained convex optmisation?

All this stuff uses maths from algebraic topology and it is discussed here and comparisons with DE.
https://www.researchgate.net/publicatio ... timisation
 
User avatar
Alan
Posts: 2958
Joined: December 19th, 2001, 4:01 am
Location: California
Contact:

Re: Lewis Formula

July 6th, 2021, 2:55 pm

Good questions. Answers inline below:

I still have a doubt though:

the sign of 'd' is different In the original book  (equation 3.2) and in the code that you have shared. Why?

>> The book code potentially suffers from The Little Heston Trap
Basically, with the book code d, H(z) can cross a branch cut as z varies within [$]0 < \mbox{Im} \, z < 1[$]. That's bad. The code I posted avoids that. The posted code is also in agreement with the formulas in Gatheral's book, which also fix the issue. You should definitely use the posted code rather than the book code for H. It's also good practice to visually examine your integrand for smoothness along the contour.

and why do we consider the gamma (risk aversion) coefficient equal to 1? 

>>  In my book, I derive a more general version of the sqrt model which has the parameter gamma, and reduces to the "conventional" Heston model when gamma=1.

Why do you say that the Feller condition is often violated in calibration? Should I not use this as a constraint?

>> If you include shorter-dated, well out of the money options, such as those available with SPX, a calibration will often
violate the Feller condition in order to achieve a "best fit". I have seen it happen often, although I typically don't use MSE on prices as the objective function. In any event, it's harmless and there's no reason not to improve a fit by accepting a Feller condition violation.

I am reading contour integrals so that I can work with the Heston model with jumps. Trying to understand strip of regularity. 

Many thanks for the helpful inputs. 

>> You're welcome