Serving the Quantitative Finance Community

 
User avatar
rnsahin
Topic Author
Posts: 0
Joined: May 22nd, 2008, 11:48 am

Heston Monte Carlo Matlab

June 8th, 2008, 8:38 am

Hi all,i try to write a code about Monte Carlo simulation of Heston Model for european call price in Matlab, but there is some problem that i can not figure it out!can anyone help me?regards.function [European_call] = Monte_Carlo_HestonK = 100;T = 1;S = 100;sigma = 0.2;r = 0.06;div = 0.03;alpha = 5.0;Vbar = 0.20;Xi = 0.02;N = 52;M = 10000;dt = T/N;rho=-0.5;sdt = sqrt(dt);sum_CT = 0;sum_CT2 = 0;for j = 1:M St1 = S; St2 = S; Vt = sigma^2; eps1 = randn(N,1); eps2 = randn(N,1); eps3 = rho*eps1 + sqrt(1-rho^2)*eps2; for i = 1:N Vtn = Vt + alpha*(Vbar-Vt)*dt + Xi*sqrt(Vt)*sdt*eps3(i,1); Vt = Vtn; Vt = abs(Vt); %prevents negative volatilities Stn1 = St1 + (r-div)*St1*dt + sqrt(Vt)*St1*sdt*eps2(i,1); Stn2 = St2 + (r-div)*St2*dt + sqrt(Vt)*St2*sdt*-eps2(i,1); St1 = Stn1; St2 = Stn2; end CT = 0.5*(max(St1 - K , 0)+ max(St2 - K , 0)); sum_CT = sum_CT + CT; sum_CT2 = sum_CT2 + CT^2;endEuropean_call = sum_CT/M*exp(-r*T)SD = sqrt((sum_CT2 - (sum_CT^2)/M)*exp(-2*r*T)/(M-1));SE = SD/sqrt(M)
Last edited by rnsahin on June 7th, 2008, 10:00 pm, edited 1 time in total.
 
User avatar
Antonio
Posts: 8
Joined: June 30th, 2004, 3:13 pm
Location: Imperial College London
Contact:

Heston Monte Carlo Matlab

June 8th, 2008, 9:11 am

The code seems ok, except maybe that rho is not defined anywhere.What is the problem exatly ?
 
User avatar
rnsahin
Topic Author
Posts: 0
Joined: May 22nd, 2008, 11:48 am

Heston Monte Carlo Matlab

June 8th, 2008, 9:41 am

hi Antonio,i just forgot to write rho here. the problem is, this code can not give the right price. i used option city calculator to see the price of option.when alpha and Xi is zero, the code gives right price. but if i change those parameters, price goes wrong.
 
User avatar
Sonyah
Posts: 0
Joined: December 11th, 2006, 3:58 pm

Heston Monte Carlo Matlab

June 10th, 2008, 7:52 am

Stn1 and Stn2 should use eps1 not eps2
 
User avatar
rnsahin
Topic Author
Posts: 0
Joined: May 22nd, 2008, 11:48 am

Heston Monte Carlo Matlab

June 10th, 2008, 9:33 am

i can not understand what is the difference between eps1 and eps2 but now it works great!thanks for the tip Sonyah.
 
User avatar
Sonyah
Posts: 0
Joined: December 11th, 2006, 3:58 pm

Heston Monte Carlo Matlab

June 10th, 2008, 10:18 am

eps1 and eps2 are both random normals but its important to get them the right way round when using eps3, which should be the correlated random with eps1. Its probably a good idea for you to read a bit about multi-factor Monte Carlo and correlated random numbers - Hull has a good basic section about it.
 
User avatar
rnsahin
Topic Author
Posts: 0
Joined: May 22nd, 2008, 11:48 am

Heston Monte Carlo Matlab

June 10th, 2008, 7:40 pm

thanks sonyah,i will read that part.