Computational finance
This presentation is the property of its rightful owner.
Sponsored Links
1 / 105

Computational Finance PowerPoint PPT Presentation


  • 102 Views
  • Uploaded on
  • Presentation posted in: General

Computational Finance. Zvi Wiener 02-588-3049 http://pluto.mscc.huji.ac.il/~mswiener/zvi.html. Plan. 1. Introduction, deterministic methods. 2. Stochastic methods. 3. Monte Carlo I. 4. Monte Carlo II. 5. Advanced methods for derivatives. Other topics:

Download Presentation

Computational Finance

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Computational finance

Computational Finance

Zvi Wiener

02-588-3049

http://pluto.mscc.huji.ac.il/~mswiener/zvi.html

Bank Hapoalim


Computational finance

Plan

1. Introduction, deterministic methods.

2. Stochastic methods.

3. Monte Carlo I.

4. Monte Carlo II.

5. Advanced methods for derivatives.

Other topics:

queuing theory, floaters, binomial trees, numeraire, ESPP, convertible bond, DAC, ML-CHKP.

CF1


Linear algebra

Linear Algebra

1

-2 1

Vectors {1, 1}, {-2, 1}

rows or1-2

columns1 1

CF1


Linear algebra1

Linear Algebra

CF1


Basic operations

Basic Operations

1 2 3

2 +-1= 1

-2 1-1

13

3 2 =6

26

CF1


Linear algebra2

Linear Algebra

vector

Vectors form a linear space.

Zero vector

Scalar multiplication

CF1


Linear algebra3

Linear Algebra

Matrices also

form a linear

space.

matrix

Zero matrix

Unit matrix

CF1


Linear algebra4

Linear Algebra

Matrix can operate on a vector

How does zero matrix operate?

How does unit matrix operate?

CF1


Linear algebra5

Linear Algebra

Transposition of a matrix

A symmetric matrix is A=AT

for example a variance-covariance matrix.

CF1


Linear algebra6

Linear Algebra

Matrix multiplication

CF1


Scalar product

Scalar Product

a is orthogonal to b if ab = 0

CF1


Linear algebra7

Linear Algebra

Scalar product of two vectors

Euclidean norm

CF1


Determinant

Determinant

Determinant is 0 if the operator maps

some vectors to zero (and can not be inverted).

CF1


Linear algebra8

Linear Algebra

  • Matrix multiplication corresponds to a consecutive application of each operator.

  • Note that it is not commutative! ABBA.

  • Unit matrix does not change a vector.

  • An inverse matrix is such that AA-1=I.

CF1


Linear algebra9

Linear Algebra

  • Determinant of a matrix ...

  • A matrix can be inverted if det(A)0

  • Rank of a matrix

  • Matrix as a system of linear equations Ax=b.

  • Uniqueness and existence of a solution.

  • Trace tr(A) – sum of diagonal elements.

CF1


Linear algebra10

Linear Algebra

  • Change of coordinates C-1AC.

  • Jordan decomposition.

  • Matrix power Ak.

  • Matrix as a quadratic form (metric) xTAx.

  • Markov process.

  • Eigenvectors, eigenvalues Ax=x, optimization.

CF1


Problems

Problems

Check how the following matrices act on vectors:

CF1


Simple exercises

Simple Exercises

  • Show an example of ABBA.

  • Construct a matrix that inverts each vector.

  • Construct a matrix that rotates a two dimensional vector by an angle .

  • Construct a covariance matrix, show that it is symmetric.

  • What is mean and variance of a portfolio in matrix terms?

CF1


Examples

Examples

  • Credit rating and credit dynamics.

  • Variance-covariance model of VaR.

  • Can the var-covar matrix be inverted

  • VaR isolines (the ovals model).

  • Prepayment model based on types of clients.

  • Finding a minimum of a function.

CF1


Calculus

Calculus

  • Function of one and many variables.

  • Continuity in one and many directions.

  • Derivative and partial derivative.

  • Gradient and Hessian.

  • Singularities, optimization, ODE, PDE.

CF1


Linear and quadratic terms

Linear and quadratic terms

$

x

CF1


Taylor series

Taylor series

CF1


Variance covariance

Variance-Covariance

CF1


Variance covariance1

Variance-Covariance

Gradient vector:

CF1


Variance covariance2

Variance-Covariance

CF1


Variance covariance3

Variance-Covariance

CF1


Variance covariance4

Variance-Covariance

For a short time period , the changes in the value are distributed approximately normal with the following mean and variance:

CF1


Variance covariance5

Variance-Covariance

Then VaR can be found as:

CF1


Weighted variance covariance

Weighted Variance covariance

Volatility estimate on day i based on last M days.

CF1


Weighted variance covariance1

Weighted Variance covariance

Covariance on day i based on last M days.

It is important to check that the resulting

matrix is positive definite!

CF1


Positive quadratic form

Positive Quadratic Form

For every vector x a we have x.A.x > 0

Only such a matrix can be used to define a norm.

For example, this matrix can not have negative diagonal elements. Any variance-covariance matrix must be positive.

CF1


Positive quadratic form1

Positive Quadratic Form

