Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
balanceguaranteedswap.hpp
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
19/*! \file balanceguaranteedswap.hpp
20 \brief Balance Guaranteed Swap instrument
21*/
22
23#pragma once
24
25#include <ql/cashflow.hpp>
26#include <ql/instruments/swap.hpp>
27#include <ql/instruments/vanillaswap.hpp>
28#include <ql/position.hpp>
29#include <ql/pricingengine.hpp>
30
31namespace QuantExt {
32using QuantLib::BusinessDayConvention;
33using QuantLib::Date;
34using QuantLib::DayCounter;
35using QuantLib::IborIndex;
36using QuantLib::Leg;
37using QuantLib::Real;
38using QuantLib::Schedule;
39using QuantLib::Size;
40using QuantLib::Time;
41using QuantLib::VanillaSwap;
42
43//! Balance Guaranteed Swap
44/*! Notice the comment in the NumericLgmBgsFlexiSwapEngine concerning the start of the prepayments, this means that the
45 tranche notionals for periods with a start date in the past or on the evaluation date should include actual (known)
46 prepayments. For future periods the notionals should correspond to a zero CPR assumption on the other hand.
47*/
48
49class BalanceGuaranteedSwap : public QuantLib::Swap {
50public:
51 class arguments;
52 class results;
53 class engine;
54 BalanceGuaranteedSwap(const VanillaSwap::Type type, const std::vector<std::vector<Real>>& trancheNominals,
55 const Schedule& nominalSchedule, const Size referencedTranche, const Schedule& fixedSchedule,
56 const std::vector<Real>& fixedRate, const DayCounter& fixedDayCount,
57 const Schedule& floatingSchedule, const QuantLib::ext::shared_ptr<IborIndex>& iborIndex,
58 const std::vector<Real>& gearing, const std::vector<Real>& spread,
59 const std::vector<Real>& cappedRate, const std::vector<Real>& flooredRate,
60 const DayCounter& floatingDayCount,
61 boost::optional<BusinessDayConvention> paymentConvention = boost::none);
62
63 //! \name Inspectors
64 //@{
65 VanillaSwap::Type type() const { return type_; }
66 const std::vector<std::vector<Real>>& trancheNominal() const { return trancheNominals_; }
67 const Schedule& nominalSchedule() const { return nominalSchedule_; }
68 const Size referencedTranche() const { return referencedTranche_; }
69
70 const Schedule& fixedSchedule() const { return fixedSchedule_; }
71 const std::vector<Real>& fixedRate() const { return fixedRate_; }
72 const DayCounter& fixedDayCount() const { return fixedDayCount_; }
73
74 const Schedule& floatingSchedule() const { return floatingSchedule_; }
75 const QuantLib::ext::shared_ptr<IborIndex>& iborIndex() const { return iborIndex_; }
76 const std::vector<Real>& gearing() const { return gearing_; }
77 const std::vector<Real>& spread() const { return spread_; }
78 const std::vector<Real>& cappedRate() const { return cappedRate_; }
79 const std::vector<Real>& flooredRate() const { return flooredRate_; }
80 const DayCounter& floatingDayCount() const { return floatingDayCount_; }
81
82 BusinessDayConvention paymentConvention() const { return paymentConvention_; }
83
84 const Leg& fixedLeg() const { return legs_[0]; }
85 const Leg& floatingLeg() const { return legs_[1]; }
86 //@}
87
88 Real trancheNominal(const Size trancheIndex, const Date& d);
89
90private:
91 const VanillaSwap::Type type_;
92 const std::vector<std::vector<Real>> trancheNominals_;
93 const Schedule nominalSchedule_;
95 const Schedule fixedSchedule_;
96 const std::vector<Real> fixedRate_;
97 const DayCounter fixedDayCount_;
98 const Schedule floatingSchedule_;
99 const QuantLib::ext::shared_ptr<IborIndex> iborIndex_;
100 const std::vector<Real> gearing_;
101 const std::vector<Real> spread_;
102 const std::vector<Real> cappedRate_;
103 const std::vector<Real> flooredRate_;
104 const DayCounter floatingDayCount_;
105 BusinessDayConvention paymentConvention_;
106
108 void setupExpired() const override;
109 void fetchResults(const QuantLib::PricingEngine::results*) const override;
110};
111
112//! %Arguments for Balance Guaranteed Swap
114public:
115 arguments() : type(VanillaSwap::Receiver) {}
116 VanillaSwap::Type type;
117 std::vector<std::vector<Real>> trancheNominals;
118 std::vector<Date> trancheNominalDates;
119 QuantLib::Frequency trancheNominalFrequency;
121
122 std::vector<Date> fixedResetDates;
123 std::vector<Date> fixedPayDates;
124 std::vector<Time> floatingAccrualTimes;
125 std::vector<Date> floatingResetDates;
126 std::vector<Date> floatingFixingDates;
127 std::vector<Date> floatingPayDates;
128
129 std::vector<Real> fixedCoupons;
130 std::vector<Real> fixedRate;
131 std::vector<Real> floatingGearings;
132 std::vector<Real> floatingSpreads;
133 std::vector<Real> cappedRate;
134 std::vector<Real> flooredRate;
135 std::vector<Real> floatingCoupons;
136
137 QuantLib::ext::shared_ptr<IborIndex> iborIndex;
138
140
141 void validate() const override;
142};
143
144//! %Results for Balance Guaranteed Swap
146public:
147 void reset() override;
148};
149
150//! Base class for Balance Guaranteed Swap engines
152 : public QuantLib::GenericEngine<BalanceGuaranteedSwap::arguments, BalanceGuaranteedSwap::results> {};
153
154} // namespace QuantExt
Arguments for Balance Guaranteed Swap
std::vector< std::vector< Real > > trancheNominals
QuantLib::ext::shared_ptr< IborIndex > iborIndex
Base class for Balance Guaranteed Swap engines.
Results for Balance Guaranteed Swap
void fetchResults(const QuantLib::PricingEngine::results *) const override
const std::vector< Real > fixedRate_
const std::vector< Real > & flooredRate() const
const DayCounter & fixedDayCount() const
const std::vector< Real > & gearing() const
BusinessDayConvention paymentConvention() const
const Schedule & fixedSchedule() const
const std::vector< std::vector< Real > > trancheNominals_
const std::vector< Real > cappedRate_
const Schedule & floatingSchedule() const
const QuantLib::ext::shared_ptr< IborIndex > & iborIndex() const
const std::vector< Real > & fixedRate() const
const std::vector< Real > flooredRate_
const std::vector< Real > & spread() const
const DayCounter & floatingDayCount() const
void setupArguments(QuantLib::PricingEngine::arguments *) const override
const std::vector< Real > & cappedRate() const
const Schedule & nominalSchedule() const
const QuantLib::ext::shared_ptr< IborIndex > iborIndex_
const std::vector< std::vector< Real > > & trancheNominal() const