Below are steps I followed to value a few swaps. Just want to know if I have included the key steps in the below definitions. In some examples I found that we are also adding indexcurve.linkTo(). I believe linking is not required as my yield term structure is already linked to yts_discount. Please suggest.
#rates as below
rates = Maturity_Date Zero_Rate
8/25/2022 0.000556
8/31/2022 0.000580
9/7/2022 0.000569
9/14/2022 0.000573
9/23/2022 0.000577
def CurveBuilding(key_value):
dc = ql.ActualActual()
crv = ql.ZeroCurve(
dates, rates, dc, ql.NullCalendar(), ql.Linear(), ql.Compounded, ql.Annual)
crv.enableExtrapolation()
shifted = ql.ZeroSpreadedTermStructure(ql.YieldTermStructureHandle(crv),ql.QuoteHandle(shift))
return ql.YieldTermStructureHandle(shifted)
def ConstructSwap():
yts = curves.get(floatindex)
yts_discount = curves.get(disc_curve)
fixingCalendar = index.fixingCalendar()
fixedSchedule = ql.MakeSchedule(effectiveDate, terminationDate, fixed_leg_tenor)
floatSchedule = ql.MakeSchedule(effectiveDate, terminationDate, float_leg_tenor,
convention=ql.ModifiedFollowing, endOfMonth=True
,calendar=fixingCalendar)
swap = ql.VanillaSwap(
ql.VanillaSwap.Receiver, notional,
fixedSchedule, fixedRate, fixed_leg_daycount,floatSchedule, index, spread, float_leg_daycount)
engine = ql.DiscountingSwapEngine(yts_discount)
swap.setPricingEngine(engine)
return swap, original_tenor
#dataframe of few swaps
for idx, row in df.iterrows():
swap, original_tenor = ConstructSwap()
npv = swap.NPV()