Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
brlcdicouponpricer.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
20
21using namespace QuantLib;
22using std::pow;
23using std::vector;
24
25namespace QuantExt {
26
27// The code here is very similar to QuantLib::OvernightIndexedCouponPricer. That class is in
28// an anonymous namespace so could not extend it. The altered code is to take account of the fact
29// that the BRL CDI coupon accrues as (1 + DI) ^ (1 / 252)
31
32 const vector<Date>& fixingDates = couponQl_ ? couponQl_->fixingDates() : couponQle_->fixingDates();
33 const vector<Time>& dt = couponQl_ ? couponQl_->dt() : couponQle_->dt();
34 Size n = dt.size();
35 Size i = 0;
36 Real compoundFactor = 1.0;
37 Date today = Settings::instance().evaluationDate();
38
39 // Already fixed part of the coupon
40 while (i < n && fixingDates[i] < today) {
41 Rate pastFixing = IndexManager::instance().getHistory(index_->name())[fixingDates[i]];
42 QL_REQUIRE(pastFixing != Null<Real>(), "Missing " << index_->name() << " fixing for " << fixingDates[i]);
43 compoundFactor *= pow(1.0 + pastFixing, dt[i]);
44 ++i;
45 }
46
47 // Today is a border case. If there is a fixing use it. If not, it will be projected in the next block.
48 if (i < n && fixingDates[i] == today) {
49 try {
50 Rate pastFixing = IndexManager::instance().getHistory(index_->name())[fixingDates[i]];
51 if (pastFixing != Null<Real>()) {
52 compoundFactor *= pow(1.0 + pastFixing, dt[i]);
53 ++i;
54 }
55 } catch (Error&) {
56 }
57 }
58
59 // Use telescopic property for piece of coupon in the future
60 // \Pi_{i=0}^{n-1} \left( 1 + DI(t, t_{i}, t_{i+1}) \right) ^ \delta = \frac{P(t, t_0)}{P(t, t_n)}
61 if (i < n) {
62 Handle<YieldTermStructure> curve = index_->forwardingTermStructure();
63 QL_REQUIRE(!curve.empty(), "BRLCdiCouponPricer needs the index to have a forwarding term structure");
64
65 const vector<Date>& dates = couponQl_ ? couponQl_->valueDates() : couponQle_->valueDates();
66 DiscountFactor startDiscount = curve->discount(dates[i]);
67 DiscountFactor endDiscount = curve->discount(dates[n]);
68
69 compoundFactor *= startDiscount / endDiscount;
70 }
71
72 Rate rate = (compoundFactor - 1.0) / (couponQl_ ? couponQl_->accrualPeriod() : couponQle_->accrualPeriod());
73 return (couponQl_ ? couponQl_->gearing() : couponQle_->gearing()) * rate +
74 (couponQl_ ? couponQl_->spread() : couponQle_->spread());
75}
76
78 // Ensure that we have an overnight coupon and that the index is BRL DI
79 couponQl_ = dynamic_cast<const QuantLib::OvernightIndexedCoupon*>(&coupon);
80 couponQle_ = dynamic_cast<const QuantExt::OvernightIndexedCoupon*>(&coupon);
81 QL_REQUIRE(couponQl_ || couponQle_, "BRLCdiCouponPricer expects an OvernightIndexedCoupon");
82
83 QuantLib::ext::shared_ptr<InterestRateIndex> index = couponQl_ ? couponQl_->index() : couponQle_->index();
84 index_ = QuantLib::ext::dynamic_pointer_cast<BRLCdi>(index);
85 QL_REQUIRE(index_, "BRLCdiCouponPricer expects the coupon's index to be BRLCdi");
86}
87
88Real BRLCdiCouponPricer::swapletPrice() const { QL_FAIL("swapletPrice not implemented for BRLCdiCouponPricer"); }
89
90Real BRLCdiCouponPricer::capletPrice(Rate effectiveCap) const {
91 QL_FAIL("capletPrice not implemented for BRLCdiCouponPricer");
92}
93
94Real BRLCdiCouponPricer::capletRate(Rate effectiveCap) const {
95 QL_FAIL("capletRate not implemented for BRLCdiCouponPricer");
96}
97
98Real BRLCdiCouponPricer::floorletPrice(Rate effectiveFloor) const {
99 QL_FAIL("floorletPrice not implemented for BRLCdiCouponPricer");
100}
101
102Real BRLCdiCouponPricer::floorletRate(Rate effectiveFloor) const {
103 QL_FAIL("floorletRate not implemented for BRLCdiCouponPricer");
104}
105
106} // namespace QuantExt
Coupon pricer for a BRL CDI coupon.
QuantLib::ext::shared_ptr< BRLCdi > index_
The index underlying the coupon to be priced.
virtual QuantLib::Real capletPrice(QuantLib::Rate effectiveCap) const override
const QuantExt::OvernightIndexedCoupon * couponQle_
virtual QuantLib::Real floorletPrice(QuantLib::Rate effectiveFloor) const override
virtual QuantLib::Rate floorletRate(QuantLib::Rate effectiveFloor) const override
virtual QuantLib::Rate capletRate(QuantLib::Rate effectiveCap) const override
const QuantLib::OvernightIndexedCoupon * couponQl_
virtual QuantLib::Rate swapletRate() const override
virtual void initialize(const QuantLib::FloatingRateCoupon &coupon) override
virtual QuantLib::Real swapletPrice() const override
const std::vector< Date > & valueDates() const
value dates for the rates to be compounded
const std::vector< Time > & dt() const
accrual (compounding) periods
const std::vector< Date > & fixingDates() const
fixing dates for the rates to be compounded
CompiledFormula pow(CompiledFormula x, const CompiledFormula &y)