Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
This post explains how to forecast yield curves using Dynamic Nelson-Siegel model given information of estimated parameters.

# Forecasting of Dynamic Nelson-Siegel model

We estimated parameters of dynamic Nelson-Seigel model in the previous post below.

Using estimated parameters in the previous post, let’s forecast yield curves.

### Forecast

Forecasting equations of DNS model ($$h=1,…,H$$) consist of the state and measurement equations as follows.

\begin{align} X_{t+h} &= \psi_0 + \psi_1 X_{t+h-1} \\ y_{t+h} (\boldsymbol{\tau}) &= B(\boldsymbol{\tau}) X_{t+h} \end{align}
Here, $$X_t (h=1)$$ is the filtered estimate of a state vector at time $$T$$ (end of sample).

### Estimated Parameters

From the previous post, we can get the following the filtered state estimate and estimated parameters.

\begin{align} \lambda &= 0.4336145 \\ A &= \begin{bmatrix} 0.9909972 & 0 & 0 \\ 0 & 0.9614324 & 0 \\ 0 & 0 & 0.9027326 \end{bmatrix} \\ \mu_X &= \begin{bmatrix} 0.0334947 \\ -0.0114954 \\ -0.0066945 \end{bmatrix} \\ X &= \begin{bmatrix} 0.01743225 \\ -0.002418071 \\ -0.0040720452 \end{bmatrix} \end{align}

### R code

The R code below implements the above forecasting procedure using estimated parameters of DNS model. Forecasts are performed during the 120-month horizon.

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 #========================================================## Quantitative ALM, Financial Econometrics & Derivatives # ML/DL using R, Python, Tensorflow by Sang-Heon Lee ## https://kiandlee.blogspot.com#——————————————————–## Forecasting in Dynamic Nelson-Siegel model#========================================================# graphics.off()  # clear all graphsrm(list = ls()) # remove all files from your workspace # DNS factor loading matrixNS.B <– function(lambda, tau){    col1 <– rep.int(1,length(tau))    col2 <– (1–exp(–lambda*tau))/(lambda*tau)    col3 <– col2–exp(–lambda*tau)     return(cbind(col1,col2,col3))} #—————————    # estimated parameters#—————————            # AR matrix    A  <– diag(c(0.9909972, 0.9614324, 0.9027326))           # mean vector    MU <– c(0.0334947, –0.0114954, –0.0066945)         lambda <– 0.4336145     Phi0 <– (diag(3)–A)%*%MU     Phi1 <– A        # factor loading matrix    v.mat <– c(0.25, 0.5, 0.75, 1, 1.5, 2,                 2.5, 3, 4, 5, 7, 10, 20)    nmat  <– length(v.mat)    B     <– NS.B(lambda,v.mat) #—————————————–    # filtered state estimate at time T#—————————————–         # final state     prevX <– c(0.01743225, –0.002418071, –0.0040720452)    #—————————————–    # forecasting H-horison#—————————————–     # forecasting horizon    nhor <– 120 # 5-year        # placeholder for predicted states     # and yield curve forecasts    Xf <– matrix(NA, nhor, 3)    yf <– matrix(NA, nhor, nmat)        # dynamic forecasting    for(h in 1:nhor) {                # prediction        Xhat <– Phi0+Phi1%*%prevX                 # forecast yield curve        y_fit  <– B%*%Xhat                # use forecasted state at h         # as previous state at h+1        prevX <– Xhat                # save        Xf[h,] <– Xhat         yf[h,] <– y_fit    }        yf    Xf Colored by Color Scripter cs

Running this R code produces the following output table of factors and yields forecast.

Factor forecasts are done recursively according to its vector autoregressive process. The following figure draws a conbined graph for the historical factor estimates and their forecasts.

Yields forecasts are calculated based on factor forecasts using the measurement equation. The following figure draws a conbined graph for the historical yield curves and their forecasts.

### Concluding Remarks

This post shows how to forecast yield curves using DNS model based on its estimated parameters. For those who are not familiar with this procedure, I hope this will help. $$\blacksquare$$

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.