Hello, dear reader.

It’s great to have a community around an open-source project like QuantLib. The latest proof? A recent contribution that I merged last week. Let me rewind a bit.

An unsolved problem

Almost two years ago, I published two posts that originally appeared as articles in Wilmott Magazine. They looked at the problem of implementing a coupon stub, like the ones sometimes found at the beginning of a floating-rate bond or an interest-rate swap, whose rate must be interpolated between the fixings of two quoted indexes. You can find them here (part I) and here (part II). They’re still a useful read: part I describes the structure of the part of the library that deals with cash flows, and part II shows a few possibilities for implementing the stub and discusses the pros and cons of each.

At the time, I tried three implementations: the first two used a new coupon class and the third used a new index class. All of them had drawbacks, so I wasn’t able to recommend one for inclusion in the library. So, no closure at all. A bummer, as far as blog series go.

The solution at last

The whole thing remained a bummer until recently, when Kyrylo Protsenko (hi, Kyrylo) submitted a pull request for implementing such a coupon. We had a bit of discussion, I pointed him to my previous posts, and he connected the dots and came back with the solution I couldn’t see at the time. It was not an aut–aut, but an et–et. For those of you not living in a former Roman province, it was not an either–or but a both. The PR introduced a new coupon and a new index, and the two of them working together avoid the drawbacks of either.

Here is a sketch that, in the interest of brevity and clarity, simplifies the new classes beyond all decency. The real classes have more features, like the ability of selecting the index for interpolation autonomously instead of having the user pass them; you can see them in detail in the pull request linked above, or in the library code.

The index works more or less as the one sketched in part II:

   class WeightedIndex : public IborIndex {
    public:
      WeightedIndex(...) {
        // stores the two indexes to interpolate
        // and their relative weights
      }
      Rate forecastFixing(
          const Date& fixingDate) const override {
        Rate fixing = 0.0;
        for (/* iterate over indexes and weights */)
            fixing += weight * index->fixing(fixingDate);
        return fixing; 
      }
      Rate pastFixing(
          const Date& fixingDate) const override {
        // same idea as forecastFixing
      }
      ...
   };

Not surprisingly, it returns the stub fixing by combining the fixings of the two underlying indexes. In part II, I pointed out that this is not enough: but with a new coupon to support it, that’s no longer true.

   class StubIborCoupon : public IborCoupon {
    public:
      StubIborCoupon(...) {
        // the constructor figures out the two indexes
        // to use according to the length of the stub
        // and their relative weights, then creates
        // the interpolated index.
      }
      Rate indexFixing() const override {
        return weightedIndex_->fixing(fixingDate());
      }
      ...
   };

The coupon is no longer the generic IborCoupon, expecting a simple index (the reason why the index alone wouldn’t work, see part II); it’s a specific coupon that knows to be using an interpolated index and overrides the parts of IborCoupon that wouldn’t work with it. Moreover, it’s the coupon itself that selects the two indexes to interpolate and creates the correct WeightedIndex instance.

Coming soon to a library near you

The above landed in QuantLib a couple of weeks ago and will be part of release 1.44, out in October 2026; thus bringing a nice close to this series of posts. I just love it when open source works. Thanks again, Kyrylo!

Subscribe to my Substack to receive my posts in your inbox, or follow me on Twitter or LinkedIn if you want to be notified of new posts, or subscribe via RSS if you’re the tech type: the buttons for all that are in the footer. Also, I’m available for training, both online and (when possible) on-site: visit my Training page for more information.