Sort Bond Maturities Before Fitting a Nelson–Siegel Curve
Summary
The document addresses an error encountered when fitting a Nelson–Siegel yield curve using bond maturities and yields in R. The accepted answer points out that the question omits key details needed for diagnosis, including the package that provides the function, and recommends supplying a reproducible example. It then offers a likely cause: the maturity values may need to be sorted in increasing order.
This is a troubleshooting suggestion, not a confirmed diagnosis or a full explanation of the function’s requirements. The data shown include maturities that are not presented in ascending order, which makes the proposed check relevant, but the document reports no corrected run or fitted curve. Users should verify the function’s expected input ordering and other package-specific requirements before treating sorting as a complete fix.
Key ideas
- The error occurs while attempting to fit a Nelson–Siegel yield curve in R.
- A useful question should identify the package and provide a reproducible example.
- The proposed likely cause is that maturities are not sorted in increasing order.
- The answer does not demonstrate that sorting resolves the error.
Tags
Full text
# Question with regards to fitting the yield curve with the Nelson.Siegel function from the YieldCurve package in R # Question with regards to fitting the yield curve with the Nelson.Siegel function from the YieldCurve package in R I have the following data: ``` mat <- c(88.96438,21.20548,53.06301,76.89863,112.99726,83.96712,119.80274,53.06301 ,112.99726,53.06301) ytm <- c(0.09380442,0.07378878,0.08823629,0.09428388,0.10381418,0.09652231 ,0.10485382,0.08865775,0.10345890,0.09040975) ``` Where $mat$ are bond maturities (in months, as the function requires) and $ytm$ are the corresponding yields (in years). I get however the following error when performing the estimation: ``` Nelson.Siegel(rate=ytm, maturity = mat) Error in seq.default(maturity[1], maturity[pillars.number], by = 0.5) : wrong sign in 'by' argument ``` Can anyone please tell me why? Thanks ## Answer by Enrico Schumann (score 1, accepted) https://quant.stackexchange.com/a/51095 If you want people to help you, you really should provide a reproducible example. In particular, you should mention where the `Nelson.Siegel` function comes from. But as a guess, the maturities (`mat`) very likely have to be sorted in increasing order.
Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.