21#include <ql/cashflows/overnightindexedcoupon.hpp>
22#include <ql/cashflows/simplecashflow.hpp>
23#include <ql/time/daycounters/business252.hpp>
24#include <ql/time/schedule.hpp>
35 const QuantLib::ext::shared_ptr<BRLCdi>& overnightIndex, Spread spread,
bool telescopicValueDates)
36 : OvernightIndexedSwap(type, nominal,
37 Schedule({startDate, endDate}, NullCalendar(),
38 QuantLib::Unadjusted, QuantLib::Unadjusted, 100 * Years),
39 fixedRate, overnightIndex->dayCounter(), overnightIndex, spread, 0, ModifiedFollowing,
40 overnightIndex->fixingCalendar(), telescopicValueDates),
41 startDate_(startDate), endDate_(endDate), index_(overnightIndex) {
47 Time dcf = index_->dayCounter().yearFraction(startDate_, endDate_);
48 Real fixedLegPayment = nominal * (
pow(1.0 + fixedRate, dcf) - 1.0);
49 Date paymentDate = legs_[0].back()->date();
50 QuantLib::ext::shared_ptr<CashFlow> fixedCashflow = QuantLib::ext::make_shared<SimpleCashFlow>(fixedLegPayment, paymentDate);
52 legs_[0].push_back(fixedCashflow);
53 registerWith(fixedCashflow);
56 QL_REQUIRE(legs_[1].size() == 1,
"BRLCdiSwap expected exactly one overnight coupon");
57 QuantLib::ext::shared_ptr<QuantLib::OvernightIndexedCoupon> coupon =
58 QuantLib::ext::dynamic_pointer_cast<QuantLib::OvernightIndexedCoupon>(legs_[1][0]);
59 QL_REQUIRE(coupon,
"BRLCdiSwap: expected QuantLib::OvernightIndexedCoupon");
60 coupon->setPricer(QuantLib::ext::make_shared<BRLCdiCouponPricer>());
67 const Spread basisPoint = 1.0e-4;
68 if (!close(endDiscounts_[0], 0.0) && endDiscounts_[0] != Null<DiscountFactor>()) {
69 DiscountFactor df = payer_[0] * endDiscounts_[0];
71 legBPS_[0] = df * nominal() * (
pow(1.0 + fixedRate() + basisPoint, dcf) -
pow(1.0 + fixedRate(), dcf));
75 QL_FAIL(
"BRLCdiSwap cannot calculate fixed leg BPS because end discount is not populated");
82 if (!close(endDiscounts_[0], 0.0) && endDiscounts_[0] != Null<DiscountFactor>()) {
83 DiscountFactor df = -payer_[0] * endDiscounts_[0];
85 return pow(overnightLegNPV() / (nominal() * df) + 1.0, 1.0 / dcf) - 1.0;
88 QL_FAIL(
"BRLCdiSwap cannot calculate fair rate because end discount is not populated");
Coupon pricer for a BRL CDI coupon.
QuantLib::Real fairRate() const
QuantLib::ext::shared_ptr< QuantLib::OvernightIndex > index_
QuantLib does not implement the method OvernightIndexedSwap::overnightIndex() so I need this.
QuantLib::Real fixedLegBPS() const
QuantLib::Date startDate_
BRLCdiSwap(Type type, QuantLib::Real nominal, const QuantLib::Date &startDate, const QuantLib::Date &endDate, QuantLib::Rate fixedRate, const QuantLib::ext::shared_ptr< BRLCdi > &overnightIndex, QuantLib::Spread spread=0.0, bool telescopicValueDates=false)
Utility functions for setting coupon pricers on legs.
CompiledFormula pow(CompiledFormula x, const CompiledFormula &y)