Skip to content
All library documents

Choosing and Evaluating Fits for Bond Yield Data

Article Quant Q&A · Author: RoyalGoose

Summary

The document compares simple functional fits to a set of bond yield observations: a linear fit against square-root maturity, a linear fit against log maturity, and a quadratic fit. The author describes visual shortcomings in each curve and asks whether any is sufficiently accurate. The response recommends judging reasonable fits with quantitative criteria rather than relying on appearance alone. Possible measures include different error norms, information criteria, and cross-validation, with the choice depending on the purpose of the curve and the trade-offs that matter.

Fit quality also depends on practical considerations such as simplicity, numerical speed, stability, sensitivity to outliers, and the risk of overfitting. The observations may not deserve equal influence: differences in liquidity or trading volume can motivate weighted least squares or a tailored loss function. The document does not report comparative error calculations or identify a winning model. Its examples are exploratory, and the appropriate fit remains dependent on how the yield curve will be used and what characteristics matter most.

Key ideas

  • Visual inspection can reject clearly poor fits, but it is not a reliable way to rank plausible models.
  • Compare candidate curves using a loss measure, information criterion, or cross-validation appropriate to the task.
  • Model choice involves practical trade-offs such as simplicity, speed, stability, and overfitting risk.
  • Consider weighting observations when liquidity, volume, or other factors make some points more important.

Tags

Full text
# Which curve is better to approximate bond yields (python)


# Which curve is better to approximate bond yields (python)












### I would like to approximate bond yields in python. But the question arose which curve describes this better?

```
import numpy as np
import matplotlib.pyplot as plt

x = [0.02, 0.22, 0.29, 0.38, 0.52, 0.55, 0.67, 0.68, 0.74, 0.83, 1.05, 1.06, 1.19, 1.26, 1.32, 1.37, 1.38, 1.46, 1.51, 1.61, 1.62, 1.66, 1.87, 1.93, 2.01, 2.09, 2.24, 2.26, 2.3, 2.33, 2.41, 2.44, 2.51, 2.53, 2.58, 2.64, 2.65, 2.76, 3.01, 3.17, 3.21, 3.24, 3.3, 3.42, 3.51, 3.67, 3.72, 3.74, 3.83, 3.84, 3.86, 3.95, 4.01, 4.02, 4.13, 4.28, 4.36, 4.4]
y = [3, 3.96, 4.21, 2.48, 4.77, 4.13, 4.74, 5.06, 4.73, 4.59, 4.79, 5.53, 6.14, 5.71, 5.96, 5.31, 5.38, 5.41, 4.79, 5.33, 5.86, 5.03, 5.35, 5.29, 7.41, 5.56, 5.48, 5.77, 5.52, 5.68, 5.76, 5.99, 5.61, 5.78, 5.79, 5.65, 5.57, 6.1, 5.87, 5.89, 5.75, 5.89, 6.1, 5.81, 6.05, 8.31, 5.84, 6.36, 5.21, 5.81, 7.88, 6.63, 6.39, 5.99, 5.86, 5.93, 6.29, 6.07]

a = np.polyfit(np.power(x,0.5), y, 1)
y1 = a[0]*np.power(x,0.5)+a[1]

b = np.polyfit(np.log(x), y, 1)
y2 = b[0]*np.log(x) + b[1]

c = np.polyfit(x, y, 2)
y3 = c[0] * np.power(x,2) + np.multiply(c[1], x) + c[2]

plt.plot(x, y, 'ro', lw = 3, color='black')
plt.plot(x, y1, 'g', lw = 3, color='red')
plt.plot(x, y2, 'g', lw = 3, color='green')
plt.plot(x, y3, 'g', lw = 3, color='blue')
plt.axis([0, 4.5, 2, 8])
plt.rcParams['figure.figsize'] = [10, 5]
```

The parabolic too goes down at the end (blue), the logarithmic goes too quickly to zero at the beginning (green), and the square root has a strange hump (red). Is there any other ways of more accurate approximation or is it that I'm already getting pretty good?

## Answer by oliversm (score 1, accepted)

https://quant.stackexchange.com/a/55685

## What makes a particular fit good?

Naturally for quantitative finance (and really for any quantitative science), while we can sometimes assess the performance of something by eye, this is not a reliable metric. Typically assessing something by eye is only acceptable when throwing away bad/awful fits. You should not use such qualitative methods for assessing or comparing models which do a reasonable job. As each of your proposed fits seems reasonable at a glance, this means you should not pursue qualitative methods any more.

Now that you want a quantitative method for assessing the performance of the various fits, there are a few different routes you could take. It is important to highlight that these are competing criteria, sometimes contradictory, and at this point it is important to know what your priorities are. (Ironically although I have said it's time for quantitative methods, choosing which method is more of an art than a science). To name a few you could do: Which has the least squared error (minimal $l^2$-error), $l^1$-error, $l^\infty$-error? Which model has the best AIC/BIC? Which performs better on a cross validation? Which is nicer analytically/mathematically for the desired purpose?

These were just some mathematical considerations, some practical ones might be which is simplest, which is quickest numerically, which is stable or sensitive to outliers, etc. Which can be done in real time, which are at risk of over fitting.

## Are all points created equal?

From a statistical or financial standpoint, it is also worth noting that not all points are created equal. By this I mean of course some are more important than others when it comes to fitting them correctly. Perhaps some of these are more liquid than others, perhaps some are higher volume, etc. This could lead to a weighted least squares, some specific loss function, etc.

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.