Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
subperiodsswap.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 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 subperiodsswap.hpp
20 \brief Single currency sub periods swap instrument
21
22 \ingroup instruments
23*/
24
25#ifndef quantext_sub_periods_swap_hpp
26#define quantext_sub_periods_swap_hpp
27
28#include <ql/indexes/iborindex.hpp>
29#include <ql/instruments/swap.hpp>
30
32
33namespace QuantExt {
34using namespace QuantLib;
35//! Single currency sub periods swap
36/*! \ingroup instruments
37 */
38class SubPeriodsSwap : public Swap {
39public:
40 //! \name Constructors
41 //@{
42 //! Constructor with conventions deduced from the index
43 SubPeriodsSwap(const Date& effectiveDate, Real nominal, const Period& swapTenor, bool isPayer,
44 const Period& fixedTenor, Rate fixedRate, const Calendar& fixedCalendar,
45 const DayCounter& fixedDayCount, BusinessDayConvention fixedConvention, const Period& floatPayTenor,
46 const QuantLib::ext::shared_ptr<IborIndex>& iborIndex, const DayCounter& floatingDayCount,
47 DateGeneration::Rule rule = DateGeneration::Backward,
49 //@}
50 //! \name Inspectors
51 //@{
52 Real nominal() const;
53 bool isPayer() const;
54
55 const Schedule& fixedSchedule() const;
56 Rate fixedRate() const;
57 const Leg& fixedLeg() const;
58
59 const Schedule& floatSchedule() const;
60 const QuantLib::ext::shared_ptr<IborIndex>& floatIndex() const;
62 const Period& floatPayTenor() const;
63 const Leg& floatLeg() const;
64
65 //@}
66 //! \name Results
67 //@{
68 Real fairRate() const;
69 Real fixedLegBPS() const;
70 Real fixedLegNPV() const;
71 Real floatLegBPS() const;
72 Real floatLegNPV() const;
73 //@}
74
75private:
78
81 DayCounter fixedDayCount_;
82
84 QuantLib::ext::shared_ptr<IborIndex> floatIndex_;
85 DayCounter floatDayCount_;
88};
89
90// Inline definitions
91inline Real SubPeriodsSwap::nominal() const { return nominal_; }
92
93inline bool SubPeriodsSwap::isPayer() const { return isPayer_; }
94
95inline const Schedule& SubPeriodsSwap::fixedSchedule() const { return fixedSchedule_; }
96
97inline Rate SubPeriodsSwap::fixedRate() const { return fixedRate_; }
98
99inline const Leg& SubPeriodsSwap::fixedLeg() const { return legs_[0]; }
100
101inline Rate SubPeriodsSwap::fixedLegBPS() const { return legBPS(0); }
102
103inline Rate SubPeriodsSwap::fixedLegNPV() const { return legNPV(0); }
104
105inline const Schedule& SubPeriodsSwap::floatSchedule() const { return floatSchedule_; }
106
107inline const QuantLib::ext::shared_ptr<IborIndex>& SubPeriodsSwap::floatIndex() const { return floatIndex_; }
108
110
111inline const Period& SubPeriodsSwap::floatPayTenor() const { return floatPayTenor_; }
112
113inline const Leg& SubPeriodsSwap::floatLeg() const { return legs_[1]; }
114
115inline Rate SubPeriodsSwap::floatLegBPS() const { return legBPS(1); }
116
117inline Rate SubPeriodsSwap::floatLegNPV() const { return legNPV(1); }
118
120public:
121 MakeSubPeriodsSwap(const Period& swapTenor, const QuantLib::ext::shared_ptr<IborIndex>& index,
122 Rate fixedRate, const Period& floatPayTenor, const Period& forwardStart = 0 * Days);
123
124 operator SubPeriodsSwap() const;
125 operator QuantLib::ext::shared_ptr<SubPeriodsSwap>() const;
126
130 MakeSubPeriodsSwap& withSettlementDays(Natural settlementDays);
131
132 MakeSubPeriodsSwap& withFixedLegTenor(const Period& t);
133 MakeSubPeriodsSwap& withFixedLegCalendar(const Calendar& cal);
134 MakeSubPeriodsSwap& withFixedLegConvention(BusinessDayConvention bdc);
135 MakeSubPeriodsSwap& withFixedLegRule(DateGeneration::Rule r);
136 MakeSubPeriodsSwap& withFixedLegDayCount(const DayCounter& dc);
137
139
140 MakeSubPeriodsSwap& withDiscountingTermStructure(const Handle<YieldTermStructure>& discountCurve);
141 MakeSubPeriodsSwap& withPricingEngine(const QuantLib::ext::shared_ptr<PricingEngine>& engine);
142
143private:
145 QuantLib::ext::shared_ptr<IborIndex> index_;
149
154
157 BusinessDayConvention fixedConvention_;
158 DateGeneration::Rule fixedRule_;
160
162
163 QuantLib::ext::shared_ptr<PricingEngine> engine_;
164};
165} // namespace QuantExt
166
167#endif
MakeSubPeriodsSwap & withFixedLegTenor(const Period &t)
MakeSubPeriodsSwap & withNominal(Real n)
MakeSubPeriodsSwap & withSettlementDays(Natural settlementDays)
BusinessDayConvention fixedConvention_
QuantExt::SubPeriodsCoupon1::Type subCouponsType_
MakeSubPeriodsSwap & withEffectiveDate(const Date &)
QuantLib::ext::shared_ptr< IborIndex > index_
MakeSubPeriodsSwap & withFixedLegConvention(BusinessDayConvention bdc)
MakeSubPeriodsSwap & withFixedLegRule(DateGeneration::Rule r)
MakeSubPeriodsSwap & withIsPayer(bool p)
QuantLib::ext::shared_ptr< PricingEngine > engine_
DateGeneration::Rule fixedRule_
MakeSubPeriodsSwap & withSubCouponsType(const QuantExt::SubPeriodsCoupon1::Type &st)
MakeSubPeriodsSwap & withPricingEngine(const QuantLib::ext::shared_ptr< PricingEngine > &engine)
MakeSubPeriodsSwap & withFixedLegDayCount(const DayCounter &dc)
MakeSubPeriodsSwap & withDiscountingTermStructure(const Handle< YieldTermStructure > &discountCurve)
MakeSubPeriodsSwap & withFixedLegCalendar(const Calendar &cal)
Single currency sub periods swap.
QuantLib::ext::shared_ptr< IborIndex > floatIndex_
const Leg & floatLeg() const
const Schedule & fixedSchedule() const
const Schedule & floatSchedule() const
const Period & floatPayTenor() const
QuantExt::SubPeriodsCoupon1::Type type() const
const QuantLib::ext::shared_ptr< IborIndex > & floatIndex() const
const Leg & fixedLeg() const
QuantExt::SubPeriodsCoupon1::Type type_
Coupon with a number of sub-periods.