Needs["LinearAlgebra`MatrixManipulation`"];

ClearAll[ positiveForm ];

positiveForm[ a_?MatrixQ ] := Module[{aa, i},

aa = Table[

Det[ TakeMatrix[ a, {1, 1}, {i, i}] ],

{i, Length[a]}];

{ aa, If[ Count[ aa, t_ /; t < 0] > 0, False, True]}

];

CF1


Stochastic transition matrix

Stochastic (transition) Matrix

Used to define a Markov chain (only the last state matters).

A matrix P is stochastic if it is non-negative and sum of elements in each line is 1.

One can easily see that 1 is an eigenvalue of any stochastic matrix.

What is the eigenvector?

CF1


Markov chain

Markov chain

  • credit migration

  • prepayment and freezing of a program

CF1


Stochastic transition matrix1

Stochastic (transition) Matrix

Theorem: P0 is stochastic iff (1,1,…1) is an eigenvector with an eigenvalue 1 and this is the maximal eigenvalue.

If both P and PT are stochastic, then P is called double stochastic.

CF1


Cholesky decomposition

Cholesky decomposition

The Cholesky decomposition writes a symmetric positive definite matrix as the product of an upper­triangular matrix and its transpose.

In MMACholeskyDecomposition[m]

CF1


Generating random samples

Generating Random Samples

We need to sample two normally distributed variables with correlation .

If we can sample two independent Gaussian variables x1 and x2 then the required variables can be expressed as

CF1


Generating random samples1

Generating Random Samples

We need to sample n normally distributed variables with correlation matrix ij, ( >0).

Sample n independent Gaussian variables x1…xn.

CF1


Function of a matrix

Function of a matrix

CF1


Computational finance

ODE

CF1


Computational finance

ODE

CF1


Bisection method

Bisection method

f

If the function is monotonic, e.g. implied vol.

x

CF1


Newton s method

Newton’s method

f

x2

x3

x

x1

CF1


Solve and findroot

Solve and FindRoot

Solve[ 0 = = x2- 0.8x3- 0.3, {x}]

{{x -> -0.467297}, {x ->0.858648 -0.255363*I}, {x -> 0.858648 + 0.255363*I}}

FindRoot[ x2 + Sin[x] - 0.8x3 - 0.3, {x, 0,1}]

{x -> 0.251968}

CF1


Max min of a multidimensional function

Max, min of a multidimensional function

  • Gradient method

  • Solve a system of equations(both derivatives)

CF1


Gradient method

Gradient method

CF1


Level curve of a multivariate function

Level curve of a multivariate function

ContourPlot[ x^2+y^3, {x,-2,2}, {y,- 2,2}]

ContourPlot[ x^2+y^3, {x,-2,2}, {y,- 2,2}], Contours->{1 ,-0.5}, ContourShading->False];

CF1


Contourplot x 2 y 3 x 2 2 y 2 2

ContourPlot[ x^2+y^3, {x,-2,2}, {y,- 2,2}]

CF1


Contourplot x 2 y 3 x 2 2 y 2 2 contours 1 0 5 contourshading false

ContourPlot[ x^2+y^3, {x,-2,2}, {y,- 2,2}], Contours->{1 ,-0.5}, ContourShading->False];

CF1


Example

Example

Consider a portfolio with two risk factors and benchmark duration of 6M.

The VaR limit is 3 bp. and you have to make two decisions:

a – % of assets kept in spread products

q – duration mismatch

we assume that all instruments (both treasuries and spread) have the same duration T+q months.

CF1


Contour levels of var static

Contour Levels of VaR (static)

q - duration

mismatch

a (% of spread)

CF1


Computational finance

VaR=3 bp

position

VaR=2 bp

q - duration

mismatch

a (% of spread)

CF1


Computational finance

In order to reduce

risk one can increase duration

(in this case).

q - duration

mismatch

a (% of spread)

CF1


Computational finance

What we can do using limits

VaR = 6 bp

CF1


Computational finance

duration mismatch (yr)

Position 2M, and

10% spread

5% weekly VaR=2.2 bp

weekly VaR limit 3 bp

spread %

CF1


Splines

Splines

x1x2x3…xn

CF1


Splines1

Splines

<<Graphics`Spline`

pts = {{0, 0}, {1, 2}, {2, 3}, {3, 1}, {4, 0}}

Show[

Graphics[

Spline[pts, Cubic, SplineDots -> Automatic]]]

CF1


Splines2

Splines

pts = Table[{i, i + i^2 + (Random[] - 0.5)}, {i, 0, 1, .05}];

Show[Graphics[Spline[pts,Cubic,SplineDots ->Automatic]]]

CF1


Fitting data

Fitting data

data = Table[7*x + 3 + 10*Random[], {x, 10}];

f[x_] := Evaluate[Fit[data, {1, x}, x]]

Needs["Graphics`Graphics`"]

DisplayTogether[

ListPlot[data, PlotStyle -> {AbsolutePointSize[3],

RGBColor[1, 0, 0]}],

Plot[f[x], {x, 0, 10}, PlotStyle -> RGBColor[0, 0, 1]]

];

CF1


