# state space for affine yield curve

i would like to reproduce in R the working paper " Affine free arbitrage class of Nelson Siegel term structure". The authors considering the equation of nelson siegel plus an adjustment term(C(t,T)) fits and estimates a state space form of this equations with Kalman filter. The measurement equations is :$y_{t}=A+BX{t}+\epsilon_{t}$ and state equation is $X_{t} = (I - exp(-K^{p} \Delta t))\theta^{p} + exp(-K^{P} \Delta t)X_{t-1} + \eta_{t}$; where $K^p$ is a matrix 3x3 of parameters to estimate and $\theta$ is a vector Nx1 of parameters to estimate. A is a vector Nx1 of adjustment term of this form: (where $\tau$ is the maturity) \begin{bmatrix} \frac{C_t}{\tau_1} \\ \vdots \\ \frac{C_N}{\tau_n} \end{bmatrix} and B is the coefficients matrix Nx3 of state variables: \begin{bmatrix} 1 & \frac{1-e^{-\lambda \tau_1}}{\lambda \tau_1} & \frac{1-e^{-\lambda \tau_1}}{\lambda \tau_1}-e^{-\lambda \tau_1} \\ \vdots & \vdots& \vdots \\ 1 & \frac{1-e^{-\lambda \tau_N}}{\lambda \tau_N} & \frac{1-e^{-\lambda \tau_N}}{\lambda \tau_1}-e^{-\lambda \tau_N} \end{bmatrix}and X is the vector of state variables: \begin{bmatrix} X{^1}{_t} \\ X{^2}{_t} \\ X{^3}{_t} \end{bmatrix}

furthermore the adjustment term C(t,T) has this analytical form: $= a \biggr[\frac{(T-t)^2}{6}\biggr] + b \biggr[\frac{1}{2 \lambda^2} - \frac{1}{\lambda^3} \frac{1-e^{-\lambda(T-t)}}{T-t)}+\frac{1}{4{\lambda^3}}\frac{1-e{-2\lambda(T-t)}}{T-t}\biggr]$

$+ c \biggr[\frac{1}{2\lambda^2}+\frac{1}{\lambda^2}*e^ {-\lambda (T-t) } - \frac{1}{4 \lambda} (T-t) e^{-2\lambda(T-t)} - \frac{3}{4 \lambda^2}e^{-2\lambda(T-t)}-\frac{2}{\lambda^3} \frac{1-e^{-\lambda (T-t)}}{(T-t)} + \frac{5}{8\lambda^3} \frac{1-e^{-2\lambda(T-t)}}{T-t)}\biggr] +$

$+ d \biggr[\frac{1}{2\lambda}(T-t)+\frac{1}{\lambda^2} e^{-\lambda(T-t)} - \frac{1}{\lambda^3} \frac{1-e^{-\lambda(T-t)}}{(T-t)}\biggr]$

$+e\biggr[\frac{3}{\lambda^2} e^{-\lambda(T-t)} + \frac{1}{2\lambda}(T-t)+\frac{1}{\lambda}(T-t) e^{-\lambda(Y-t)} - \frac{3}{\lambda^3}\frac{1-e^{-\lambda(T-t)}}{(T-t)}\biggr]$

$+f \biggr[\frac{1}{\lambda^2}+\frac{1}{\lambda^2} e^{-\lambda(t-t)} - \frac{1}{2\lambda^2}e^{-2\lambda(T-t)} -\frac{1-e^{-\lambda(T-t)}}{(T-t)} + \frac{1}{4{\lambda^3}}\frac{1-e{-2\lambda(T-t)}}{T-t}\biggr]$

where

$a=\sigma{^2_{11}}+\sigma{^2_{12}+\sigma{^2}_{13}}$;$b=\sigma{^2_{22}}+\sigma{^2_{21}+\sigma{^2}_{23}}$,

$c=\sigma{^2_{31}}+\sigma{^2_{32}+\sigma{^2}_{33}}$

$d=\sigma_{11} \sigma_{21}+\sigma_{12}\sigma_{22}+\sigma_{13}\sigma_{23}$;

$e=\sigma_{11} \sigma_{31}+\sigma_{12}\sigma_{32}+\sigma_{13}\sigma_{33}$;

$f=\sigma_{21} \sigma_{31}+\sigma_{22}\sigma_{32}+\sigma_{23}\sigma_{33}$;

the value of $\sigma_{ii}$ and ($\sigma_{ij}$) are unknown and they are respectively the volatility and correlation of state variables.

• @BobJansen,@Gordon – frank Nov 5 '15 at 11:31
• What is the question? – Kiwiakos Nov 5 '15 at 11:38
• how can i reproduce this in R? – frank Nov 5 '15 at 12:35
• I am not familiar with R. But I sense that the work load is not small. You may need to start with yours and share the issues that you have encountered. Then people may help you identify the problems. – Gordon Nov 5 '15 at 13:38