Symbolic Math Toolbox

Calculating Jacobians of Nelson Siegel and Svensson Models

This example uses Symbolic Math Toolbox to calculate Jacobian matrices of Nelson Siegel and Svensson models, which are commonly used for modeling bond data. The Jacobians can subsequently be imported into MATLAB and used to speed up optimization of model parameters. 

Nelson-Siegel Model

image
Svensson Model

image

Note that t is the independent variable in these models, and represents time to maturity.

I. Nelson-Siegel Model

We begin by defining the Nelson-Siegel model equation.

y1 := b0+b1*exp(-t/t1)+b2*(-t/t1)*exp(-t/t1)

math

We extract the indeterminates (i.e. variables) that the Nelson Siegel model is comprised of, and subtract the independent variable t. These variables will be needed for the Jacobian calculation.

v1 := indets(y1) minus {t}

math

We convert the result from a set to a list and compute the Jacobian matrix of y1 with respect to v1.

v1 := coerce(v1, DOM_LIST);
J1 := linalg::jacobian([y1], v1)

math
math

We determine the variable type and dimension of J1 using simple commands.

type(J1)

math

linalg::matdim(J1)

math

II. Svensson Model

We now perform the same calculations for the Svensson model. We start by defining the model equation.

y2 := b0+b1*exp(-t/t1)+b2*(-t/t1)*exp(-t/t1)+b3*(t/t2)*exp(-t/t2)

math

We extract the variables that the Svensson model is comprised of, and subtract the independent variable t.

v2 := indets(y2) minus {t}

math

We convert the result from a set to a list and compute the Jacobian matrix of y2 with respect to v2.

v2 := coerce(v2, DOM_LIST);
J2 := linalg::jacobian([y2], v2)

math
math

We determine the variable type and dimension of J2 using simple commands.

type(J2)

math

linalg::matdim(J2)

math

We can read the Jacobian matrices J1 and J2 into MATLAB using the getVar function in Symbolic Math Toolbox, and use them to help speed up optimization of model parameters so that they fit real-world government bond data as well as possible. To see the complete example that includes the model optimization and the speed up achieved via analytical Jacobians, view the recorded webinar “ Using MATLAB and Symbolic Math Toolbox to Develop and Analyze Financial Models (36:23) .”