Fitting data1

Fitting data

CF1


Fitting data2

Fitting data

data = {{1.0, 1.0, .126}, {2.0, 1.0, .219},

{1.0, 2.0, .076}, {2.0, 2.0, .126}, {.1, .0, .186}};

ff[x_, y_] = NonlinearFit[data,

a*c*x/(1 + a*x + b*y), {x, y}, {a, b, c}];

ff[x, y]

nonlinear, multidimensional

CF1


Orly nelson siegel

Orly - Nelson Siegel

MAKAM

CF1


Numerical differentiation

Numerical Differentiation

CF1


Numerical differentiation1

Numerical Differentiation

CF1


Finite differences

S

time

Finite Differences

Following P. Wilmott, “Derivatives”

Typically equal time and S (or logS) steps.

CF1


Finite differences1

Finite Differences

Time step t

asset step S

(i,k) node of the grid is t = T - kt, iS

0  i  I, 0  k  K

assets value at each node is

note the direction of time!

CF1


The black scholes equation

The Black-Scholes equation

Linear parabolic PDE

Final conditions

Boundary conditions ...

CF1


Transformation of bs

Transformation of BS

CF1


Approximating

Approximating 

CF1


Approximating1

Approximating 

CF1


Approximating2

Approximating 

CF1


Bilinear interpolation

Bilinear Interpolation

V1

V2

A4

A3

A1

A2

Area of the rectangle

V3

V4

CF1


Final conditions and payoffs

Final conditions and payoffs

For example a European Call option

CF1


Boundary conditions call

Boundary conditions Call

For example a Call option

For large S the Call value asymptotes to

S-Ee-r(T-t)

CF1


Boundary conditions put

Boundary conditions Put

For example a Put option

For large S

CF1


Boundary conditions s 0

Boundary conditions S=0

CF1


Explicit scheme

Explicit scheme

CF1


Explicit scheme1

Explicit scheme

Local truncation error

CF1


Explicit scheme2

Explicit scheme

Value here is calculated

S

These values are

already known

time

CF1


Explicit scheme3

Explicit scheme

This equation is defined for 1i I-1,

for i=1 and i=I we use boundary conditions.

CF1


Explicit scheme4

Explicit scheme

For the BS equation (with dividends)

CF1


Explicit scheme5

Explicit scheme

Stability problems related to step sizes.

These relationships should guarantee stability.

Note that reducing asset step by half we must reduce the time step by a factor of four.

CF1


Explicit scheme6

Explicit scheme

Advantages

easy to program, hard to make a mistake

when unstable it is obvious

coefficients can be S and t dependent

Disadvantages

there are restrictions on time step, which may cause slowness.

CF1


Implicit scheme

Implicit scheme

CF1


Implicit scheme1

Implicit scheme

CF1


Implicit scheme2

Implicit scheme

Values here are calculated

S

This value is used

time

CF1


Crank nicolson scheme

Crank-Nicolson scheme

CF1


Crank nicolson scheme1

Crank-Nicolson scheme

CF1


Crank nicolson scheme2

Crank-Nicolson scheme

Values here are calculated

S

These values are used

time

CF1


Crank nicolson scheme3

Crank-Nicolson scheme

A general form of the linear equation is:

Note that M are tridiagonal!

CF1


Crank nicolson scheme4

Crank-Nicolson scheme

Theoretically this equation can be solved as

In practice this is inefficient!

CF1


Lu decomposition

LU decomposition

M is tridiagonal, thus M=LU, where L is lower triangular, and U is upper triangular.

In fact L has 1 on the diagonal and one subdiagonal only, U has a diagonal and one superdiagonal.

CF1


Lu decomposition1

LU decomposition

Then in order to solve

Mv=q

or

LUv=q

We will solve

Lw=q

first, and then

Uv=w.

CF1


Lu decomposition2

LU decomposition

Very fast, especially when M is time independent.

Disadvantages:

Needs a big modification for American options

CF1


Other methods

Other methods

  • SOR successive over relaxation

  • Douglas scheme

  • Three time-level scheme

  • Alternating direction method

  • Richardson Extrapolation

  • Hopscotch method

  • Multigrid methods

CF1


Multidimensional case

Multidimensional case

Fixed t layer

S

These values are used

to calculate space derivatives

r

Note additional boundary conditions.

CF1


Geometrical brownian motion

Geometrical Brownian Motion

CF1


Lognormal process

Lognormal process

CF1


Euler scheme

Euler Scheme

CF1


Milstein scheme

Milstein Scheme

CF1


Stochastic calculus

Stochastic Calculus

Standard Normal

Diffusion process

ABM

GBM

CF1


Ito s lemma

dtdX

dt00

dX0dt

Ito’s Lemma

CF1


Computational finance

CF1


Siegel s paradox

Siegel’s paradox

Consider two currencies X and Y. Define S an exchange rate (the number of units of currency Y for a unit of X).

The risk-neutral process for S is

By Ito’s lemma the process for 1/S is

CF1


Siegel s paradox1

Siegel’s paradox

The paradox is that the expected growth rate of 1/S is not ry - rX, but has a correction term.

CF1


  • Login