Apr
28

## Kalman Filter Finance Revisited

Inspired by @MichaelRW at Twitter, I decide to continue the topic on Kalman Filter following posts Kalman Filter Example and Kalman Filter Finance.

Specifically, Kalman Filter is applied to estimate the parameters of a Cox Ingersoll Ross (CIR) one factor interest rate model, (Vasicek model is simplier than CIR, so the latter is chosen as an example), it is a widely used mean-reverting process with SDE

A three-factor CIR model has a measurement equation

and a transition equation

source from the paper "affine term structure models: theory and implementation" downloaded at www.bankofcanada.ca/en/res/wp/2001/wp01-15a.pdf

I skip the derivation part and recommend the following two papers: "estimating and testing exponential-affine term structure models by kalman filter " and "affine term structure models: theory and implementation" to understand the transition and measurement equations. Below are the sample Matlab implementation:

flip over to next page...

Hot posts:

15 Incredibly Stupid Ways People Made Their Millions

Ino.com: Don't Join Marketclub until You Read This MarketClub Reviews

Online stock practice

World Changing Mathematical Discoveries

Value at Risk xls

Random posts:

Kalman filter toolbox for Matlab

Week in Review 021211 R Language

Maximum likelihood estimation in R

A Course in Derivative Securities: Introduction to Theory and Computation

Credit Informed Tactical Asset Allocation

Specifically, Kalman Filter is applied to estimate the parameters of a Cox Ingersoll Ross (CIR) one factor interest rate model, (Vasicek model is simplier than CIR, so the latter is chosen as an example), it is a widely used mean-reverting process with SDE

A three-factor CIR model has a measurement equation

and a transition equation

source from the paper "affine term structure models: theory and implementation" downloaded at www.bankofcanada.ca/en/res/wp/2001/wp01-15a.pdf

I skip the derivation part and recommend the following two papers: "estimating and testing exponential-affine term structure models by kalman filter " and "affine term structure models: theory and implementation" to understand the transition and measurement equations. Below are the sample Matlab implementation:

function [para, sumll] = TreasuryYieldKF()

% author: biao from www.mathfinance.cn

%%CIR parameter estimation using Kalman Filter for given treasury bonds yields

% check paper ""estimating and testing exponential-affine term structure

% models by kalman filter " and "affine term structure models: theory and

% implementation" for detail

% S(t+1) = mu + F S(t) + noise(Q)

% Y(t) = A + H S(t) + noise(R)

% read data Y

Y = xlsread('ir.xls');

[nrow, ncol] = size(Y);

tau = [1/4 1/2 1 5]; % stand for 3M, 6M, 1Y, 5Y yield

para0 = [0.05, 0.1, 0.1, -0.1, 0.01*rand(1,ncol).*ones(1,ncol)];

[x, fval] = fmincon(@loglik, para0,[],[],[],[],[0.0001,0.0001,0.0001, -1, 0.00001*ones(1,ncol)],[ones(1,length(para0))],[],[],Y, tau, nrow, ncol);

para = x;

sumll = fval;

end

% author: biao from www.mathfinance.cn

%%CIR parameter estimation using Kalman Filter for given treasury bonds yields

% check paper ""estimating and testing exponential-affine term structure

% models by kalman filter " and "affine term structure models: theory and

% implementation" for detail

% S(t+1) = mu + F S(t) + noise(Q)

% Y(t) = A + H S(t) + noise(R)

% read data Y

Y = xlsread('ir.xls');

[nrow, ncol] = size(Y);

tau = [1/4 1/2 1 5]; % stand for 3M, 6M, 1Y, 5Y yield

para0 = [0.05, 0.1, 0.1, -0.1, 0.01*rand(1,ncol).*ones(1,ncol)];

[x, fval] = fmincon(@loglik, para0,[],[],[],[],[0.0001,0.0001,0.0001, -1, 0.00001*ones(1,ncol)],[ones(1,length(para0))],[],[],Y, tau, nrow, ncol);

para = x;

sumll = fval;

end

flip over to next page...

Pages: [1] [2]

**People viewing this post also viewed:**

Hot posts:

Random posts:

%volatility of measurement error

sigmai = para(5:end);

??? Input argument "para" is undefined.

Error in ==> loglik

when I run the program...