samedi 2 juin 2018

Random walk algorithm for pricing barrier options

Can someone help me realize this with matlab? I don't understand this algorithm, because the condition 3) never holds. I post my code in the end.

Choose a time-step h>0 so that M=9/h is a integer. 
Set log(L_0) = L_0 = 0.13 and Z(0)=0.
rho_k are independent random variables distributed by the law P(+-1)=0.5


1) log(L_{k+1}) = log(L_k)-0.5*sigma^2*h+sigma*sqrt(h)*rho_{k+1}

2) Z_{k+1} = Z_k - sigma* [(erfc((2*2^(1/2)*(log((25*exp(log L_k))/7) + 9/32))/3)/2 - erfc((2*2^(1/2)*(log(100*exp(log L_k)) + 9/32))/3)/2 + erfc((2*2^(1/2)*(log(7/(25*exp(log L_k))) - 9/32))/3)/56 - erfc((2*2^(1/2)*(log(196/(25*exp(log L_k))) - 9/32))/3)/56 + (exp(log L_k)*((2*2^(1/2)*exp(-(8*(log(7/(25*exp(log L_k))) - 9/32)^2)/9))/(3*exp(log L_k)*pi^(1/2)) - (2*2^(1/2)*exp(-(8*(log(196/(25*exp(log L_k))) - 9/32)^2)/9))/(3*exp(log L_k)*pi^(1/2))))/28 - exp(log L_k)*((2*2^(1/2)*exp(-(8*(log((25*exp(log L_k))/7) + 9/32)^2)/9))/(3*exp(log L_k)*pi^(1/2)) - (2*2^(1/2)*exp(-(8*(log(100*exp(log L_k)) + 9/32)^2)/9))/(3*exp(log L_k)*pi^(1/2))) - (14*2^(1/2)*exp(-(8*(log(7/(25*exp(log L_k))) + 9/32)^2)/9))/(75*exp(log L_k)*pi^(1/2)) + (14*2^(1/2)*exp(-(8*(log(196/(25*exp(log L_k))) + 9/32)^2)/9))/(75*exp(log L_k)*pi^(1/2)) + (2^(1/2)*exp(-(8*(log((25*exp(log L_k))/7) - 9/32)^2)/9))/(150*exp(log L_k)*pi^(1/2)) - (2^(1/2)*exp(-(8*(log(100*exp(log L_k)) - 9/32)^2)/9))/(150*exp(log L_k)*pi^(1/2))))]*sqrt(h)*rho_{k+1};

3) log L_k < log(H)+1/2*sigma^2*h-sigma*sqrt(h)


H=0.28
sigma=0.25
K=0.01

To realize the algorithm we follow the random walk generated by (1), and at each time t_k; we check whether the condition (3) holds. If it does not, L_k has reached the boundary zone and we stop the chain at log(H). If it does, we perform (1)-(2) to find log(L_k+1) and Z_{k+1}. If k + 1 = M; we stop, otherwise we continue with the algorithm. The outcome of simulating each trajectory is a point (t_kappa, log(L_kappa), Z_kappa). Evaluate the expectation E[(exp(log(L_{kappa}))-K)^+ * Chi(kappa=M) + Z_{kappa}]=price with the Monte Carlo technique and do 10^6 Monte Carlo runs.

Here is my code. It doesn't work, because I don't get something near 0.0657 (the result).

Y=zeros(1,M+1); %ln L_k = Y(k)
Z=zeros(1,M+1);
sigma=0.25;
H=0.28;
K=0.01;
Y(1)=0.13; 
Z(1)=0;

M=90;
h=0.1;

for k=1:M+1
    vec=[-1 1];
    index= random('unid', length(vec),1);
    x(1,k)=vec(index);
end %'Rho' 

for k=1:M
    if Y(k)<log(H)+1/2*sigma^2*h-sigma*sqrt(h) %Bedingung
        Y(k+1) = Y(k)-(1/2)*(sigma)^2*h + sigma*sqrt(h)*x(k+1);
        Z(k+1)=Z(k)+(-sigma*(erfc((2*2^(1/2)*(log((25*exp(Y(k)))/7) + 9/32))/3)/2 - erfc((2*2^(1/2)*(log(100*exp(Y(k))) + 9/32))/3)/2 + erfc((2*2^(1/2)*(log(7/(25*exp(Y(k)))) - 9/32))/3)/56 - erfc((2*2^(1/2)*(log(196/(25*exp(Y(k)))) - 9/32))/3)/56 + (exp(Y(k))*((2*2^(1/2)*exp(-(8*(log(7/(25*exp(Y(k)))) - 9/32)^2)/9))/(3*exp(Y(k))*pi^(1/2)) - (2*2^(1/2)*exp(-(8*(log(196/(25*exp(Y(k)))) - 9/32)^2)/9))/(3*exp(Y(k))*pi^(1/2))))/28 - exp(Y(k))*((2*2^(1/2)*exp(-(8*(log((25*exp(Y(k)))/7) + 9/32)^2)/9))/(3*exp(Y(k))*pi^(1/2)) - (2*2^(1/2)*exp(-(8*(log(100*exp(Y(k))) + 9/32)^2)/9))/(3*exp(Y(k))*pi^(1/2))) - (14*2^(1/2)*exp(-(8*(log(7/(25*exp(Y(k)))) + 9/32)^2)/9))/(75*exp(Y(k))*pi^(1/2)) + (14*2^(1/2)*exp(-(8*(log(196/(25*exp(Y(k)))) + 9/32)^2)/9))/(75*exp(Y(k))*pi^(1/2)) + (2^(1/2)*exp(-(8*(log((25*exp(Y(k)))/7) - 9/32)^2)/9))/(150*exp(Y(k))*pi^(1/2)) - (2^(1/2)*exp(-(8*(log(100*exp(Y(k))) - 9/32)^2)/9))/(150*exp(Y(k))*pi^(1/2))))*sqrt(h)*x(k+1);

    else
        Y(k)=log(H);

        break





    end

end


if k == M

end

if (L(M)-K) > 0
(L(M)-K);

else
0;
end

return
exp(Y(M))-K+Z(M)




Aucun commentaire:

Enregistrer un commentaire