lballabio / QuantLib

The QuantLib C++ library
http://quantlib.org
Other
5.26k stars 1.78k forks source link

Add lookback and lockout to the overnight coupon #1985

Closed marcin-rybacki closed 3 months ago

marcin-rybacki commented 4 months ago

In this PR I would like to add new functionality allowing to handle lookbacks, with and without observation shifts, and lockouts in the overnight indexed coupon.

The methodology for lookbacks and lockouts is outlined in a document by NY FED (pages 16-22). Excel examples, based on which the unit tests were created, can also be found on the NY FED website.

Lookback days do not need to define a separate member in the OvernightIndexedCoupon class, instead utilize the fixingDays_ member, because it already serves that purpose. It should be noted however that applying a lookback (with or without observation shift) might make it not possible to apply the telescopic formula and each fixing within the compounded coupon will have to be projected separately. This has to do with the fact that the value dates (and their accrual) over which the fixing is projected will no longer cancel out with the accrual of the interest period for that fixing.

To further elaborate on this, we can define a single SOFR rate projection $F(T{i}^{V}, T{i+1}^{V})$ as:

$$ F(T{i}^{V}, T{i+1}^{V}) = \left [ \frac{P(t,T{i}^{V})}{P(t,T{i+1}^{V})} - 1 \right ]\frac{1}{\alpha (T{i}^{V}T{i+1}^{V})}, $$

where $P(t,T)$ is a discount factor at time $T$, and $\alpha (T{i}^{V},T{i+1}^{V})$ is a time fraction between value dates $T{i}^{V}$ and $T{i+1}^{V}$.

Now, if we consider the formula for the compounded rate $FC(T{J},T{K})$ over the coupon period $T{J},T{K}$:

$$ FC(T{J},T{K}) = \left [ \prod{k=J}^{K-1} \left ( 1+\alpha(T{k}^{I},T{k+1}^{I})F(T{k}^{V},T{k+1}^{V}) \right ) - 1 \right ] \frac{1}{\alpha (T{J},T_{K})},$$

we can see that each fixing in the compounded rate is accrued at $\alpha(T{i}^{I},T{i+1}^{I})$. In case where there's lookback the interest $T{i}^{I},T{i+1}^{I}$ and value date periods $T{i}^{V},T{i+1}^{V}$ will not be the same and the telescopic formula will not be applicable. Also in case of an observation shift these periods might not be the same. This has to do with the fact that value dates are defined relative to the fixing date based on the fixing delay of an interest rate index. When the lookback period in the coupon is different than the fixing delay in the index, even the observation shift will not align value dates with interest dates.

It can be shown that the same applies to lockout periods. Value dates (at which the projection is calculated) correspond to the locked-out fixing, while the interest dates (at which the interest over that fixing is accrued) are not fixed at lockout, hence they do not cancel out.

Where possible, I tried to enrich the comments in the code addressing those issues.

The changes to the coupon pricer are quite significant, so I would appreciate any feedback - also given the complexity of the calculations, especially for coupon projections. I implemented unit tests that should address the corner cases, but I might have omitted/overlooked something.

This PR addresses https://github.com/lballabio/QuantLib/issues/1422.

coveralls commented 4 months ago

Coverage Status

coverage: 72.571% (+0.02%) from 72.55% when pulling aada1990ff56ba9588ef9bfe44471f5ff6e4db36 on marcin-rybacki:overnight-coupon-lookback-lockout into b9d94cad2d6eb0bb74621d2644e342a6a6aa26c7 on lballabio:master.

lballabio commented 3 months ago

Thanks! When the index has 0 intrinsic fixings days and observation shift is used, do you think it would be possible to use the telescopic property?

marcin-rybacki commented 3 months ago

Thanks! When the index has 0 intrinsic fixings days and observation shift is used, do you think it would be possible to use the telescopic property?

I would say that is a corner case where telescopic property can be applied. Thank you for pointing that out. I will add a proper check.

lballabio commented 3 months ago

Thanks! I assume all we need to give the same features to overnight interest swaps is to add the new parameters to the constructor and forward them to OvernightLeg, right? If so, I can do it if you're busy.

marcin-rybacki commented 3 months ago

Thanks! I assume all we need to give the same features to overnight interest swaps is to add the new parameters to the constructor and forward them to OvernightLeg, right? If so, I can do it if you're busy.

Yes, I think that is all we need to do. I can do it still in this PR, if that's ok.

lballabio commented 3 months ago

That would be great, thanks.

lballabio commented 3 months ago

I'm guessing that quoted swaps can have these features, too, meaning that we'll need to support them in OISRateHelper as well—is this correct?

lballabio commented 3 months ago

If that's the case, please have a look at #1998 and tell me if you think it's ok.

marcin-rybacki commented 3 months ago

I'm guessing that quoted swaps can have these features, too, meaning that we'll need to support them in OISRateHelper as well—is this correct?

Good idea! Those features would be mostly added to issued bonds or loans, depending on the requirements of treasury departments. There could be some swaps offered to hedge those. Still, it's nice to have the helper support it.