function
[Call,Put] = TrinomialEuro(s0,k,T,n,r,sigma)
% s0 underlying asset price
% k exercise price
% T expiration date
% numbers of steps
% risk free rate
% sigma volitility of stock
deltat=T/n;
u=exp(sigma*sqrt(deltat));
d=1/u;
m=1;
P=(exp(2*r*deltat)+sigma^2*deltat-(d+1)*exp(r*deltat)+d)/((u^2-1)-(u-
1)*(d+1));
Q=(exp(r*deltat)-1-(u-1)*P)/(d-1);
M=1-Q-P;
for
i=1:n+1
for
j=1:n+2-i
s(i,j)=s0*u^(i-1)*m^(j-1)*d^(n+2-i-j);
w(i,j)=nchoosek(n,i-1)*P^(i-1)*nchoosek(n+1-i,j-1)*M^(j-1)*Q^(n+2-i-j
);
x(i,j)=max(s(i,j)-k,0);
y(i,j)=max(k-s(i,j),0);
cv(i,j)=w(i,j)*x(i,j);
pv(i,j)=w(i,j)*y(i,j);
end
end
Call=sum(cv(:))*exp(-r*T);
Put=sum(pv(:))*exp(-r*T);
Price=max(exp(-r*deltat)*(p*f(1,1)+q*f(1,2)),0); |