# How many parameters in a discount curve exponential spline fit?

I am investigating the ExponentialSplinesFitting class in QuantLib. I've used this fitting technique using a variety of systems in the past (including by hand!). The form is $$df(t) = \sum_{n=1}^{N}(\beta(n)\exp(-n \cdot \alpha \cdot t))$$, ie there is one alpha (which QuantLib calls 'kappa') and 1 to N Betas.

QuantLib seems to be hard-coded with 9 Betas (which will reduce to 8 independent Betas if df(0) constrained = 1):

Size ExponentialSplinesFitting::size() const {
return constrainAtZero_ ? 9 : 10;
}

My question is: Why 9?

When using this method in the past, I've used a maximum of 6 in practice. I have found the "best" number to be influenced by the density of bonds across the term structure. Adding more parameters increases the quality of fit at the short end, but can have the side effect of producing unwarranted perturbations at the long end. So unless you have a lot of bonds in the 0-1 year range, using fewer parameters may give a better fit further out. Bottom line: should I be modifying the QL implementation to have a variable number of parameters?

I believe $$N = 9$$ is the default because the original paper, "Merrill Lynch Exponential Spline Model," used that value for the US Treasury market when the model was developed back in 1994. To be precise, the paper actually showed results for $$N$$ up to 14, concluding that fitted residuals are within noise levels at $$N \geq 9$$; it also recommended lower $$N$$ for French and Canadian markets.
So yes, as you have pointed out, there is no reason to use $$N = 9$$. The exact number of basis functions to use depends on the market in question. In my personal experience, $$N$$ in the range of 7 or 8 works just fine for US Treasuries and results in more stable curves than 9. A book authored by the model's creators used a value of 7 as well. For markets where fewer instruments are available (aka pretty much every other bond market), even lower $$N$$ should be used. I should also note that I ran into a ton of numerical issues when I tested $$N \geq 10$$.
Fitting the front end of the curve with this kind of model, in my opinion, is not particularly useful. You're better off appending the GC repo curve, which will give you more usable forward yields. To improve fitting at the long end, you could also try adjusting the weights assigned to long bonds in the weighted least squares estimator, in addition to adjusting the value of $$N$$.