# 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
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)



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''

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,
 * 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)