|
From: Steve H. <war...@gm...> - 2023-09-13 08:42:57
|
Dear all,
I have a question regarding addfixing. I try to value a portfolio of
interest rate swaps, I add all the existing and required fixing rate of my
swaps to the index, however I get unexpected npv and dv01 for some trades.
My original code is in C++, for conenience, I try to reproduce it in python
as below. The story is that I add a fixing rate on 2019/11/12 which is
actually unnecessary for this swap. and it change the NPV of this swap. I
think the pricer will automatically choose pastfixing or forecasting by
swap’s fixing dates. Since it’s not the required fixing rate, adding such a
rate should have no impact to the NPV.
Do I miss anything or I make any mistake?
Need your advice and help.
Many Thanks.
Best,
Steve
from IPython.display import display
import QuantLib as ql
import pandas as pd
ql.Settings.instance().evaluationDate= ql.Date(12, 11, 2019)
refDate=ql.Settings.instance().evaluationDate
cashFlowCdr = ql.JointCalendar(ql.UnitedStates(ql.UnitedStates.Settlement),
ql.UnitedStates(ql.UnitedStates.LiborImpact))
yts = ql.RelinkableYieldTermStructureHandle()
instruments = [
('depo', '3M', 0.020),
('swap', '1Y', 0.031),
('swap', '2Y', 0.032),
('swap', '5Y', 0.035)
]
helpers = ql.RateHelperVector()
index = ql.USDLibor(ql.Period('3M'),yts)
for instrument, tenor, rate in instruments:
if instrument == 'depo':
helpers.append( ql.DepositRateHelper(rate, index) )
if instrument == 'fra':
monthsToStart = ql.Period(tenor).length()
helpers.append( ql.FraRateHelper(rate, monthsToStart, index) )
if instrument == 'swap':
swapIndex = ql.UsdLiborSwapIsdaFixAm(ql.Period(tenor))
helpers.append( ql.SwapRateHelper(rate, swapIndex))
curve = ql.PiecewiseLogCubicDiscount(0, cashFlowCdr, helpers, ql.
ActualActual())
yts.linkTo(curve)
engine = ql.DiscountingSwapEngine(yts)
calendar = ql.TARGET()
start = ql.Date(11,9,2019)
maturity = calendar.advance(start, ql.Period('4y'))
fixedSchedule = ql.MakeSchedule(start, maturity, ql.Period('3M'))
floatSchedule = ql.MakeSchedule(start, maturity, ql.Period('3M'))
index.addFixing( ql.Date(9, 9, 2019), 0.020)
index.addFixing( ql.Date(12, 11, 2019), 0.030)
swap = ql.VanillaSwap(
ql.VanillaSwap.Payer, 1000000,
fixedSchedule, 0.01, ql.Thirty360(),
floatSchedule, index, 0, ql.Actual360()
)
swap.setPricingEngine(engine)
npv=swap.NPV()
print(npv)
|