View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Heston Model Calibration and Simulation

5.0 | 4 ratings Rate this file 50 Downloads (last 30 days) File Size: 6.79 KB File ID: #29446 Version: 1.1

Heston Model Calibration and Simulation


Moeti Ncube (view profile)


18 Nov 2010 (Updated )

Calibrated the Heston Model to market Option prices

| Watch this File

File Information

This code calibrates the heston model to any dataset of the form
of the marketdata.txt file.

Provides analytical heston and MCMC heston pricing of Option

To see an example, run the hestoncalibrationexample.m code

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (21)
01 Mar 2016 Francesco Ruta

Dear Moeti,

Thank you very much for your file, it is very useful! However, I see that it only shows the Heston pricing for a call option. Do you have by any chance the Heston pricing model for a put option? In other words, do you have the "HestonPut" file?

Thank you very much for your sharing!

20 Jun 2015 Zhongzhi Hu

Alternatively, you can also enforce the Feller condition as a constraint by using fmincon:
where Feller is a the constraint function.

Comment only
18 Jun 2015 Zhongzhi Hu

Adressing to Moeti, boulala666 and mj:

It is indeed essential that the obtained parameters satisfy the Feller condition. In the main program I edit the following: in x0, lb and ub I added another element x(6). Make sure that the lower bound for x(6) is 0. In costf2.m I added x(6)=2*x(2)*x(3)-x(4)^2; %Feller condition.

Thanks a lot Moeti for your code! It was very helpful for my Msc. thesis in Financial Econometrics.

06 Dec 2014 boulala666

nice code. but is the problem fixed that "mj" mentioned?

Comment only
15 Jun 2014 jie

jie (view profile)

very good

Comment only
18 Mar 2014 mj

mj (view profile)

Dear Moeti,
In Heston model, If the parameters obey 2*kappa*theta> sig (known as the Feller condition) then the process volatility is strictly positive. When I run your codes even using your marketdata, calibrated parameters violate the feller condition. Could you please explain why it is so and probably fix it if possible.
Thanks in advance

Comment only
19 Nov 2013 Carlos AY

04 Aug 2013 Fanghua

Where is the "MCMC heston pricing" part of pricing because it seems that there is only the analytical approach, or am I missing something here?

Many thanks for anyone who could help me.

Comment only
25 May 2012 københavner

Hey every one I am trying to run this code as it is but I get the message " Undefined function 'lsqnonlin' for input arguments of type'function_handle'.
Error in hestoncalibrationexample (line 36)
x = lsqnonlin(@costf2,x0,lb,ub);

Any body can help me with this problem?
thanks in advance

Comment only
22 Oct 2011 TingFu

TingFu (view profile)

Dear Moeti Ncube
Thanks for your code, it does help me a lot!
But I have a question for results.
In general, the simulated price should be very close to the Heston model price, right?
But why it seem that there is a gap between "simhes" and "modhes"?

Comment only
25 Apr 2011 Tilburg University

03 Mar 2011 Moeti Ncube

Moeti Ncube (view profile)

Yankun, sorry I could never get your code to work. Perhaps you can send folder in zip format with your revision and I will try to run again.

Comment only
23 Feb 2011 Yankun

Yankun (view profile)

Sorry, I made a mistake.
I mean your HestonCall.m doesn't work correctly when parameters such as St,K,r,T,vt,kap,th,sig,rho,lda are vectors instead of scalars.

Comment only
23 Feb 2011 Yankun

Yankun (view profile)

Dear Moeti Ncube
Thanks for your code.
But I think your HestonCalibration.m doesn't work correctly when parameters such as St,K,r,T,vt,kap,th,sig,rho,lda are vectors instead of scalars.
I've mailed you my modification based on your code.
Thank you.

Comment only
10 Feb 2011 Catherine

Dear Moeti NCube
I have read several discussions of
pricing and calibration of Heston model and I am wondering if you have encountered the problems alluded to in the following comments on calibrating Heston and pricing Heston calls given parameters:
(1) pricing the option using Heston' formulas " gives rise to an inherent numerical instability as a
consequence of which most implementations of Heston’s formulæ are not robust for moderate to long dated maturities or strong mean reversion."
(2) the calibration can get bogged down in local minima and can take a long time

Comment only
06 Jan 2011 Moeti Ncube

Moeti Ncube (view profile)

Hi, and thanks for your questions

Some of the variables you discussed are vectors in the code:

So if you want to modify the strikes and maturities consider you should adjust the marketdata.txt file

St and r is the current value of underlying and risk free rate respectively which will always be scalars. You can't have multiple values for the underlying spot price or risk free rate (technically).

Comment only
05 Jan 2011 me1 k

me1 k (view profile)

Hi moeti, thnx for the code. It gave me the opportunity to understand better the calibration procedure.
However, I am wondering how can the HestonCall(St,K,r,T,vt,kap,th,sig,rho,lda) for example work for vectors.
I mean how can I input St,K,r,T as vectors? What modifications are needed to be done in the code? Thank you in advance.

Comment only
10 Dec 2010 tbfanso ??

Oh,I see.Thanks for you help!

Comment only
10 Dec 2010 Moeti Ncube

Moeti Ncube (view profile)

Correction: volatility equation should be the following
vhes(j+1)=vhes(j)*exp(((kappa*(theta - vhes(j))-0.5*vsigma^2)*dt)/vhes(j) + vsigma*(1/sqrt(vhes(j)))*sqrt(dt)*r2);

Comment only
10 Dec 2010 Moeti Ncube

Moeti Ncube (view profile)

Hi, and thanks for comments.

The second column is not needed in the calibration as it was a column I created, for data extraction purposes, to represent how far away from the spot month the contract was. So for example if the value is '1' this mean this contract is 1 month away from expiry, if it has a value of '2', this means the contract is 2 months away from expiry.

Hope this helps.

Comment only
08 Dec 2010 tbfanso ??

I have read your great code seriously,but I have a some questions.First,about the marketdata the calibration used,the marketdata's first column is strike,and third is implied volatility,the fourth is time to maturity(days),but it seem that the third column data not used in the calibration? and what is the third column data?

Thank you for your time

Comment only
15 Jun 2011 1.1

Corrected volatility simulation to following:

vhes(j+1)=vhes(j)*exp(((kappa*(theta - vhes(j))-0.5*vsigma^2)*dt)/vhes(j) + vsigma*(1/sqrt(vhes(j)))*sqrt(dt)*r2);

Contact us