# Forward Swap Rate calculation using Quantlib

Here, we have an example for the calculation of Forward Swap Rate - How to compute forward swap rates?

Below is my Forward Swap -

from QuantLib import *
import datetime
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

calc_date = Date(29, 3, 2019)
start = 10
length = 10
maturity_date = start_date + Period(length, Years)

spot_curve = FlatForward(calc_date, QuoteHandle(SimpleQuote(0.01)), Actual365Fixed())
termStructure = YieldTermStructureHandle(spot_curve)
index = Euribor6M(termStructure)

fixedSchedule = Schedule(start_date,     ## pd.DataFrame({'date': list(fixedSchedule)})
maturity_date,
Period(1, Years),
TARGET(),
DateGeneration.Forward,
False
)
floatingSchedule = Schedule(start_date,  ## pd.DataFrame({'date': list(floatingSchedule)})
maturity_date,
Period(6, Months),
TARGET(),
ModifiedFollowing,
ModifiedFollowing,
DateGeneration.Forward,
True
)

10000000,
fixedSchedule,
1.45 / 100,
Thirty360(Thirty360.BondBasis),
floatingSchedule,
index,
0.0,
index.dayCounter()
)


Is there any way to directly obtain the Forward Swap rate using QuantLib? I am trying to avoid explicit calculations using the given link.

You can't get the Forward Swap directly since you will have to give some conventions for what you want. However there is a less verbose way to construct a forward swap and get it's fairRate. Note that most conventions will come from the index you specified.

import QuantLib as ql

calc_date = ql.Date(29, 3, 2019)

spot_curve = ql.FlatForward(calc_date, ql.QuoteHandle(ql.SimpleQuote(0.01)), ql.Actual365Fixed())
termStructure = ql.YieldTermStructureHandle(spot_curve)
index = ql.Euribor6M(termStructure)
engine = ql.DiscountingSwapEngine(termStructure)

start = 10
length = 10
swapTenor = ql.Period(length, ql.Years)
forwardStart = ql.Period(start, ql.Years)
swap = ql.MakeVanillaSwap(swapTenor, index, 0.0, forwardStart, pricingEngine=engine)

print(f"Forward Rate Swap Rate: {swap.fairRate():.3%}")


Forward Rate Swap Rate: 1.006%

(Edit) To see the swap details:

print(swap.fixedDayCount().name())
print([dt.ISO() for dt in swap.fixedSchedule()])
print(swap.floatingDayCount().name())
print([dt.ISO() for dt in swap.floatingSchedule()])


30/360 (Bond Basis)
['2030-09-23', '2031-09-23', '2032-09-23', '2033-09-23', '2034-09-25', '2035-09-24', '2036-09-23', '2037-09-23', '2038-09-23', '2039-09-23', '2040-09-24']
Actual/360
['2030-09-23', '2031-03-24', '2031-09-23', '2032-03-23', '2032-09-23', '2033-03-23', '2033-09-23', '2034-03-23', '2034-09-25', '2035-03-27', '2035-09-24', '2036-03-24', '2036-09-23', '2037-03-23', '2037-09-23', '2038-03-23', '2038-09-23', '2039-03-23', '2039-09-23', '2040-03-23', '2040-09-24']

• Thanks. So in this case, we are not considering the Swap fixed/float payoff structure. Is that logically correct? Also, what is the purpose of the function DiscountingSwapEngine? Appreciate your clarifications Commented Sep 17, 2020 at 8:15
• You are considering the fixed/float payoff structure. If you check the swap details they will have the correct EUR Swap conventions (from Euribor6M template). The DiscountingSwapEngine is the pricing engine needed to value the swap and find the fairRate Commented Sep 17, 2020 at 8:40