<<d:opcie\diffuse.m

WeinerProcessMake[w]
DiffusionPrint[w]

sim1=DiffusionSimulate[w,100,0.01]

ListPlot[sim1,Joined->True,PlotRange->All]

sim2=DiffusionSimulate[w,100,0.01];
ListPlot[sim2,Joined->True,PlotRange->All]

(*Generovanie postupnosti realizacii Wienerovho procesu*)
PocetPokusov=5;T=2;PocetKrokov=200;Krok=T/PocetKrokov;
Do[sim[i]=DiffusionSimulate[w,PocetKrokov,Krok];
graf[i]=ListPlot[sim[i],Joined->True,PlotRange->All,Frame->True,PlotStyle->Hue[i/PocetPokusov]],{i,1,PocetPokusov}]

Show[Table[graf[i],{i,1,PocetPokusov}]](*vytvorenie grafu vsetkych realizacii*)

mi=0.1;sigma=0.04;s0=100;
Clear[s];
grafdet=Plot[s0*Exp[mi*t],{t,0,10},PlotRange->All]

DiffusionMake[s,w,mi*s,sigma*s,s0]
DiffusionPrint[s]

simulacia=DiffusionSimulate[s,100,0.1];
grafdifuzie=ListPlot[simulacia,Joined->True,PlotRange->All]

Show[grafdet,grafdifuzie]

mi=0.1;sigma=0.3;s0=100;
Clear[s];
grafdet=Plot[s0*Exp[mi*t],{t,0,10},PlotRange->All];
DiffusionMake[s,w,mi*s,sigma*s,s0];
DiffusionPrint[s];
simulacia=DiffusionSimulate[s,100,0.1];
grafdifuzie=ListPlot[simulacia,Joined->True,PlotRange->All];
Show[grafdet,grafdifuzie]

R=0.1;H0=100;m=1;n=10;
H0(1+R/m)^(m n)
H0 Exp[R n]

R=0.1;H0=100;m=12;n=10;
H0(1+R/m)^(m n)
H0 Exp[R n]

R=0.1;H0=100;m=365;n=10;
H0(1+R/m)^(m n)
H0 Exp[R n]

(**********************************)
(*     Europske call a put opcie  *)
(*********************************)

CallPayoff[s_,x_]:=Max[0,s-x]
Plot[CallPayoff[s,60],{s,0,100},PlotStyle->{Red,Thickness[0.01]}]

PutPayoff[s_,x_]:=Max[x-s,0]
Plot[PutPayoff[s,60],{s,0,100},PlotStyle->{Red,Thickness[0.01]}]

Plot[PDF[NormalDistribution[0,1],x],{x,-4,4},PlotRange->All]

Plot[CDF[NormalDistribution[0,1],x],{x,-4,4}]

NormalCDF[u_]:=CDF[NormalDistribution[0,1],u];
Print[NormalCDF[u]];
Plot[NormalCDF[u],{u,-4,4}]

(*Explicitny vzorec pre europsku call opciu so spojitou dividendou *)

EuropeanCall[s_,x_,sigma_,r_,d_,tau_]:=
Module[{d1,d2},
d1=(Log[s/x]+(r-d+sigma^2/2)*tau)/(sigma*Sqrt[tau]);
d2=d1-sigma*Sqrt[tau];
Return[Exp[-d*tau]*s*NormalCDF[d1]-x*Exp[-r*tau]*NormalCDF[d2]]];

(* Explicitny vzorec pre europsku put opciu so spojitou dividendou*)

EuropeanPut[s_,x_,sigma_,r_,d_,tau_]:= EuropeanCall[s,x,sigma,r,d,tau] + x * Exp[-r tau] - s * Exp[-d tau];

(* Prikladpre pouzitia pre hodnoty
	s = 58.5; X = 60; sigma = 0.29; r = 0.04; D = 0.02; T = 0.3 *)

Print["ECall= ", EuropeanCall[58.5,60,0.1,0.04,0.02,0.5]];
Print["EPut= ", EuropeanPut[58.5,60,0.1,0.04,0.02,0.5]];

X = 60; sigma = 0.4; r = 0.04; d = 0; T = 1
Print[" Europsky Call pre hodnoty "];
Print[" X = ", X, " σ = ", sigma. " r = ", r, " d = ", d, " T = ", T];

