I'm trying to figure out the way to value SONIA swap over the range of days based on the example in the QuantLib Python book (which has bonds in it).

import QuantLib as ql

rate = 0.02
calculation_date = ql.Date(10, 12, 2021)
ql.Settings.instance().evaluationDate = calculation_date
day_count = ql.Actual365Fixed()
ois_curve = ql.FlatForward(calculation_date, rate, day_count)

curve_handle = ql.RelinkableYieldTermStructureHandle(ois_curve)

swap = ql.MakeOIS(

As expected print(swap.NPV()) 0.

Now to calculate a NPV on this swap after a month (assuming the same flat curve for simplicity)

new_date = calculation_date + ql.Period("1M")
ql.Settings.instance().evaluationDate = new_date
new_ois_curve = ql.FlatForward(new_date, risk_free_rate, day_count)
curve_handle = ql.RelinkableYieldTermStructureHandle(new_ois_curve)

After calling NPV I get the following error

RuntimeError                              Traceback (most recent call last)
/tmp/ipykernel_10169/552115063.py in <module>
----> 1 swap.NPV()

~/miniconda3/envs/notebooks/lib/python3.9/site-packages/QuantLib/QuantLib.py in NPV(self)
   9658     def NPV(self):
-> 9659         return _QuantLib.Instrument_NPV(self)
   9661     def errorEstimate(self):

RuntimeError: 2nd leg: Missing SoniaON Actual/365 (Fixed) fixing for December 14th, 2021

I can see for instance here that the way to fix it to provide fixing for an index. The question I have here is how may data points would I need to price this OIS swap? Do I need to provide index fixing for every day between swap start date and new valuation date?


1 Answer 1


Yes, you need to provide index fixing for every day between the start date and the valuation date. The code will compose them.


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.