Matlab: pricing nonstandard fictitious option using monte carlo simulation

  • Thread starter Thread starter Bhoj
  • Start date Start date
Joined
11/25/11
Messages
22
Points
11
I need help to price one of the non standard option via monte carlo simulation in matlab. I would very much appreciate if any you are know better is willing to assist me. I will send the pdf with the issue. I am new to matlab. Thanks!
 
Thanks Freshdough. I really need a help to this issue. I have attached the pdf file. Just need to write to two programs to price a option similar to asian one. Thanks man! hope that it will be fine with you.
 

Attachments

The Monte Carlo part seems very simple. You know the risk neutral distribution of ( R_t ) (which happens to be independent of ( S )). Generate 10 of these (since the ( R_t ) is calculated annually and T=10). At each point calculate ( max(R_t, R) ). From there it is trivial to calculate the payoff.

This is one sample path. Repeat this sample numsum amount of times, divide by numsum, and discount at the risk free rate. This is the MC price of the option.

The MC standard error is (iirc) the standard deviation of the payoffs divided by ( \sqrt{numsum} )
 
Hi DStahl,
Thanks for the suggestion! It would be nice if you could attach me the code as per my attachment. I am just trying to learn how monte carlo is done in matlab.
 
You're right, this is old homework from a friend which I want to solve. And there is no deadline for this like homework because its just I wanna practice. I am not forcing you do anything DStahl. Its on your conviction, if you feel you wanna show how you code these, then I would welcome at anytime because its not H/W.
 
If there is no deadline, you could/should learn Matlab and then be able to solve the problem. Matlab is not a hard language to learn, and learning it yourself instead of someone showing the code is infinitely more useful to you. There is LOTS of help to be found in the Matlab docs if you run into problems. I am willing to help as well (though I do not claim to be an expert at Matlab).

I would start here: http://www.mathworks.com/help/toolbox/stats/normrnd.html
 
Thanks for the link! I have got the link that you sent me. The main issue for me is that when you don't have any whatsoever experience with coding before and you're a beginner, sometimes its hard to comprehend how to come to correct result. In addition to that I also don't have strong math background but solid highs school maths. I have done some coding on the problem that I have posted in this conversation, not finished yet. When I am done, I would be glad if you could correct them.
 
Ah. If you don't have a strong math background is it possible you do not know the distribution of ( S_t )? That would make this problem prohibitively difficult.

The SDE given by the problem is ( dS=(r-\delta)Sdt+\sigma S dW_t ). This has solution ( S_t = S_0 e^{\large(r-\delta-\frac{\sigma^2}{2}\right) t+\sigma W_t} ), where ( W_t \sim \sqrt{t}\mathcal{N}(0, 1) ). The fact that ( W_t ) is normally distributed is why you need to use normrnd.
 
Thanks a lot man! I have done initial programming to price option. But its not correct, I just didnot know how to define Rt. Could you please check, correct and come back to me. I couldnot upload notepad here for some reason I don't know but coding is below. Its for question 3.
Code:
%function to price non standard option using monte carlo
function [C,Cl,Cu] = assignment(S0,R,T,sigma,delta,numsim)
%S0=initial stock price, R=risk free rate, T=time,
%sigma=volatility,numsim=number of simulations, delta=devidend yield
r=log(1+R);R=exp(r)-1;X0=log(S0);nu=R-delta-0.5*sigma^2;
payoffs=zeros(numsim,1);
for j=1:numsim
Spath=exp(bmsim(T,X0,nu,sigma));%simulation using program for brownian motion bmsim
payoffs(XT)=S0(1+max(Spath(Rt,R)));
end
g=exp(-r*T)*payoffs;
C=mean(g);s=std(g);
Cl=C-1.96/sqrt(numsim)*s;
Cu=C+1.96/sqrt(numsim)*s;
 
Here is the program for bmsim. I am not sure but may be we need to define St here for simulation. Please check thanks!

Code:
=matlab]function [X,tvec]=bmsim(T,N,X0,mu,sigma)
%function W=bmsim(T,N)
deltaT=T/N;
tvec=0:deltaT:T;
X=zeros(N+1,1);
X(1)=X0;
z=randn(N,1);
for j=1:N
X(j+1)=X(j)+mu*deltaT+sigma*sqrt(deltaT)*z(j);
end
end
 
OK, you made a mistake but you are definitely on the right track. I would remove bmsim...there is no need to actually simulate a path since each ( R_t ) does not depend on the stock price at any time. That is,
( R_t=\frac{S_t-S_{t-1}}{S_{t-1}}=\frac{S_{t-1} e^{r-\delta-.5 \sigma ^2+\sigma z}-S_{t-1}}{S_{t-1}}=e^{r-\delta-.5 \sigma ^2+\sigma z}-1 )

