nelson_siegel_svensson package¶
Submodules¶
nelson_siegel_svensson.calibrate module¶
Calibration methods for Nelson-Siegel(-Svensson) Models. See calibrate_ns_ols and calibrate_nss_ols for ordinary least squares (OLS) based methods.
-
nelson_siegel_svensson.calibrate.
betas_ns_ols
(tau: float, t: numpy.ndarray, y: numpy.ndarray) → Tuple[nelson_siegel_svensson.ns.NelsonSiegelCurve, Any][source]¶ Calculate the best-fitting beta-values given tau for time-value pairs t and y and return a corresponding Nelson-Siegel curve instance.
-
nelson_siegel_svensson.calibrate.
betas_nss_ols
(tau: Tuple[float, float], t: numpy.ndarray, y: numpy.ndarray) → Tuple[nelson_siegel_svensson.nss.NelsonSiegelSvenssonCurve, Any][source]¶ Calculate the best-fitting beta-values given tau (= array of tau1 and tau2) for time-value pairs t and y and return a corresponding Nelson-Siegel-Svensson curve instance.
-
nelson_siegel_svensson.calibrate.
calibrate_ns_ols
(t: numpy.ndarray, y: numpy.ndarray, tau0: float = 2.0) → Tuple[nelson_siegel_svensson.ns.NelsonSiegelCurve, Any][source]¶ Calibrate a Nelson-Siegel curve to time-value pairs t and y, by optimizing tau and chosing all betas using ordinary least squares.
-
nelson_siegel_svensson.calibrate.
calibrate_nss_ols
(t: numpy.ndarray, y: numpy.ndarray, tau0: Tuple[float, float] = (2.0, 5.0)) → Tuple[nelson_siegel_svensson.nss.NelsonSiegelSvenssonCurve, Any][source]¶ Calibrate a Nelson-Siegel-Svensson curve to time-value pairs t and y, by optimizing tau1 and tau2 and chosing all betas using ordinary least squares. This method does not work well regarding the recovery of true parameters.
-
nelson_siegel_svensson.calibrate.
empirical_factors
(y_3m: float, y_2y: float, y_10y: float) → Tuple[float, float, float][source]¶ Calculate the empirical factors according to Diebold and Li (2006).
-
nelson_siegel_svensson.calibrate.
errorfn_ns_ols
(tau: float, t: numpy.ndarray, y: numpy.ndarray) → float[source]¶ Sum of squares error function for a Nelson-Siegel model and time-value pairs t and y. All betas are obtained by ordinary least squares given tau.
-
nelson_siegel_svensson.calibrate.
errorfn_nss_ols
(tau: Tuple[float, float], t: numpy.ndarray, y: numpy.ndarray) → float[source]¶ Sum of squares error function for a Nelson-Siegel-Svensson model and time-value pairs t and y. All betas are obtained by ordinary least squares given tau (= array of tau1 and tau2).
nelson_siegel_svensson.cli module¶
Console script for nelson_siegel_svensson.
-
class
nelson_siegel_svensson.cli.
Curve
[source]¶ Bases:
click.types.ParamType
Parameter type representing a curve (either Nelson-Siegel or Nelson-Siegel-Svensson)
-
convert
(value, param, ctx)[source]¶ Convert the value to the correct type. This is not called if the value is
None
(the missing value).This must accept string values from the command line, as well as values that are already the correct type. It may also convert other compatible types.
The
param
andctx
arguments may beNone
in certain situations, such as when converting prompt input.If the value cannot be converted, call
fail()
with a descriptive message.Parameters: - value – The value to convert.
- param – The parameter that is using this type to convert
its value. May be
None
. - ctx – The current context that arrived at this value. May
be
None
.
-
name
= 'curve'¶
-
-
class
nelson_siegel_svensson.cli.
FloatArray
[source]¶ Bases:
click.types.ParamType
Parameter type representing an array of floats
-
convert
(value, param, ctx)[source]¶ Convert the value to the correct type. This is not called if the value is
None
(the missing value).This must accept string values from the command line, as well as values that are already the correct type. It may also convert other compatible types.
The
param
andctx
arguments may beNone
in certain situations, such as when converting prompt input.If the value cannot be converted, call
fail()
with a descriptive message.Parameters: - value – The value to convert.
- param – The parameter that is using this type to convert
its value. May be
None
. - ctx – The current context that arrived at this value. May
be
None
.
-
name
= 'floats'¶
-
nelson_siegel_svensson.ns module¶
Implementation of a Nelson-Siegel interest rate curve model. See NelsonSiegelCurve class for details.
-
class
nelson_siegel_svensson.ns.
NelsonSiegelCurve
(beta0: float, beta1: float, beta2: float, tau: float)[source]¶ Bases:
object
Implementation of a Nelson-Siegel interest rate curve model. This curve can be interpreted as a factor model with three factors (including a constant).
-
factor_matrix
(T: Union[float, numpy.ndarray]) → Union[float, numpy.ndarray][source]¶ Factor loadings for time(s) T as matrix columns, including constant column (=1.0).
-
factors
(T: Union[float, numpy.ndarray]) → Union[Tuple[float, float], Tuple[numpy.ndarray, numpy.ndarray]][source]¶ Factor loadings for time(s) T, excluding constant.
-
nelson_siegel_svensson.nss module¶
Implementation of a Nelson-Siegel-Svensson interest rate curve model. See NelsonSiegelSvenssonCurve class for details.
-
class
nelson_siegel_svensson.nss.
NelsonSiegelSvenssonCurve
(beta0: float, beta1: float, beta2: float, beta3: float, tau1: float, tau2: float)[source]¶ Bases:
object
Implementation of a Nelson-Siegel-Svensson interest rate curve model. This curve can be interpreted as a factor model with four factors (including a constant).
-
factor_matrix
(T: Union[float, numpy.ndarray]) → Union[float, numpy.ndarray][source]¶ Factor loadings for time(s) T as matrix columns, including constant column (=1.0).
-
factors
(T: Union[float, numpy.ndarray]) → Union[Tuple[float, float, float], Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]][source]¶ Factor loadings for time(s) T, excluding constant.
-
Module contents¶
Implementation of the Nelson-Siegel-Svensson interest rate curve model. For details, see classes NelsonSiegelCurve and NelsonSiegelSvenssonCurve.
-
class
nelson_siegel_svensson.
NelsonSiegelCurve
(beta0: float, beta1: float, beta2: float, tau: float)[source]¶ Bases:
object
Implementation of a Nelson-Siegel interest rate curve model. This curve can be interpreted as a factor model with three factors (including a constant).
-
factor_matrix
(T: Union[float, numpy.ndarray]) → Union[float, numpy.ndarray][source]¶ Factor loadings for time(s) T as matrix columns, including constant column (=1.0).
-
factors
(T: Union[float, numpy.ndarray]) → Union[Tuple[float, float], Tuple[numpy.ndarray, numpy.ndarray]][source]¶ Factor loadings for time(s) T, excluding constant.
-
-
class
nelson_siegel_svensson.
NelsonSiegelSvenssonCurve
(beta0: float, beta1: float, beta2: float, beta3: float, tau1: float, tau2: float)[source]¶ Bases:
object
Implementation of a Nelson-Siegel-Svensson interest rate curve model. This curve can be interpreted as a factor model with four factors (including a constant).
-
factor_matrix
(T: Union[float, numpy.ndarray]) → Union[float, numpy.ndarray][source]¶ Factor loadings for time(s) T as matrix columns, including constant column (=1.0).
-
factors
(T: Union[float, numpy.ndarray]) → Union[Tuple[float, float, float], Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]][source]¶ Factor loadings for time(s) T, excluding constant.
-