Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
subperiodscouponpricer.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 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
21namespace QuantExt {
22
24
25 coupon_ = dynamic_cast<const SubPeriodsCoupon1*>(&coupon);
26 QL_REQUIRE(coupon_, "SubPeriodsCoupon required");
27
28 index_ = QuantLib::ext::dynamic_pointer_cast<InterestRateIndex>(coupon_->index());
29 QL_REQUIRE(index_, "InterestRateIndex required");
30
31 gearing_ = coupon_->gearing();
33 accrualPeriod_ = coupon_->accrualPeriod();
34 type_ = coupon_->type();
36}
37
39
40 std::vector<Time> accrualFractions = coupon_->accrualFractions();
41 Size numPeriods = accrualFractions.size();
42 Spread incSpread = includeSpread_ ? spread_ : 0.0;
43 Spread excSpread = includeSpread_ ? 0.0 : spread_;
44 Real accumulatedRate;
45 Rate rate;
46
47 std::vector<Rate> fixings = coupon_->indexFixings();
49 accumulatedRate = 0.0;
50 for (Size i = 0; i < numPeriods; ++i) {
51 accumulatedRate += (fixings[i] + incSpread) * accrualFractions[i];
52 }
53 rate = gearing_ * accumulatedRate / accrualPeriod_ + excSpread;
55 accumulatedRate = 1.0;
56 for (Size i = 0; i < numPeriods; ++i) {
57 accumulatedRate *= (1.0 + (fixings[i] + incSpread) * accrualFractions[i]);
58 }
59 rate = gearing_ * (accumulatedRate - 1.0) / accrualPeriod_ + excSpread;
60 } else {
61 QL_FAIL("Invalid sub-period coupon type");
62 }
63
64 return rate;
65}
66} // namespace QuantExt
bool includeSpread() const
whether to include/exclude spread in compounding/averaging
const std::vector< Time > & accrualFractions() const
accrual periods for the sub-periods
const std::vector< Rate > & indexFixings() const
fixings for the sub-periods
Type type() const
whether sub-period fixings are averaged or compounded
Spread spread() const
Need to be able to change spread to solve for fair spread.
void initialize(const FloatingRateCoupon &coupon) override
QuantLib::ext::shared_ptr< InterestRateIndex > index_
Pricer for sub-period coupons.