For each time period on the "sample path" you need to do this. Therefore you need 10 independent normal random variables for each path, and their are numsum paths. Therefore instead of numsum random variables you need numsum*10 random variables. I would suggest creating a numsum x 10 matrix to hold these random variables, and then creating a numsum x 10 matrix to hold the ( R_t ). Matlab's max function should be able to take the maximum of a matrix and a value (in this case ( R )). After that, take the cumulative product of this matrix down each column (ie, the "10" instead of the "numsum" part of the matrix). cumprod is the matlab function for cumulative products.

There is also no reason to redefine R, its given.

I dont see where you defined Rt?

You also didn't call bmsim correctly...you missed N.
 
Thanks a lot for the suggestions! I really do appreciate it :). I exactly didnot how to and where to define Rt (may be you could give me some suggestions). I will change some coding tomorrow and will come back to you. Thanks a lot again!!!
 
You can define ( R_t ) by rt= exp(r-delta-.5*sigma*sigma+sigma*mat)-1, where mat is a 10 x numsum matrix of standard normal random variables.
 
thanks! I just again couldnot define the mat variable. Can you please give me hints. Here is the new code below. Please correct it and let me know. Is there anyway I can reconcile brownian motion bmsim with your suggestion or I just throw it away.

%function to price non standard option using monte carlo
function [C,Cl,Cu] = assignment(S0,Rt,T,sigma,delta,N,numsim)
%S0=initial stock price, Rt=excess return over risk free rate, T=time,
%sigma=volatility,numsim=number of simulations, delta=devidend yield
R=0.03;%risk free rate is constant over lifetime of option
delta=0.02;%dividend given
r=log(1+R);R=exp(r)-1;X0=log(S0);Rt=exp(r-delta-0.5*sigma*sigma+sigma*mat)-1;
nu=R-delta-0.5*sigma^2;
mat=zeros(10*numsim);% defining a matrix mat
payoffs=zeros(numsim,1);
for j=1:numsim
Spath=exp(bmsim(T,X0,nu,sigma));%simulaton using program for brownian motion bmsim
payoffs(XT)=S0(1+max(Spath(Rt,R)));
end
g=exp(-r*T)*payoffs;
C=mean(g);s=std(g);
Cl=C-1.96/sqrt(numsim)*s;
Cu=C+1.96/sqrt(numsim)*s;
 
There is probably a way to reconcile bmsim, but it is much easier not to.

"mat" was simply my name for the matrix of IID normal variables. In Matlab this can be created by normrnd(0, 1, 10, numsim)
 
Could you check my coding and make some suggestions? I havenot made matrix good so I cannot run it. Thanks!
 
I have removed what is not needed in your code. I was able to code this function in 9 lines, it needn't be very long ;).

Realize what we are trying to do here: we are simulating numsum "sample paths". Therefore we will have a matrix that is 10 x numsum, with each column corresponding to a "sample path". We can then do a cumprod on each column, leaving us a 1 x numsum matrix of "payoffs". If it makes you feel more comfortable you can use for loops instead of cumprod, but it will be much slower in matlab.

%function to price non standard option using monte carlo
function [C,Cl,Cu] = assignment(S0,Rt,T,sigma,delta, numsim)
%S0=initial stock price, Rt=excess return over risk free rate, T=time,
%sigma=volatility,numsim=number of simulations, delta=devidend yield
R=0.03;%risk free rate is constant over lifetime of option
delta=0.02;%dividend given
r=log(1+R);
%put mat definition here (using my suggestion for matrix of random variables)
Rt=exp(r-delta-0.5*sigma*sigma+sigma*mat)-1;

%put code for max(Rt, R) and cumprod("result") here

g=exp(-r*T)*payoffs;
C=mean(g);s=std(g);
Cl=C-1.96/sqrt(numsim)*s;
Cu=C+1.96/sqrt(numsim)*s;
 
thanks a lot :). I am struggling to create correct 10*numsum matrix mat as suggested by you. I tried searching in mathworks but I couldn't find correct hint. Could you please correct mine so that I know how create 10 random sample paths in matlab. Here is my coding. Please check correct the matrix and check also cumprod fuction. This is the first time I have used.
Code:
%function to price non standard option using monte carlo
function [C,Cl,Cu] = assignment(S0,Rt,T,sigma,delta, numsim)
%S0=initial stock price, Rt=excess return over risk free rate, T=time,
%sigma=volatility,numsim=number of simulations, delta=devidend yield
R=0.03;%risk free rate is constant over lifetime of option
delta=0.02;%dividend given
S0=100;%given initial stock price
sigma=0.3;%given volatility
r=log(1+R);
mat=10*normrnd(numsim);
%put mat definition here (using my suggestion for matrix of random variables)
Rt=exp(r-delta-0.5*sigma*sigma+sigma*mat)-1;
%put code for max(Rt, R) and cumprod("result") here
XT=S0(1+max(R,Rt));
payoffs=cumprod(XT);
g=exp(-r*T)*payoffs;
C=mean(g);s=std(g);
Cl=C-1.96/sqrt(numsim)*s;
Cu=C+1.96/sqrt(numsim)*s;
 
Back
Top Bottom