26#include <ql/cashflows/overnightindexedcoupon.hpp>
32class PricerSetter :
public AcyclicVisitor,
33 public Visitor<CashFlow>,
34 public Visitor<Coupon>,
35 public Visitor<QuantLib::OvernightIndexedCoupon>,
36 public Visitor<QuantExt::OvernightIndexedCoupon>,
37 public Visitor<CappedFlooredOvernightIndexedCoupon>,
38 public Visitor<AverageONIndexedCoupon>,
39 public Visitor<QuantExt::SubPeriodsCoupon1>,
40 public Visitor<FormulaBasedCoupon> {
42 const QuantLib::ext::shared_ptr<FloatingRateCouponPricer>
pricer_;
45 PricerSetter(
const QuantLib::ext::shared_ptr<FloatingRateCouponPricer>& pricer) :
pricer_(pricer) {}
47 void visit(CashFlow& c)
override;
48 void visit(
Coupon& c)
override;
49 void visit(QuantLib::OvernightIndexedCoupon& c)
override;
51 void visit(CappedFlooredOvernightIndexedCoupon& c)
override;
52 void visit(AverageONIndexedCoupon& c)
override;
54 void visit(FormulaBasedCoupon& c)
override;
57void PricerSetter::visit(CashFlow&) {
61void PricerSetter::visit(
Coupon&) {
65void PricerSetter::visit(QuantLib::OvernightIndexedCoupon& c) {
67 QuantLib::ext::shared_ptr<BRLCdi> brlCdiIndex = QuantLib::ext::dynamic_pointer_cast<BRLCdi>(c.index());
69 const QuantLib::ext::shared_ptr<BRLCdiCouponPricer> brlCdiCouponPricer =
70 QuantLib::ext::dynamic_pointer_cast<BRLCdiCouponPricer>(
pricer_);
71 QL_REQUIRE(brlCdiCouponPricer,
"Pricer not compatible with BRL CDI coupon");
72 c.setPricer(brlCdiCouponPricer);
80 QuantLib::ext::shared_ptr<BRLCdi> brlCdiIndex = QuantLib::ext::dynamic_pointer_cast<BRLCdi>(c.index());
82 const QuantLib::ext::shared_ptr<BRLCdiCouponPricer> brlCdiCouponPricer =
83 QuantLib::ext::dynamic_pointer_cast<BRLCdiCouponPricer>(
pricer_);
84 QL_REQUIRE(brlCdiCouponPricer,
"Pricer not compatible with BRL CDI coupon");
85 c.setPricer(brlCdiCouponPricer);
91void PricerSetter::visit(CappedFlooredOvernightIndexedCoupon& c) {
92 const QuantLib::ext::shared_ptr<CappedFlooredOvernightIndexedCouponPricer> p =
93 QuantLib::ext::dynamic_pointer_cast<CappedFlooredOvernightIndexedCouponPricer>(
pricer_);
98 c.underlying()->accept(*
this);
101void PricerSetter::visit(AverageONIndexedCoupon& c) {
102 const QuantLib::ext::shared_ptr<AverageONIndexedCouponPricer> averageONIndexedCouponPricer =
103 QuantLib::ext::dynamic_pointer_cast<AverageONIndexedCouponPricer>(
pricer_);
104 QL_REQUIRE(averageONIndexedCouponPricer,
"Pricer not compatible with Average ON Indexed coupon");
105 c.setPricer(averageONIndexedCouponPricer);
109 const QuantLib::ext::shared_ptr<QuantExt::SubPeriodsCouponPricer1> subPeriodsCouponPricer =
110 QuantLib::ext::dynamic_pointer_cast<QuantExt::SubPeriodsCouponPricer1>(
pricer_);
111 QL_REQUIRE(subPeriodsCouponPricer,
"Pricer not compatible with sub-periods coupon");
112 c.setPricer(subPeriodsCouponPricer);
115void PricerSetter::visit(FormulaBasedCoupon& c) {
116 auto p = QuantLib::ext::dynamic_pointer_cast<FormulaBasedCouponPricer>(
pricer_);
117 QL_REQUIRE(p,
"Pricer not compatible with Formula Based coupon");
122void setCouponPricer(
const Leg& leg,
const QuantLib::ext::shared_ptr<FloatingRateCouponPricer>& pricer) {
123 PricerSetter setter(pricer);
124 for (Size i = 0; i < leg.size(); ++i) {
125 leg[i]->accept(setter);
129void setCouponPricers(
const Leg& leg,
const std::vector<QuantLib::ext::shared_ptr<FloatingRateCouponPricer> >& pricers) {
131 Size nCashFlows = leg.size();
132 QL_REQUIRE(nCashFlows > 0,
"No cashflows");
134 Size nPricers = pricers.size();
135 QL_REQUIRE(nCashFlows >= nPricers,
136 "Mismatch between leg size (" << nCashFlows <<
") and number of pricers (" << nPricers <<
")");
138 for (Size i = 0; i < nCashFlows; ++i) {
139 PricerSetter setter(i < nPricers ? pricers[i] : pricers[nPricers - 1]);
140 leg[i]->accept(setter);
Pricer for average overnight indexed coupons.
Coupon pricer for a BRL CDI coupon.
const QuantLib::ext::shared_ptr< FloatingRateCouponPricer > pricer_
Utility functions for setting coupon pricers on legs.
void setCouponPricers(const Leg &leg, const std::vector< QuantLib::ext::shared_ptr< FloatingRateCouponPricer > > &pricers)
Set Coupon Pricers.
void setCouponPricer(const Leg &leg, const QuantLib::ext::shared_ptr< FloatingRateCouponPricer > &pricer)
Set Coupon Pricer.
coupon paying the compounded daily overnight rate, copy of QL class, added includeSpread flag
Pricer for sub-period coupons.