[buy, sell] = TrinomialEuro(s0, k, t, n, r, sigma)
% s0 Base Asset Price
% k exercise price
% T expiration date
Percentage of steps
% risk-free interest rate
% sigma inventory change rate
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);