同步操作将从 acrowise/nelson_siegel_svensson 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
Implementation of the Nelson-Siegel-Svensson interest rate curve model in Python.
from nelson_siegel_svensson import NelsonSiegelSvenssonCurve
import numpy as np
from matplotlib.pyplot import plot
y = NelsonSiegelSvenssonCurve(0.028, -0.03, -0.04, -0.015, 1.1, 4.0)
t = np.linspace(0, 20, 100)
plot(t, y(t))
In order to calibrate a curve to given data you can use the calibrate_ns_ols and calibrate_nss_ols functions in the calibrate module:
import numpy as np
from nelson_siegel_svensson.calibrate import calibrate_ns_ols
t = 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 tau
assert status.success
print(curve)
which gives the following output:
NelsonSiegelCurve(beta0=0.04201739383636799, beta1=-0.031829031569430594, beta2=-0.026797319779108236, tau=1.7170972656534174)
nelson_siegel_svensson provides 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, try
nelson_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.0
which gives
{"beta0": 0.042017393764903765, "beta1": -0.03182903146166806, "beta2": -0.026797320316066128, "tau": 1.717097232403383}
This curve can then be evaluated on the command line using
nelson_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 with
nelson_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 prevents bash from evalutating the JSON-based parameters. Depending on your shell, you may require a different quoting mechanism.
Main developer is luphord.
This package was prepared with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。