nss

Syntax

nss(maturity, yield, [method="nss"])

Arguments

maturity is a numeric vector with negative elements, indicating the maturity (in years) of a bond.

yield is a numeric vector of the same length as maturity, indicating the bond yield.

method (optional) is a string indicating the model used. It can be:

  • "nss" (default): Nelson-Siegel-Svensson model

  • "ns": Nelson-Siegel model

Details

Fit yield curve using NS/NSS model with Nelder-Mead algorithm.

Return value: A dictionary with the following key-value pairs:

  • modelName: The model used.

  • params: The fitted model parameters.

    • NS model: a vector of length 4, containing β0, β1, β2, λ.

    • NSS model: a vector of length 6, containing β0, β1, β2, β3, λ0, λ1.

  • fminResult: The optimization result of the Nelder-Mead method, as detailed in the function fmin.

  • predict: The prediction function generated by the model. The method is model.predict(T) where T is the maturity in years. It returns the predicted yield with this model.

Examples
maturity = [1,2,3,4,5,8,10,15,20,25,30]
yield = [0.0039,0.0061,NULL,NULL,0.0166,NULL,0.0258,NULL,NULL,0.0332,NULL]
model = nss(maturity, yield)

model.modelName 
//output: nss

model.params 
//output: [0.038184469794996,-0.048575389082029,-0.022287414169806,0.047523360012739,1.873046195772644,0.161159907274023]

model.fminResult
/* Output:
xopt->[0.038184469794996,-0.048575389082029,-0.022287414169806,0.047523360012739,1.873046195772644,0.161159907274023]
fopt->5.456415848001168E-9
iterations->541
fcalls->860
warnFlag->0
*/

// make predictions
model.predict([3,1])
/* Output:
[0.009904201306001,0.003891991292041]
*/