Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
%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;
=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
%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;