Skip to content
All library documents

Repricing a QuantLib Swap with New Curves at a Later Date

Article Quant Q&A · Author: bob.jonst

Summary

The document describes how to mark an existing vanilla swap to market after time has passed while preserving its original cash-flow dates and maturity. Rather than rebuilding the swap with shifted schedules, the approach is to retain the swap object, advance QuantLib’s evaluation date, and update the market curves used for valuation. Relinkable yield-curve handles allow discounting and floating-rate projection curves to be replaced with curves for the new valuation date.

The swap’s net present value can then be recalculated from the updated evaluation date and curves. The response also notes that floating coupons fixed before the new evaluation date may require historical index fixings to be loaded. It provides the core workflow but no numerical pricing example, discussion of curve construction, or treatment of additional market conventions. Accurate results therefore depend on supplying appropriate current curves and all required past fixings.

Key ideas

  • Keep the existing swap object to preserve its contractual schedule and maturity.
  • Advance the evaluation date to the desired valuation date.
  • Use relinkable curve handles to connect the swap to updated discount and projection curves.
  • Load index fixings for floating coupons fixed before the new evaluation date.

Tags

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


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

## Answer by Luigi Ballabio (score 2, accepted)

https://quant.stackexchange.com/a/35983

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

libor_curve.linkTo(
    # the curve for the new evaluation date
)
discount_curve.linkTo(
    # 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)
```

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.