Manipulate[
Plot[{CallPayoff[S,X],EuropeanCall[S,X,sigma,r,d,tau]},{S,20,100},
Frame->True,
PlotStyle->{{Thickness[0.005],Red},{Thickness[0.005],Blue}},
PlotLabel->"Europsky Call",
FrameLabel->{"Cena akcie", "Cena opcie", "", ""},
PlotRange->{0,40}],
{tau, T, 0.01,-0.01}]

Plot3D[EuropeanCall[S,X,sigma,r,d,tau],{S,20,100},{tau,0,1}]

X = 60; sigma = 0.4; r = 0.04; d = 0; T = 1
Print[" Europsky Put pre hodnoty "];
Print[" X = ", X, " σ = ", sigma. " r = ", r, " d = ", d, " T = ", T];

Manipulate[
Plot[{PutPayoff[S,X],EuropeanPut[S,X,sigma,r,d,tau]},{S,20,100},
Frame->True,
PlotStyle->{{Thickness[0.005],Red},{Thickness[0.005],Blue}},
PlotLabel->"Europsky Put",
FrameLabel->{"Cena akcie", "Cena opcie", "", ""},
PlotRange->{0,40}],
{tau, T, 0.01,-0.01}]

X = 60; sigma = 0.4; r = 0.04; d = 0.1; T = 1
Print[" Europsky Call pre hodnoty s dividendami"];
Print[" X = ", X, " σ = ", sigma. " r = ", r, " d = ", d, " T = ", T];

Manipulate[
Plot[{CallPayoff[S,X],EuropeanCall[S,X,sigma,r,d,tau]},{S,20,100},
Frame->True,
PlotStyle->{{Thickness[0.005],Red},{Thickness[0.005],Blue}},
PlotLabel->"Europsky Call s dividendami",
FrameLabel->{"Cena akcie", "Cena opcie", "", ""},
PlotRange->{0,40}],
{tau, T, 0.01,-0.01}]

(***************************************************)
(*              28. februara 2008                  *)
(***************************************************)

(* trinomicky strom 
k - casovy krok  , k = (SuperStar[τ]) / m, m - hlbka stromu, (SuperStar[τ]) = τ - cas do expiracie
h - priestorovy krok

(Subscript[u, i]^(j+1)) = ( a (Subscript[u, i+1]^j) + b (Subscript[u, i]^j) + c (Subscript[u, i+1]^j) ) / (1 + r k)
a = (k σ^2)/(2 h^2) + (k σ^2)/(4 h) - (k r)/(2 h)
b = 1 - (k σ^2)/(h^2)
c = (k σ^2)/(2 h^2) - (k σ^2)/(4 h) + (k r)/(2 h)
(Subscript[u, i]^0) = u((Subscript[x, i]), 0) = 0, (Subscript[x, i]) ≤ ln(X) inak (e^(Subscript[x, i]))- X , (Subscript[x, i]) > ln(X)
*)

TrinomialTree[S_,X_,σ_,r_,τ_,m_] :=
Module[ {k,h, a, b, c}, 
k = τ / m;
h = Sqrt[k];
TransfCallPayoff[x_] := If[x ≤ Log[X], 0, Exp[x]-X];
Do[u[i,0]=TransfCallPayoff[Log[S]+(i h)],{i,-m,m}];
a = (k σ^2)/(2 h^2) + (k σ^2)/(4 h) - (k r)/(2 h);
b = 1 - (k σ^2)/(h^2);
c = (k σ^2)/(2 h^2) - (k σ^2)/(4 h) + (k r)/(2 h);
Do[Do[u[i,j+1]=(a u[i-1,j] + b u[i,j]+ c u[i+1,j]) / (1 + (k r)),{i,-m+j+1,m+j-1}],{j,0,m-1}];
Print["Priblizna cena call opcie = ", u[0,m]]
]

Print["Presna cena call opcie = ", EuropeanCall[58.5,60,0.29,0.04,0,0.3]];
TrinomialTree[58.5,60,0.29,0.04,0.3,3]

Print["Presna cena call opcie = ", EuropeanCall[58.5,60,0.29,0.04,0,0.3]];
Do[{Print["m = ",m],TrinomialTree[58.5,60,0.29,0.04,0.3,m]},{m,1, 100}]