|
From: Luigi B. <lui...@gm...> - 2023-10-11 13:20:43
|
Hi Steve,
the fixing rate is not used per se—none of the coupons uses it as a
stored fixing—but as Marcin says, its presence causes the bootstrapped
forecasting curve to be slightly different, and therefore the future
fixings calculated off that curve will be different.
I wouldn't make two instances of the index, though. If the fixing was
available at the time the swap rates were quoted, it should be included for
consistency since it was taken into account; and for instrument valuation,
you'll also need the fixing in case one of your instruments requires it.
Hope this helps,
Luigi
On Wed, Sep 13, 2023 at 12:10 PM Steve Hsieh <war...@gm...>
wrote:
> Hi Marcin
> Thanks for the reply. It does provide valuable information. According to
> your previous discussion, it looks like I have to make two independent
> instance of index. One is for build term structure, and the other one is
> for instrument valuation. However, I still have confusion on the valuation
> part. When calling NPV in my example, the fixing rate on valuation date
> should not be used, since it’s not the applicable fixing date for the
> relevant cash flows. I will try to look deeper into this by review the
> source code. Many Thanks for the help.
>
> Best,
> Steve
>
>
> On Wed, Sep 13, 2023 at 5:17 PM Marcin Rybacki <mry...@gm...>
> wrote:
>
>> Hi Steve,
>>
>> That fixing that you are passing on 2019/11/12 (also the evaluation date)
>> is actually quite important, because it is being set on the swap
>> instruments you are using to bootstrap the curve. Hence, it will affect the
>> NPV of the swap, which might not necessarily need that particular fixing.
>>
>> See this related issue for more color:
>> https://github.com/lballabio/QuantLib/issues/1213
>>
>> Hope this helps.
>>
>> Kind regards,
>> Marcin
>>
>> On Wed, 13 Sept 2023 at 10:44, Steve Hsieh <war...@gm...>
>> wrote:
>>
>>> 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)
>>>
>> _______________________________________________
>>> QuantLib-users mailing list
>>> Qua...@li...
>>> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>>>
>> _______________________________________________
> QuantLib-users mailing list
> Qua...@li...
> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>
|