|
From: Arkadiy N. <ark...@gm...> - 2024-08-27 03:42:44
|
Hi Jack,
It looks like your test is undermined by your using the flat 5% curve, forcing your resets, no matter the frequency, to generate exactly the same interest over the 3M period. It’s just that the fixing for the daily resets will be slightly smaller than that for weekly resets, and that in turn will be smaller than the fixing for the quarterly resets (to account for the compounding). I would try creating curve with a few tenors, and re-running the test with that new curve.
Sent from my iPad
> On Aug 26, 2024, at 10:09 PM, Spectrum <jac...@gm...> wrote:
>
>
> In the QuantLib python document, there is an example for creating a custom OvernightIndex:
>
> name = 'CNYRepo7D'
> fixingDays = 1
> currency = ql.CNYCurrency()
> calendar = ql.China()
> dayCounter = ql.Actual365Fixed()
> overnight_index = ql.OvernightIndex(name, fixingDays, currency, calendar, dayCounter)
>
> In this example, a CNYRepo7D index is created as an OvernightIndex. But, the CNYRepo7D has a coupon reset frequency of 7 days, not daily. So the coupon should compound every week, not everyday. Is this example correct?
>
> I then tried to use ql.IborIndex to model CNYRepo7D, where I created an IborIndex with a ql.Period(7, ql.Days). I also tried an IborIndex with a Period of 3M. But the result seems to be identical. I created a swap with a flat curve of 5% and printed out the floating leg cash flow. All 3 indexes (Overnight, 7D Ibor, 3M Ibor) give me the same cash flow for the dummy swap.
>
> What is the correct way to model a swap where its reset frequency is different from the payment frequency?
>
> import QuantLib as ql
>
> today = ql.Date(24,8,2024)
>
> # create a flat curve of 5%
> rate = 0.05
> dayCounter = ql.Actual365Fixed()
> interest_rate = ql.QuoteHandle(ql.SimpleQuote(rate))
> flat_curve = ql.FlatForward(today, ql.QuoteHandle(ql.SimpleQuote(rate)), dayCounter)
> curve_handle = ql.YieldTermStructureHandle(flat_curve)
>
> currency = ql.CNYCurrency()
> calendar = ql.China()
>
>
> def print_floating_cashflow_given_index(index):
> # Add the fixing
> index.addFixing(ql.Date(23, 8, 2024), 0.05)
> # Create a 1Y swap with Quarterly Payment Frequency
> maturity_date = calendar.advance(today, 1, ql.Years, ql.Unadjusted)
> schedule = ql.Schedule(today, maturity_date, ql.Period(3, ql.Months), calendar, ql.ModifiedFollowing,
> ql.ModifiedFollowing, ql.DateGeneration.Forward, False)
> schedule_len = len(schedule) - 1
> coupon_swap = ql.NonstandardSwap(ql.VanillaSwap.Receiver,
> [1] * schedule_len,
> [1] * schedule_len,
> schedule,
> [0.05] * schedule_len,
> dayCounter,
> schedule,
> index,
> [1.] * schedule_len,
> [0] * schedule_len,
> dayCounter,
> False,
> True)
> for cf in coupon_swap.floatingLeg():
> print(cf.date(), cf.amount())
>
> # create Overnight Index
> fixingDays = 1
> overnight_index = ql.OvernightIndex('CNYRepo7D',
> fixingDays,
> currency,
> calendar,
> dayCounter,
> curve_handle)
> print('Overnight Index Floating CashFlow')
> print_floating_cashflow_given_index(overnight_index)
>
> # create Ibor Weekly Index
> ibor_weekly_index = ql.IborIndex(
> 'CNY_Weekly',
> ql.Period(7, ql.Days),
> 1,
> currency,
> calendar,
> ql.ModifiedFollowing,
> False,
> dayCounter,
> curve_handle
> )
> print('Weekly Ibor Index Floating CashFlow')
> print_floating_cashflow_given_index(ibor_weekly_index)
>
> # create Ibor Quarterly Index
> ibor_quarterly_index = ql.IborIndex(
> 'CNY_Quarterly',
> ql.Period(3, ql.Months),
> 1,
> currency,
> calendar,
> ql.ModifiedFollowing,
> False,
> dayCounter,
> curve_handle
> )
> print('Quarterly Ibor Index Floating CashFlow')
> print_floating_cashflow_given_index(ibor_quarterly_index)
>
> Output
>
> Overnight Index Floating CashFlow
> November 25th, 2024 0.012465753424657534
> February 24th, 2025 0.012543774790186646
> May 26th, 2025 0.012543774790186868
> August 25th, 2025 0.012543774790186868
> August 25th, 2025 1.0
> Weekly Ibor Index Floating CashFlow
> November 25th, 2024 0.012465753424657534
> February 24th, 2025 0.012543774790186646
> May 26th, 2025 0.012543774790186868
> August 25th, 2025 0.012543774790186868
> August 25th, 2025 1.0
> Quarterly Ibor Index Floating CashFlow
> November 25th, 2024 0.012465753424657534
> February 24th, 2025 0.012543774790186646
> May 26th, 2025 0.012543774790186868
> August 25th, 2025 0.012543774790186868
> August 25th, 2025 1.0
>
> Thanks
> Jack
>
> _______________________________________________
> QuantLib-users mailing list
> Qua...@li...
> https://lists.sourceforge.net/lists/listinfo/quantlib-users
|