I want to simulate data from the following model:

$\textbf{z}_k=\textbf{H}\textbf{x}_k+\textbf{v}_k$ $\textbf{v}_k \sim N(\textbf{0},\textbf{R})$

$\textbf{H}$ does not change over time
$\textbf{x}$ is a vector of loadings
$\textbf{R}$ is a diagonal of constants

$\textbf{x}_k=\textbf{F}\textbf{x}_{k-1}+(\textbf{I}-\textbf{F}){\mu} + \textbf{w}_k $ $\textbf{w}_k \sim N(\textbf{0},\textbf{Q})$

$\textbf{I}$ is the identity matrix
$\mu$ is the vector of mean values of $\textbf{x}$
$\textbf{F}$ is diagonal with the AR(1) params which do not change over time
$\textbf{Q}$ is diagonal with the innovation processes for $\textbf{x}$

I have the following code in Matlab

nDates=20000; %number of dates

mats=[1 2 3 4 5 6 7 8 9 10 12 15 20 25 30]'; %maturities 
nY=length(mats); %#number of yields

z=zeros(nY,nDates);  %declare vector for yields
x=zeros(3,nDates); %declare vector for factors

R=0.00001;   %standard deviation
I=eye(3); %3*3 identity matrix

v=normrnd(0,R,nY,nDates); %generate residuals
F=[0.9963 0 0; 0 0.9478 0; 0 0 0.774]; %AR(1) matrix
mu=[0.0501; -0.0251;-.0116]; %mean of X

q = [0.0026^0.5 0 0;0 0.0027^0.5 0; 0 0 0.0035^0.5];
rng('default');  % For reproducibility
r = randn(nDates,3);
w= (r*Q)';     

B= [ones(nY,1),((1-exp(-lambda*mats))./(lambda*mats)),((1-exp(-lambda*mats))./(lambda*mats))-exp(-lambda*mats)];


for t=2:nDates


It all seems straightforward enough but what test can I so to ensure that it has been implemented correctly?

Ones I have thought of:
Check the correlation of the factors x on their 1 period lags match the values given in matrix F
Check that the variances of v and w are correct
Check that the mean of the simulated variables are correct

I would like to check that the empirical variance of the parameters matches their theoretical equivalent, but I don't know what the theoretical equivalent should be?

Please feel free to suggest further tests that will allow me to know for sure if the implementation is correct.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.