Skip to content

Commit

Permalink
Fix initialization of sub-periods coupon, rename to multiple-resets c…
Browse files Browse the repository at this point in the history
…oupon (#2098)
  • Loading branch information
lballabio authored Oct 16, 2024
2 parents 065e2c7 + 2c01e48 commit ee7f9aa
Show file tree
Hide file tree
Showing 20 changed files with 1,200 additions and 872 deletions.
3 changes: 2 additions & 1 deletion QuantLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@
<ClInclude Include="ql\cashflows\inflationcoupon.hpp" />
<ClInclude Include="ql\cashflows\inflationcouponpricer.hpp" />
<ClInclude Include="ql\cashflows\lineartsrpricer.hpp" />
<ClInclude Include="ql\cashflows\multipleresetscoupon.hpp" />
<ClInclude Include="ql\cashflows\overnightindexedcoupon.hpp" />
<ClInclude Include="ql\cashflows\overnightindexedcouponpricer.hpp" />
<ClInclude Include="ql\cashflows\rangeaccrual.hpp" />
Expand Down Expand Up @@ -1918,12 +1919,12 @@
<ClCompile Include="ql\cashflows\inflationcoupon.cpp" />
<ClCompile Include="ql\cashflows\inflationcouponpricer.cpp" />
<ClCompile Include="ql\cashflows\lineartsrpricer.cpp" />
<ClCompile Include="ql\cashflows\multipleresetscoupon.cpp" />
<ClCompile Include="ql\cashflows\overnightindexedcoupon.cpp" />
<ClCompile Include="ql\cashflows\overnightindexedcouponpricer.cpp" />
<ClCompile Include="ql\cashflows\rangeaccrual.cpp" />
<ClCompile Include="ql\cashflows\replication.cpp" />
<ClCompile Include="ql\cashflows\simplecashflow.cpp" />
<ClCompile Include="ql\cashflows\subperiodcoupon.cpp" />
<ClCompile Include="ql\cashflows\timebasket.cpp" />
<ClCompile Include="ql\cashflows\yoyinflationcoupon.cpp" />
<ClCompile Include="ql\cashflows\zeroinflationcashflow.cpp" />
Expand Down
9 changes: 6 additions & 3 deletions QuantLib.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,9 @@
<ClInclude Include="ql\cashflows\inflationcouponpricer.hpp">
<Filter>cashflows</Filter>
</ClInclude>
<ClInclude Include="ql\cashflows\multipleresetscoupon.hpp">
<Filter>cashflows</Filter>
</ClInclude>
<ClInclude Include="ql\cashflows\overnightindexedcoupon.hpp">
<Filter>cashflows</Filter>
</ClInclude>
Expand Down Expand Up @@ -4499,6 +4502,9 @@
<ClCompile Include="ql\cashflows\inflationcouponpricer.cpp">
<Filter>cashflows</Filter>
</ClCompile>
<ClCompile Include="ql\cashflows\multipleresetscoupon.cpp">
<Filter>cashflows</Filter>
</ClCompile>
<ClCompile Include="ql\cashflows\overnightindexedcoupon.cpp">
<Filter>cashflows</Filter>
</ClCompile>
Expand All @@ -4514,9 +4520,6 @@
<ClCompile Include="ql\cashflows\simplecashflow.cpp">
<Filter>cashflows</Filter>
</ClCompile>
<ClCompile Include="ql\cashflows\subperiodcoupon.cpp">
<Filter>cashflows</Filter>
</ClCompile>
<ClCompile Include="ql\cashflows\timebasket.cpp">
<Filter>cashflows</Filter>
</ClCompile>
Expand Down
1 change: 1 addition & 0 deletions cmake/GenerateHeaders.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function(generate_dir_headers source_dir binary_dir)

list(FILTER children_hpp EXCLUDE REGEX "dividendvanillaoption.hpp")
list(FILTER children_hpp EXCLUDE REGEX "averageoiscouponpricer.hpp")
list(FILTER children_hpp EXCLUDE REGEX "subperiodcoupon.hpp")
list(FILTER children_hpp EXCLUDE REGEX "fdmultiperiodengine.hpp")
list(FILTER children_hpp EXCLUDE REGEX "fdvanillaengine.hpp")
list(FILTER children_hpp EXCLUDE REGEX "sampledcurve.hpp")
Expand Down
3 changes: 2 additions & 1 deletion ql/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ set(QL_SOURCES
cashflows/inflationcoupon.cpp
cashflows/inflationcouponpricer.cpp
cashflows/lineartsrpricer.cpp
cashflows/multipleresetscoupon.cpp
cashflows/overnightindexedcoupon.cpp
cashflows/overnightindexedcouponpricer.cpp
cashflows/rangeaccrual.cpp
cashflows/replication.cpp
cashflows/simplecashflow.cpp
cashflows/timebasket.cpp
cashflows/subperiodcoupon.cpp
cashflows/yoyinflationcoupon.cpp
cashflows/zeroinflationcashflow.cpp
currencies/africa.cpp
Expand Down Expand Up @@ -959,6 +959,7 @@ set(QL_HEADERS
cashflows/inflationcoupon.hpp
cashflows/inflationcouponpricer.hpp
cashflows/lineartsrpricer.hpp
cashflows/multipleresetscoupon.hpp
cashflows/overnightindexedcoupon.hpp
cashflows/overnightindexedcouponpricer.hpp
cashflows/rangeaccrual.hpp
Expand Down
5 changes: 3 additions & 2 deletions ql/cashflows/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ this_include_HEADERS = \
inflationcoupon.hpp \
inflationcouponpricer.hpp \
lineartsrpricer.hpp \
multipleresetscoupon.hpp \
overnightindexedcoupon.hpp \
overnightindexedcouponpricer.hpp \
rangeaccrual.hpp \
Expand Down Expand Up @@ -64,12 +65,12 @@ cpp_files = \
inflationcoupon.cpp \
inflationcouponpricer.cpp \
lineartsrpricer.cpp \
multipleresetscoupon.cpp \
overnightindexedcoupon.cpp \
overnightindexedcouponpricer.cpp \
rangeaccrual.cpp \
replication.cpp \
simplecashflow.cpp \
subperiodcoupon.cpp \
timebasket.cpp \
yoyinflationcoupon.cpp \
zeroinflationcashflow.cpp
Expand Down Expand Up @@ -100,7 +101,7 @@ all.hpp: Makefile.am
echo "/* This file is automatically generated; do not edit. */" > ${srcdir}/$@
echo "/* Add the files to be included into Makefile.am instead. */" >> ${srcdir}/$@
echo >> ${srcdir}/$@
for i in $(filter-out all.hpp, $(this_include_HEADERS)); do \
for i in $(filter-out all.hpp subperiodcoupon.hpp, $(this_include_HEADERS)); do \
echo "#include <${subdir}/$$i>" >> ${srcdir}/$@; \
done
echo >> ${srcdir}/$@
Expand Down
2 changes: 1 addition & 1 deletion ql/cashflows/all.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
#include <ql/cashflows/inflationcoupon.hpp>
#include <ql/cashflows/inflationcouponpricer.hpp>
#include <ql/cashflows/lineartsrpricer.hpp>
#include <ql/cashflows/multipleresetscoupon.hpp>
#include <ql/cashflows/overnightindexedcoupon.hpp>
#include <ql/cashflows/overnightindexedcouponpricer.hpp>
#include <ql/cashflows/rangeaccrual.hpp>
#include <ql/cashflows/rateaveraging.hpp>
#include <ql/cashflows/replication.hpp>
#include <ql/cashflows/simplecashflow.hpp>
#include <ql/cashflows/subperiodcoupon.hpp>
#include <ql/cashflows/timebasket.hpp>
#include <ql/cashflows/yoyinflationcoupon.hpp>
#include <ql/cashflows/zeroinflationcashflow.hpp>
Expand Down
17 changes: 8 additions & 9 deletions ql/cashflows/couponpricer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <ql/cashflows/digitalcoupon.hpp>
#include <ql/cashflows/digitaliborcoupon.hpp>
#include <ql/cashflows/rangeaccrual.hpp>
#include <ql/cashflows/subperiodcoupon.hpp>
#include <ql/cashflows/multipleresetscoupon.hpp>
#include <ql/experimental/coupons/cmsspreadcoupon.hpp> /* internal */
#include <ql/experimental/coupons/digitalcmsspreadcoupon.hpp> /* internal */
#include <ql/pricingengines/blackformula.hpp>
Expand Down Expand Up @@ -253,7 +253,7 @@ namespace QuantLib {
public Visitor<DigitalCmsCoupon>,
public Visitor<DigitalCmsSpreadCoupon>,
public Visitor<RangeAccrualFloatersCoupon>,
public Visitor<SubPeriodsCoupon> {
public Visitor<MultipleResetsCoupon> {
private:
ext::shared_ptr<FloatingRateCouponPricer> pricer_;
public:
Expand All @@ -274,7 +274,7 @@ namespace QuantLib {
void visit(DigitalCmsCoupon& c) override;
void visit(DigitalCmsSpreadCoupon& c) override;
void visit(RangeAccrualFloatersCoupon& c) override;
void visit(SubPeriodsCoupon& c) override;
void visit(MultipleResetsCoupon& c) override;
};

void PricerSetter::visit(CashFlow&) {
Expand Down Expand Up @@ -386,12 +386,11 @@ namespace QuantLib {
c.setPricer(rangeAccrualPricer);
}

void PricerSetter::visit(SubPeriodsCoupon& c) {
const ext::shared_ptr<SubPeriodsPricer> subPeriodsPricer =
ext::dynamic_pointer_cast<SubPeriodsPricer>(pricer_);
QL_REQUIRE(subPeriodsPricer,
"pricer not compatible with sub-period coupon");
c.setPricer(subPeriodsPricer);
void PricerSetter::visit(MultipleResetsCoupon& c) {
const ext::shared_ptr<MultipleResetsPricer> pricer =
ext::dynamic_pointer_cast<MultipleResetsPricer>(pricer_);
QL_REQUIRE(pricer, "pricer not compatible with multiple-resets coupon");
c.setPricer(pricer);
}

void setCouponPricersFirstMatching(const Leg& leg,
Expand Down
Loading

0 comments on commit ee7f9aa

Please sign in to comment.