MATLAB Examples

cfaffineEx

Returns the extended characteristic function evaluation of a parameterized Affine Jump-Diffusion (AJD) process. Part of the CFH Toolbox.

Syntax

W = CFAFFINEEX(U,V,X0,TAU,K0,K1,H0,H1,R0,R1)
W = CFAFFINEEX(U,V,X0,TAU,K0,K1,H0,H1,R0,R1,L0,L1,jump,gradJump)
W = CFAFFINEEX(U,V,X0,TAU,K0,K1,H0,H1,R0,R1,L0,L1,jump,gradJump,ND)

See theory for a description of the coefficient matrices K0,K1,H0,H1,R0,R1,L0,L1. You may leave any unused coefficient empty [], e.g. CFAFFINEEX(U,V,X0,TAU,K0,[],H0,[],R0) describes a system with constant interest rate, drift and variance, whereas CFAFFINEEX(U,V,X0,TAU,K0,K1,[],H1,[],R1,[],L1,jump) describes a system with state dependent drift, variance, interest rate and jump intensity.

For real argument U, cfaffineEx returns the characteristic function of the stochastic process. For complex arugment U=-v*i, cfaffineEx returns the moment generating function of the stochastic process.

[W alpha beta A B] = CFAFFINEEX(U,V,X0,TAU,K0,K1,H0,H1,R0,R1,L0,L1,jump,ND)

Returns the parameters $\alpha,\beta$ as well as $A$ and $B$ that solve the Ricatti equations. See Theory for details.

Input Arguments

By default, cfaffineEx expects U to be an array of dimension (K)x(1) or (1)x(K). If U is a (NX)x(K) array, set ND=1, if U is a (K)x(NX) array, set ND=2.

Contents

Example 1: Expected interest rate level

If we set $u=0$, we can obtain arbitrary (discounted) expectations of linear combinations of $X_T$ by appropriate choice of $v$. For example, say we want to compute the average short rate over a future time period. The short rate $r_t$ is assumed to follow a CIR process. Further, we introduce

$y_t=\int_0^{t}r_sds$

The augmented state space is then

$dr=\kappa(\theta-r)dt + \sigma\sqrt{r}dW$

$dy=rdt$

We are interested in

$AVG = \frac{1}{T-t}E(\int_t^Tr_sds)=\frac{1}{T-t}E(\int_0^Tr_sds-\int_0^tr_sds)=\frac{1}{T-t}E(\int_0^Tr_sds)-\frac{1}{T-t}E(\int_0^tr_sds) =\frac{1}{T-t}E(y_T)-\frac{1}{T-t}E(y_t)$

This expectation corresponds to

$AVG = \frac{1}{T-t}E((0x_T+1y_T)\exp(0x_T+0y_T))-\frac{1}{T-t}E((0x_t+1y_t)\exp(0x_t+0y_t))$

The last two expectations are evaluations of the extended transform of an augmented state space, setting $u=0$.

Let us compute the average expectation

kR          = 2.2;
tR          = 0.08;
sR          = 0.10;
r0          = 0.04;
y0          = 0;
x0          = [r0 y0]';

Translating our problem into extended AJD coefficients, we obtain

K0          = [kR*tR 0]';
K1          = [-kR 0 ; 1 0];
H0          = zeros(2);
H1          = zeros(2,2,2);
H1(1,1,1)   = sR^2;
v           = [0 1]';
T           = 2;
t           = 0.5;
E1          = 1/(T-t)*cfaffineEx([0 0]',v,x0,T,K0,K1,H0,H1,[],[],[],[],[],[],1);
E2          = 1/(T-t)*cfaffineEx([0 0]',v,x0,t,K0,K1,H0,H1,[],[],[],[],[],[],1);
AVG1        = E1-E2;

Let us compare this result against a simulation of the same process:

nSim        = 100000;
nSteps      = 5000;
dt          = T/nSteps;
xx          = r0*ones(nSim,1);
yy          = y0*ones(nSim,1);
for k = 1:nSteps;
    xx          = xx + kR*(tR-xx)*dt + sR*sqrt(dt)*xx.*randn(nSim,1);
    if k*dt>t
        yy          = yy + xx*dt;
    end
end
AVG2        = mean(yy/(T-t));

We find that the results are nearly identical:

[AVG1 AVG2]
ans =

    0.0761    0.0761

Example 2: Asian options

Using the extended transform and its inverse, we can price Asian options as well. Say that we want to price an option that pays

$max(\frac{1}{T}\int_0^T r_sds-X,0)=max(\frac{1}{T}Y_T-X,0)$

in the future. The (discounted) risk neutral expectation of the payoff is

$P=E(max(\frac{1}{T}Y_T-X,0)\exp(-Y_T))$

by the definition of the discount factor. This expectation can be further split into

$P=\frac{1}{T}E(Y_T 1_{-Y_T\leq -XT}\exp(-Y_T))-XE(1_{-Y_T\leq -XT}\exp(-Y_T))$

At a closer inspection we find that the first conditional expectation is

$\frac{1}{T}\tilde{G}(0,[0, -1],[0, 1],-XT)$

whereas the second integral is

$XG(0,[0, -1],-XT)$

From the theory we know that both expectations can be recovered via their corresponding inverse Fourier transforms. All that is needed are the characteristic function and the extended characteristic function. Let us set them up now:

cf          = @(u) cfaffine([0 1]'*u,x0,T,K0,K1,H0,H1,[],[1 0]',[],[],[],1);
cfEx        = @(u) cfaffineEx([0 1]'*u,[0 1]',x0,T,K0,K1,H0,H1,[],[1 0]',[],[],[],[],1);

Here we have done the following: The first argument of cfaffine results in an (NX)x(NU) array of inputs. By setting ND=1, we tell the function that it should operate on U column-wise. We do the same for cfaffineEx. This setting directly implements the choice $a=[0,1]$ in $G(a,b,y)$. The same holds for $b=[0,-1]$. The choice of $v=[0 1]$ in cfaffineEx sets the coefficient $d=[0,1]$ in the extended expectation $\tilde{G}(a,b,d,y)$.

We set the strike to 3.5%, the option pays the positive difference between the average interest rate over the next two years and 3.5%.

X           = 0.035;

Finally, we can combine the corresponding expectations and obtain a price

e1          = 1/T*cf2gaby(cfEx,0,-1,-X*T,struct('uMax',500));
e2          = X*cf2gaby(cf,0,-1,-X*T,struct('uMax',500));
price       = e1-e2;

Let us compare this result against a simulation of the same option:

xx          = r0*ones(nSim,1);
yy          = y0*ones(nSim,1);
for k = 1:nSteps;
    xx          = xx + kR*(tR-xx)*dt + sR*sqrt(dt)*xx.*randn(nSim,1);
    yy          = yy + xx*dt;
end
df          = exp(-yy);
e1sim       = mean(yy/T.*(yy/T>X).*df);
e2sim       = X*mean((yy/T>X).*df);
priceSim    = e1sim-e2sim;

Again, we find that the results are nearly identical:

[price priceSim]
ans =

    0.0312    0.0313