3
$\begingroup$

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()
$\endgroup$
3

1 Answer 1

1
$\begingroup$

There are two different curves involved in swap pricing: the forecast curve that the index will use to forecast future coupons and the discount curve that will be used to discount the coupon amounts. In QuantLib, the discount curve is passed to the engine; that's yts_discount in your code. The forecast curve is passed to the index. Your code doesn't show how index is initialized, so I can't comment on that, but the curve handle should have been passed to its constructor.

If you're asking specifically about the linkTo method, that's used in case you want to switch to a different curve, for instance because you want to do a sensitivity calculation. If your handle was already created with a curve (like you do in CurveBuilding here) and you don't want to change it, linkTo is not needed.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.