|
From: Peter C. <pca...@gm...> - 2021-08-29 13:43:52
|
Hi Suhas,
you should use OISRateHelper or AverageOISRateHelper instead of
SwapRateHelper for SOFR swaps: The latter class builds a swap with
daily payments. SOFR swaps have annual payments instead. The former
two classes build such swaps with a compounded or averaged rate.
Best Regards
Peter
On Sat, 28 Aug 2021 at 22:13, Suhas Ghorpadkar <suh...@gm...> wrote:
>
> While building SOFR curve for discounting, I am noticing that creating SwapRateHelper gets progressively slower. Below is my test case and the output. There is also comparison with USDLibor 3M where I do not see this behavior. I wonder if I am doing something wrong in creating Sofr index. Any help is appreciated.
> Thanks.
>
> #include <catch.hpp>
> #include <ql/indexes/ibor/sofr.hpp>
> #include <ql/indexes/ibor/usdlibor.hpp>
> #include <ql/instruments/forwardrateagreement.hpp>
> #include <ql/instruments/makevanillaswap.hpp>
> #include <ql/termstructures/yield/ratehelpers.hpp>
> #include <ql/utilities/dataparsers.hpp>
> #include <string>
> #include <iostream>
>
> using namespace QuantLib;
>
> TEST_CASE("sofr curvebuilder build test") {
>
> Settings::instance().evaluationDate() = Date(16,August,2021);
>
> std::vector<std::string> periods {"1M","2M","3M","4M","5M","6M","9M","1Y",
> "18M","2Y","3Y","4Y","5Y","7Y","10Y","12Y",
> "15Y","20Y","25Y","30Y","40Y","50Y"};
> Calendar swapcalendar = UnitedStates(UnitedStates::Market::FederalReserve);
> Frequency frequency = Frequency::Annual;
> DayCounter fDayCount = Actual360();
> std::vector<ext::shared_ptr<RateHelper>> sofrhelpers,liborhelpers;
> sofrhelpers.reserve(22);liborhelpers.reserve(22);
> ext::shared_ptr<Sofr> sofr(new Sofr());
> ext::shared_ptr<IborIndex> usdlibor = ext::make_shared<USDLibor>(Period(3, Months));
>
> for (auto& period_str : periods){
>
> Period period = PeriodParser::parse(period_str);
>
> ext::shared_ptr<SimpleQuote> s = ext::make_shared<SimpleQuote>(0.05 / 100.0);
> auto start = std::chrono::steady_clock::now(); //START
> std::shared_ptr<SwapRateHelper> helper = std::make_shared<SwapRateHelper>(Handle<Quote>(s), period, swapcalendar,
> frequency, BusinessDayConvention::ModifiedFollowing,
> fDayCount, sofr);
> auto end = std::chrono::steady_clock::now(); //STOP
> std::cout << period << " sofrhelper took : " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << " ms" << std::endl;
> sofrhelpers.emplace_back(helper);
> }
> REQUIRE(sofrhelpers.size()==22);
>
> std::cout << "====================================" << std::endl;
>
> for (auto& period_str : periods){
>
> Period period = PeriodParser::parse(period_str);
>
> ext::shared_ptr<SimpleQuote> s = ext::make_shared<SimpleQuote>(0.05 / 100.0);
> auto start = std::chrono::steady_clock::now(); //START
> std::shared_ptr<SwapRateHelper> helper = std::make_shared<SwapRateHelper>(Handle<Quote>(s), period, swapcalendar,
> frequency, BusinessDayConvention::ModifiedFollowing,
> fDayCount, usdlibor);
> auto end = std::chrono::steady_clock::now(); //STOP
> std::cout << period << " liborhelper took : " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << " ms" << std::endl;
> liborhelpers.emplace_back(helper);
> }
> REQUIRE(liborhelpers.size()==22);
>
> }
>
> 1M sofrhelper took : 0 ms
> 2M sofrhelper took : 0 ms
> 3M sofrhelper took : 1 ms
> 4M sofrhelper took : 0 ms
> 5M sofrhelper took : 1 ms
> 6M sofrhelper took : 1 ms
> 9M sofrhelper took : 1 ms
> 1Y sofrhelper took : 2 ms
> 1Y6M sofrhelper took : 4 ms
> 2Y sofrhelper took : 5 ms
> 3Y sofrhelper took : 12 ms
> 4Y sofrhelper took : 15 ms
> 5Y sofrhelper took : 21 ms
> 7Y sofrhelper took : 34 ms
> 10Y sofrhelper took : 65 ms
> 12Y sofrhelper took : 85 ms
> 15Y sofrhelper took : 115 ms
> 20Y sofrhelper took : 211 ms
> 25Y sofrhelper took : 326 ms
> 30Y sofrhelper took : 451 ms
> 40Y sofrhelper took : 728 ms
> 50Y sofrhelper took : 1112 ms
> ====================================
> 1M liborhelper took : 0 ms
> 2M liborhelper took : 0 ms
> 3M liborhelper took : 0 ms
> 4M liborhelper took : 0 ms
> 5M liborhelper took : 0 ms
> 6M liborhelper took : 0 ms
> 9M liborhelper took : 0 ms
> 1Y liborhelper took : 0 ms
> 1Y6M liborhelper took : 0 ms
> 2Y liborhelper took : 0 ms
> 3Y liborhelper took : 0 ms
> 4Y liborhelper took : 0 ms
> 5Y liborhelper took : 0 ms
> 7Y liborhelper took : 0 ms
> 10Y liborhelper took : 0 ms
> 12Y liborhelper took : 0 ms
> 15Y liborhelper took : 0 ms
> 20Y liborhelper took : 1 ms
> 25Y liborhelper took : 1 ms
> 30Y liborhelper took : 1 ms
> 40Y liborhelper took : 1 ms
> 50Y liborhelper took : 2 ms
> ===============================================================================
> All tests passed (2 assertions in 1 test case)
>
>
> _______________________________________________
> QuantLib-users mailing list
> Qua...@li...
> https://lists.sourceforge.net/lists/listinfo/quantlib-users
|