# Calculating market value of a vanilla swap at a later date in QuantLib

I am following the cookbook example for pricing a Vanilla Swap in QuantLib Python, given here.

Now let's assume that a week passed, and we are trying to calculate the mark to market value of the same swap. After a bit of looking around, I have found this thread, which leads me to believe that in order to re-price a swap at a later date, one needs to change the settlement date to get the updated market value of a swap. This does not seem right, since changing the settlement_date for the swap would result in shifting the cash flow schedules as well.

What I am looking for is to keep the swap definition (cash flow dates, maturity etc), load in a new yield curve at a later date, and re-price my swap using the new yield curve.

Can anybody show me how to do this?

Thanks!

You can keep the Swap instance you created, which contains the swap definition, and change the evaluation date and the curves you're using.

The evaluation date is simple: in Python,

Settings::instance().evaluationDate = new_date


will do the trick.

As for the curves, you'll have to change the declaration of discount_curve and libor_curve so that they use YieldTermStructureRelinkableHandle instead of YieldTermStructureHandle. This will give you the possibility to relink them to a different curve. Your modified script will be something like:

# as in the original notebook: create the swap,
# the curves for pricing on the first evaluation date, etc.

print swap.NPV()   # as of the first evaluation date

Settings::instance().evaluationDate = new_date

# the curve for the new evaluation date
)
# the curve for the new evaluation date
)

print swap.NPV()  # as of the new date, using the new curves.


In short: keep the swap, change everything else as required. The swap will recalculate accordingly.

One thing you might need to be aware of: if any of the non-expired floating coupon fixed before the evaluation date, you'll have to load the fixing of the underlying index. The interface to do that is, e.g.,

libor3M_index.addFixing(date, value)

• Luigi, thank you for your comment. I was able to reprice a swap by doing what you say, and adding a fixing. I would like to understand why adding a fixing is necessary to calculate the NPV if the swap is to be repriced one day after it was created, but not on the day that swap was created. Thx – bob.jonst Sep 11 '17 at 23:09
• It the coupon fixes today, you can forecast the fixing off the LIBOR curve. If it fixed yesterday, you can't, because the curve starts at today's date and is missing information on the past. – Luigi Ballabio Sep 12 '17 at 7:23
• thx, makes sense – bob.jonst Sep 12 '17 at 20:53