Skip to content
All library documents

Finding a Fair Basis Swap Spread with a Numerical Solver

Article Quant Q&A · Author: Bryant

Summary

The discussion addresses how to find the fair spread on a single-currency basis swap built with QuantLib’s floating-for-floating swap instrument. The instrument does not expose a direct method for solving the fair spread, so the suggested approach is to create a pricing function that takes a candidate spread, constructs the swap with that spread, assigns a discounting engine, and returns its net present value.

A root finder such as Brent’s method can then search for the spread that makes the swap’s net present value zero, given an initial guess, step size, and accuracy tolerance. This illustrates a general numerical-pricing workflow for instruments without a built-in fair-spread accessor. The example is not a complete implementation guide: it assumes schedules, indices, conventions, curves, and other inputs are already set up correctly, and it does not discuss validation or sensitivities.

Key ideas

  • The floating-for-floating swap class described does not provide a direct fair-spread method.
  • Define a pricing function that recalculates net present value for candidate spreads.
  • Use a root-finding method to locate the spread that makes the swap value zero.
  • The result depends on correct market curves, schedules, indices, and swap conventions.

Tags

Full text
# How to calculate basis swap fair spread Using Quantlib 'floatfloatswap'?


# How to calculate basis swap fair spread Using Quantlib 'floatfloatswap'?












I am trying to calculate a single currency basis swap by using the Quantlib floatfloatswap function.

Please advice if I am doing wrongly.

```
float3m=floatingSchedule1
float6m=floatingSchedule2
index3m=index1
index6m=index2
spread=0
notional=100e6
basisSwap=ql.FloatFloatSwap(ql.VanillaSwap.Payer,
                [notional] * (len(float3m)-1),
                [notional] * (len(float6m)-1),
                float3m,
                index3m,
                ql.Actual360(),
                float6m,
                index6m,
                ql.Actual360(), False, False,
                [] * (len(float3m)-1),
                [] * (len(float3m)-1))
swapEngine = DiscountingSwapEngine(discount_curve)
basisSwap.setPricingEngine(swapEngine)

basisSwap.spread1()
```

Trying not to be too length, the input arguments are not copied here.

After setting up, I try to use floatfloatswap.spread1() to obtain the fair spread. It returns an error message:

> 'AttributeError: 'FloatFloatSwap' object has no attribute 'spread1''

## Answer by David Duarte (score 1)

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

The FloatFloatSwap class does not have a method to solve for the spread but you can use a solver to find it.

Do something like this...

```
def basisFairValue(spread):
    basisSwap = ql.FloatFloatSwap(ql.VanillaSwap.Payer,
                    [notional] * size3m,
                    [notional] * size6m,
                    float3m,
                    index3m,
                    ql.Actual360(),
                    float6m,
                    index6m,
                    ql.Actual360(), False, False,
                    [1] * size3m, [spread] * size3m)
    basisSwap.setPricingEngine(engine)
    return basisSwap.NPV()
    
accuracy = 0.0001
guess = -0.0002
step = 0.0001
fairSpread = ql.Brent().solve(basisFairValue, accuracy, guess, step)
print(fairSpread)
```

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.