0
$\begingroup$

I'm trying to estimate a Dynamic Nelson-Siegel-Svensson (DNSS) model with time-varying scale factors lambda_{1} and lambda_{2}. I am therefore estimating the lambdas as state variables (same as the Betas) in an extended Kalman Filter. However the lambdas (i.e. state variables x_{5}, x_{6} in my model as Beta_{0}=x_{1}, Beta_{1}=x_{2}, Beta_{2}=x_{3}, and Beta_{3}=x_{4}) need to remain positive, as we know.

I have read that one trick to ensure the non-negativity of a state variable in the Kalman Filter is to estimate log(x) instead of x as a state variable. (What would be the other options?)

Now, if I estimate log(lambda_{1}) and log(lambda_{2}) in my DNSS, I have to modify the Jacobian matrix accordingly, and that is fine. However, I can't figure out how my Kalman Filter algorithm equations need to be modified?

In plane (non finance terms), I'm trying to estimate a Kalman Filter with f(x)=log(x) instead of x as a state variable. How do you modify the predict and update equations accordingly?

Here is the code for a plain extended Kalman Filter:

# Loop over time
for t in range(T):

# Predict state vector
Xt_1[:, [t]] = muP + thetaP @ Xt[:, [t]]

# MSE matrix state equation
Pt_1[:, :, t] = thetaP @ Pt[:, :, t] @ thetaP.T + Sigmae

# Measurement equation
y_hat = A + B.T @ Xt_1[:, [t]]
# fitting errors
errors = yields[[t], :] - y_hat

# estimatge Jacobian
H = compute_jacobian(Xt_1, t)
# compute F
F = np.matrix(H @ Pt_1[:, :, t] @ H.T) + Sigmaz

# Kalman gain
K = Pt_1[:, :, t] @ B @ np.linalg.inv(F)
# state vector
Xt[:, [t + 1]] = Xt_1[:, [t]] + K @ errors
# MSE matrix state equation
Pt[:, :, t + 1] = (np.eye(3) - K @ B.T) @ Pt_1[:, :, t]

Note that my question is not so much Python or Matlab related but more how to express the mathematics in the code.

Many thanks for your help :)

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.