From 3a984131765801f50302611d42c2f2e45a9c3ec7 Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 3 Mar 2024 23:26:30 +0100 Subject: [PATCH 1/2] recompute fixingDays after add/subtract 10 years --- test-suite/convertiblebonds.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/test-suite/convertiblebonds.cpp b/test-suite/convertiblebonds.cpp index 904bdcea68b..fe43f6c759f 100644 --- a/test-suite/convertiblebonds.cpp +++ b/test-suite/convertiblebonds.cpp @@ -55,7 +55,7 @@ struct CommonVars { Calendar calendar; DayCounter dayCounter; Frequency frequency; - Natural settlementDays; + Natural settlementDays, fixingDays; RelinkableHandle underlying; RelinkableHandle dividendYield, riskFreeRate; @@ -78,10 +78,15 @@ struct CommonVars { frequency = Annual; settlementDays = 3; - issueDate = calendar.advance(today,2,Days); + fixingDays = 2; + issueDate = calendar.advance(today, fixingDays, Days); maturityDate = calendar.advance(issueDate, 10, Years); // reset to avoid inconsistencies as the schedule is backwards issueDate = calendar.advance(maturityDate, -10, Years); + fixingDays = 0; + for (Date d = today; d != issueDate; ++d) + if (calendar.isBusinessDay(d) && !calendar.isWeekend(d.weekday())) + ++fixingDays; underlying.linkTo(ext::make_shared(50.0)); dividendYield.linkTo(flatRate(today, 0.02, dayCounter)); @@ -231,14 +236,13 @@ BOOST_AUTO_TEST_CASE(testBond) { ext::shared_ptr index = ext::make_shared(discountCurve); - Natural fixingDays = 2; std::vector gearings(1, 1.0); std::vector spreads; ConvertibleFloatingRateBond euFloating(euExercise, vars.conversionRatio, vars.no_callability, vars.issueDate, vars.settlementDays, - index, fixingDays, spreads, + index, vars.fixingDays, spreads, vars.dayCounter, schedule, vars.redemption); euFloating.setPricingEngine(engine); @@ -246,7 +250,7 @@ BOOST_AUTO_TEST_CASE(testBond) { ConvertibleFloatingRateBond amFloating(amExercise, vars.conversionRatio, vars.no_callability, vars.issueDate, vars.settlementDays, - index, fixingDays, spreads, + index, vars.fixingDays, spreads, vars.dayCounter, schedule, vars.redemption); amFloating.setPricingEngine(engine); @@ -261,7 +265,7 @@ BOOST_AUTO_TEST_CASE(testBond) { DateGeneration::Backward, false); FloatingRateBond floating(vars.settlementDays, vars.faceAmount, floatSchedule, - index, vars.dayCounter, Following, fixingDays, + index, vars.dayCounter, Following, vars.fixingDays, gearings, spreads, std::vector(), std::vector(), false, From 368c13b0641ecd9940915e865331b2c1bc01e8b3 Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 4 Mar 2024 13:29:19 +0100 Subject: [PATCH 2/2] make use of Calendar::businessDaysBetween() --- test-suite/convertiblebonds.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test-suite/convertiblebonds.cpp b/test-suite/convertiblebonds.cpp index fe43f6c759f..7f0f314cd4a 100644 --- a/test-suite/convertiblebonds.cpp +++ b/test-suite/convertiblebonds.cpp @@ -83,10 +83,7 @@ struct CommonVars { maturityDate = calendar.advance(issueDate, 10, Years); // reset to avoid inconsistencies as the schedule is backwards issueDate = calendar.advance(maturityDate, -10, Years); - fixingDays = 0; - for (Date d = today; d != issueDate; ++d) - if (calendar.isBusinessDay(d) && !calendar.isWeekend(d.weekday())) - ++fixingDays; + fixingDays = calendar.businessDaysBetween(today, issueDate); underlying.linkTo(ext::make_shared(50.0)); dividendYield.linkTo(flatRate(today, 0.02, dayCounter));