// Question 5 // La formule de Black et Scholes // pour verifier function [y]=NN(x) [y,Q]=cdfnor("PQ",x,0,1); endfunction function [res] = BS_Call(S_0,K,sigma,r,T) d1=(log(S_0/K)+(r+sigma^2/2)*T)/(sigma*sqrt(T)); d2=d1-sigma*sqrt(T); res=S_0*NN(d1)-K*exp(-r*T)*NN(d2); endfunction // Le payoff function [y]=call(x,K) // ones(x) rend la fonction vectorielle : // x peut etre un vecteur auquel cas y est un vecteur de meme taille y=max(x-K*ones(x),0); endfunction function []=test_call_girsanov(r, sigma, S_0, T, K, lambda,N) W_T = sqrt(T)*rand(1,N,"gauss"); S_T = S_0*exp((r-sigma^2/2)*T + sigma*(W_T+lambda* T)); payoff = exp(-r*T) * call(S_T,K); // Pour l'importance voir la formule du texte importance = *************...************ ; payoff = importance .* payoff; estimation=mean(payoff); // estimation de la moyenne ecart_type=stdev(payoff); // estimation de l'ecart type erreur=1.96*ecart_type/sqrt(N); // demi-largeur de l'intervalle de confiance printf("Girsanov, lambda=%f, N=%d, %f +- %f\n",lambda, N, estimation, erreur); endfunction T=1; // an S_0=100; r=0.05; // par an sigma=0.3; // par racine d'annee sigma^2 * T est sans dimension N=10000; K=150; lambda=0;// simulation naturelle, importance=1 test_call_girsanov(r, sigma, S_0, T, K, lambda,N); lambda= (log(K/S_0)-(r-sigma^2/2)*T)/(sigma*sqrt(T)); // avec ce lambda avec proba 1/2, S_T > K, condition d'exercice test_call_girsanov(r, sigma, S_0, T, K, lambda,N); // Vérification BS_Call(S_0,K,sigma,r,T) K=200; lambda=0;// simulation naturelle, importance=1 test_call_girsanov(r, sigma, S_0, T, K, lambda,N); lambda= (log(K/S_0)-(r-sigma^2/2)*T)/(sigma*T); // avec ce lambda avec proba 1/2, S_T > K, condition d'exercice test_call_girsanov(r, sigma, S_0, T, K, lambda,N); // Vérification BS_Call(S_0,K,sigma,r,T)