// TP7_19 Collar
n=50;T=1;sigma=0.4;S0=120; K=S0; r=0.25;
deltat=T/n;
up=exp(sigma*sqrt(deltat));down=1/up;
R=exp(r*deltat); p=(R-down)/(up-down);
function s=S(i,j);s=S0.*up^j.*down^(i-j); endfunction;
function monphi=phi(S,K); monphi=max(S-K,0); endfunction;
function moncall=Call(K);moncall=phi(S(n,0:n),K)*binomial(p,n)'/R^n; endfunction;
function monput=Put(K); monput=Call(K)-S0+K*exp(-r*T) endfunction;
function dif=difference(K); dif=Call(K)-Put(S0) endfunction;
// Question 4
Kcollar=fsolve(S0,difference);disp(Kcollar,"Kcollar="); 
// Question 7
S0*exp(r*T)
// Question 8
function dif=Ldifference(K); dif=Call(K)-Put(0.9*S0) endfunction;
Lcollar=fsolve(S0,Ldifference);disp(Lcollar,"Lcollar="); 

