luphord / nelson_siegel_svensson

Implementation of the Nelson-Siegel-Svensson interest rate curve model.
MIT License
110 stars 41 forks source link

Unexpected results for calibrate_nss_ols function #8

Closed shyimo closed 3 years ago

shyimo commented 3 years ago

Description

unexpected results of calibrate_nss_ols calibration function

What I Did

Hi There,
first of all - thanks for this python implementation !
i have some excel data that i would like to compute the calibrate values for and i'm getting very different results from my excel.

this is when i run in the code:
calibrate_nss_ols(np.array([1, 2, 5, 10, 25]), np.array([0.0039, 0.0061, 0.0166, 0.0258, 0.0332]) , tau0=[1.0, 1.0])
and i got this response:
(NelsonSiegelSvenssonCurve(beta0=0.037538814593271755, beta1=-0.03687865378245708, beta2=194192398920.83823, beta3=-194192398920.88785, tau1=1.000036239805082, tau2=1.0000362398052216)‏

however, in my excel sheet i use the same times (the time is in years of course) and the same yields as percentage (0.39%, 0.61%, 1.66%, 2.58%, 3.32%) and by curve factors are the following:

beta0=0.04
beta1=-0.03
beta2=-0.02
beta3=-0.02
tau0=2.10
tau0=1.04

i have test this a couple of times and i can't seem to find the problem,
Thank you very much for any help!
luphord commented 3 years ago

In your setup above you are using identical starting values for tau1 and tau2 by setting tau0=[1.0, 1.0]. In consequence, the factors for beta2 and beta3 are equal, thus degenerating the model. The stepwise calibration algorithm will probably not be able to recover from a broken start. I recommend you try different starting values, e.g. tau0=[1.0, 2.0].

Furthermore, you currently try to estimate 6 parameters (4 betas + 2 taus) from only 5 data points. You cannot expect this to yield proper estimates. I suggest you either try a NelsonSiegelCurve (no Svensson, only 4 parameters). Or you fix the parameters tau1 and tau2 to any values you deem sensible and use nelson_siegel_svensson.calibrate.betas_nss_ols for calibration.

The intuition for tau1 and tau2 is the time points (i.e. typically years) where the curve can exhibit "humps". So you want to place them at time points where the curve is expected to be particularly non-linear. For example, you might want to have a hump at the short end tau1=0.5 and at some medium maturity tau2=4.

shyimo commented 3 years ago

Hi @luphord, Thanks for clarify that. everything works now as expected.

Thanks!