美式看跌期权:
function [] =
trinomialAmerican(T,n,K,r,sigma,S0)
T ;% experiation date
n ;%total number of periods
K; %exercise price
r ;%risk free interest rate
sigma ;%vloatility of
S0 ;
deltat=T/n;
u=exp(sigma*sqrt(deltat));
d=exp(-sigma*sqrt(deltat));
p=(sigma^2*deltat+exp(2*r*deltat)-exp(r*deltat)*(1+d)+d)/((u-1)*(u-d)); %risk adjusted probability
q=(exp(r*deltat)-1-p*(u-1))/(d-1);
m=1-p-q;
for i=1:n
for j=1:(2*i+1)
s(j,i)=d^(i-j+1)*S0; % stock price
end
end
for i=1:(2*n+1)
x(i,n)=max(s(i,n)-K,0);
y(i,n)=max(-s(i,n)+K,0);
end
for g=1:(n-1)
i=n-g;
for j=1:(2*i+1)
x(j,i)=max(max((s(j,i)-K),0),(m*x(j+1,i+1)+p*x(j+2,i+1)+q*x(j,i+1))*exp(-r*deltat)); % call
y(j,i)=max(max((-s(j,i)+K),0),(m*y(j+1,i+1)+p*y(j+2,i+1)+q*y(j,i+1))*exp(-r*deltat)); % European put
end
end
c=(m*x(2,1)+p*x(3,1)+q*x(1,1))*exp(-r*deltat)
p=(m*y(2,1)+p*y(3,1)+q*y(1,1))*exp(-r*deltat)
亚式期权:function [] =
trinomialAsian(T,n,K,r,sigma,S0,N)
T % expiration date;
n % numbers of steps;
K % exercise price;
r % risk free rate;
sigma % volitility of stock;
S0 % present price of stock;
deltat=T/n;
N % times of monte carlo;
大小:58 KB
只需: 4 个论坛币 马上下载
Project 1
Yahoo finance is one of the most important investment research site on the web. Yahoo finance provides the facilities like with stock prices that update automatically, you can get complete stock quotes from a big number of countries, options, mutual funds, ETFs, indexes, financial calendars, bonds, commodities and other financial assets, all in an easy to read format.Notes:
a)
欧式期权:
function [] = binomialeuro(T,n,k,r,sigma,s0,z)
T % expiration date
n % total number of periods
k % exercise price
r % risk free interest rate
sigma % volatility of
s0 % present price
deltat = T/n
z % devidend
u=exp(sigma*sqrt(deltat));
d=exp(-sigma*sqrt(deltat));
p=(exp((r-z)*deltat)-d)/(u-d);
q=1-p;
for i=1:n+1
s(i)=s0*u^(n+1-i)*d^(i-1); % stock price
w(i)=nchoosek(n,i-1)*p^(n+1-i)*q^(i-1); % probability
x(i)=max(s(i)-k,0); % call option price
y(i)=max(k-s(i),0); % put option price
cv(i)=w(i)*x(i);
pv(i)=w(i)*y(i);
end
C=sum(cv(:))*exp(-r*T)
P=sum(pv(:))*exp(-r*T)
美式看跌期权:
function [] = binomialamer(T,n,k,r,sigma,s0,z)
T % expiration date
n % total number of periods
k % exercise price
r % risk free interest rate
sigma % volatility of
s0 % present price
deltat = T/n
z % devidend
u=exp(sigma*sqrt(deltat));
d=exp(-sigma*sqrt(deltat));
p=(exp((r-z)*deltat)-d)/(u-d);
q=1-p;
for j=1:n
for i=1:j+1
s(j,i)=s0*u^(j+1-i)*d^(i-1);
y(j,i)=max(k-s(j,i),0);
end
end
for w=1:n
f(n-1,w)=max(y(n-1,w),exp(-r*deltat)*(p*y(n,w)+q*y(n,w+1)));
end
for g=n-2:-1:1
for h=1:g+1
f(g,h)=max(y(g,h),exp(-r*deltat)*(p*f(g+1,h)+q*f(g+1,h+1)));
end
end
P=max(exp(-r*deltat)*(p*f(1,1)+q*f(1,2)),0)
function [] =
trinomialAsian(T,n,K,r,sigma,S0,N)
T % expiration date;
n % numbers of steps;
K % exercise price;
r % risk free rate;
sigma % volitility of stock;
S0 % present price of stock;
deltat=T/n;
N % times of monte carlo;
u=exp(sigma*sqrt(deltat));
d=exp(-sigma*sqrt(deltat));
p=(sigma^2*deltat+exp(2*r*deltat)-exp(r*deltat)*(1+d)+d)/((u-1)*(u-d));
q=(exp(r*deltat)-1-p*(u-1))/(d-1);
m=1-p-q;
s(1)=S0;
for i=1:N
z=1;
for v=2:n+1
x=rand(1);
if x<=q
num=0;
end
if q<x
if x<q+m
num=1;
end
end
if x>=q+m
num=2;
end
z=z+num;
s(v)=d^(v-z)*S0;
end
price(i)=(sum(s(:))-S0)/n;
call(i)=max(price(i)-K,0)*exp(-r*T);
put(i)=max(-price(i)+K,0)*exp(-r*T);
end
ss=[1:n+1];
plot(ss-1,s(ss),'k-');
title('Random Stock Price')
xlabel('N'),ylabel('Stock Price')
call=sum(call(:))/N
put=sum(put(:))/N
扫码加好友,拉您进群



收藏
