Package: nelson-siegel-svensson
Nelson-Siegel-Svensson ModelImplementation of the Nelson-Siegel-Svensson interest rate curve model in Python.fromnelson_siegel_svenssonimportNelsonSiegelSvenssonCurveimportnumpyasnpfrommatplotlib.pyplotimportploty=NelsonSiegelSvenssonCurve(0.028,-0.03,-0.04,-0.015,1.1,4.0)t=np.linspace(0,20,100)plot(t,y(t))Free software: MIT licensePython 3.7 or later supportedDocumentation:https://nelson-siegel-svensson.readthedocs.io.FeaturesPython implementation of the Nelson-Siegel curve (three factors)Python implementation of the Nelson-Siegel-Svensson curve (four factors)Methods for zero and forward rates (as vectorized functions of time points)Methods for the factors (as vectorized function of time points)Calibration based on ordinary least squares (OLS) for betas and nonlinear optimization for tausSimple command line interface (CLI) for evaluating, calibrating and plotting curvesCalibrationIn order to calibrate a curve to given data you can use thecalibrate_ns_olsandcalibrate_nss_olsfunctions in thecalibratemodule:importnumpyasnpfromnelson_siegel_svensson.calibrateimportcalibrate_ns_olst=np.array([0.0,0.5,1.0,2.0,3.0,4.0,5.0,10.0,15.0,20.0,25.0,30.0])y=np.array([0.01,0.011,0.013,0.016,0.019,0.021,0.026,0.03,0.035,0.037,0.038,0.04])curve,status=calibrate_ns_ols(t,y,tau0=1.0)# starting value of 1.0 for the optimization of tauassertstatus.successprint(curve)which gives the following output:NelsonSiegelCurve(beta0=0.04201739383636799,beta1=-0.031829031569430594,beta2=-0.026797319779108236,tau=1.7170972656534174)Command Line interfacenelson_siegel_svenssonprovides basic functionality using a command line interface (CLI):Usage: nelson_siegel_svensson [OPTIONS] COMMAND [ARGS]...

Commandline interface for nelson_siegel_svensson.

Options:
--help  Show this message and exit.

Commands:
calibrate  Calibrate a curve to the given data points.
evaluate   Evaluate a curve at given points.
plot       Plot a curve at given points.In order to calibrate a curve to given data points on the command line, trynelson_siegel_svensson calibrate -t '[0.0, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0]' -y '[0.01, 0.011, 0.013, 0.016, 0.019, 0.021, 0.026, 0.03, 0.035, 0.037, 0.038, 0.04]' --nelson-siegel --initial-tau1 1.0which gives{"beta0": 0.042017393764903765, "beta1": -0.03182903146166806, "beta2": -0.026797320316066128, "tau": 1.717097232403383}This curve can then be evaluated on the command line usingnelson_siegel_svensson evaluate -c '{"beta0": 0.042017393764903765, "beta1": -0.03182903146166806, "beta2": -0.026797320316066128, "tau": 1.717097232403383}' -t '[0, 1, 2, 3]'resulting in[0.010188362303235707, 0.012547870204470839, 0.01574855552855885, 0.01897955804146046]And finally, the curve can be plotted withnelson_siegel_svensson plot -o cli_plot_example.png -c '{"beta0": 0.042017393764903765, "beta1": -0.03182903146166806, "beta2": -0.026797320316066128, "tau": 1.717097232403383}'Note that the quoting in the above commands preventsbashfrom evalutating the JSON-based parameters. Depending on your shell, you may require a different quoting mechanism.CreditsMain developer isluphord.This package was prepared withCookiecutterand theaudreyr/cookiecutter-pypackageproject template.History0.5.0 (2022-11-13)Drop support for Python 3.7Add support Python 3.9 and 3.10Reformat code with blackUpgrade dependenciesUpgrade development status to beta0.4.3 (2022-03-15)Migrate to GitHub Actions0.4.2 (2020-02-04)Support Python 3.8Upgrade flake8 (test requirement) as prior version did not support Python 3.80.4.1 (2019-11-14)Added return type annotations for core modulesAdded some example notebooks0.4.0 (2019-07-08)Simple command line interface (CLI) supporting curve evaluation, calibration and plottingAdded more documentation0.3.0 (2019-03-17)Added type annotations0.2.0 (2019-02-20)Ordinary least squares based calibration of Nelson-Siegel-SvenssonOrdinary least squares based calibration of Nelson-SiegelA little bit of usage documentation0.1.0 (2019-02-13)First release on PyPI.