 # Computational Methods for (Quantitative) Finance

This University course focused on numerical solutions for some Quantitative Finance problems.

Notably, it included:

• Tree methods for the pricing of European contingent claims and empirical check of the convergence of the results to the Black and Scholes formula in the case of put and call options. Computation of the delta. Application of the methods in the case of American contingent claims
• Finite differences methods (implicit, explicit, Crank-Nicholson) for the pricing of European and American contingent claims. Stability and convergence
• Monte Carlo methods: Euler scheme for the simulation of trajectories of stochastic processes. Use of Monte Carlo methods for derivative pricing

it also involved:

• Monte Carlo integration
• Pseudorandom number generator (Linear congruential generator)
• Generation of random numbers from any kinds of distribution, continuous or discrete, given its Pdf or Cdf, and an uniform random number generator (inverse Cdf method) Examples from my final exam:

## Three correlated Geometric Brownian Motions:  ## European Call Option, Crank-Nicholson method:  123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 % CALLER SCRIPT s0 = 120; k = 150; t = 1; sig = 0.3; r = 0.02; prezzi = (80:2:130); mat = (0.1:0.05:1); [X, Y] = meshgrid(prezzi, mat); Z = zeros(size(X)); for i=1:length(prezzi) for j=1:length(mat) pr = es2(prezzi(i), k, mat(j),sig,r); Z(j,i) = pr; end end mesh(X, Y, Z); % FUNCTION function pr = es2(s0, k, t,sig,r) %ES2 Summary of this function goes here % Detailed explanation goes here % s0 = 120; % k = 150; % t = 1; % sig = 0.3; % r = 0.02; n = 252; dt = t/n; xMax = log(3); dx = sig*sqrt(3*dt); m = ceil(xMax/dx); payoff = max(0,s0*exp((-m:m)'*dx)-k); D = zeros(2*m+1, n+1); D(:,end) = payoff; fs = 1/(1+r*dt); nu = r-0.5*sig^2; a = (dt/4)*(-nu/dx+sig^2/dx^2); b = -0.5*dt*(r+(sig^2)/dx^2); c = (dt/4)*(nu/dx+sig^2/dx^2); A =-a*diag(ones(2*m,1),-1)+(1-b)*diag(ones(2*m+1,1))-c*diag(ones(2*m,1),1); A(1,1:2) = [1 0]; A(end, end-2:end) = [1 -2 1]; B =a*diag(ones(2*m,1),-1)+(1+b)*diag(ones(2*m+1,1))+c*diag(ones(2*m,1),1); B(1,1:2) = [fs 0]; B(end, end-2:end) = [0 0 0]; for i=n:-1:1 d = B*D(:,i+1); D(:,i) = A\d; end pr = D(m+1,1);