|
From: Luigi B. <lui...@gm...> - 2024-09-19 10:07:36
|
Hi, an update: it turns out that sometimes SubPeriodsLeg doesn't do the right thing, see < https://implementingquantlib.substack.com/p/coupons-with-multiple-resets>. I'll try to get a fix in the library in one of the next releases. Luigi On Tue, Aug 27, 2024 at 9:11 AM Luigi Ballabio <lui...@gm...> wrote: > Hi, > as Arkadiy says, they will have the same fixing, but there are other > problems as well. > > One is that, unfortunately, Period(7, Days) is not the same as one week; > it's 7 business days instead. You need Period(1, Weeks). We'll have to > try and disambiguate it sometime, but it's everywhere in the library so > we'll have to be careful. > > Another is that NonstandardSwap creates floating-rate coupons with a > single initial fixing, regardless of the tenor of the passed index; so > coupons will take the 1-week fixing at the beginning of their tenor and > accrue it for the whole three months without compounding. To get the > behavior you want, there's no built-in instrument but you can build the two > legs manually and pass them to the Swap class. You'll have to use FixedLeg > for the fixed coupons and SubPeriodsLeg for the floating leg; the latter > builds a sequence of SubPeriodsCoupon instances, which have the compounding > behavior you want. > > I'll try to publish an example when I get a chance to work on it, but in > the meantime I hope this helps to point you in the right direction. > > Luigi > > > On Tue, Aug 27, 2024 at 5:46 AM Arkadiy Naumov <ark...@gm...> > wrote: > >> 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 >> >> _______________________________________________ >> QuantLib-users mailing list >> Qua...@li... >> https://lists.sourceforge.net/lists/listinfo/quantlib-users >> > |