/src/quantlib/ql/pricingengines/swaption/gaussian1dfloatfloatswaptionengine.hpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2013, 2015 Peter Caspers |
5 | | |
6 | | This file is part of QuantLib, a free-software/open-source library |
7 | | for financial quantitative analysts and developers - http://quantlib.org/ |
8 | | |
9 | | QuantLib is free software: you can redistribute it and/or modify it |
10 | | under the terms of the QuantLib liense. You should have received a |
11 | | copy of the license along with this program; if not, please email |
12 | | <quantlib-dev@lists.sf.net>. The license is also available online at |
13 | | <https://www.quantlib.org/license.shtml>. |
14 | | |
15 | | This program is distributed in the hope that it will be useful, but WITHOUT |
16 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
17 | | FOR A PARTICULAR PURPOSE. See the license for more details. |
18 | | */ |
19 | | |
20 | | /*! \file gaussian1dfloatfloatswaptionengine.hpp |
21 | | \brief float float swaption engine for one factor interest rate models |
22 | | */ |
23 | | |
24 | | #ifndef quantlib_pricers_gaussian1d_floatfloatswaption_hpp |
25 | | #define quantlib_pricers_gaussian1d_floatfloatswaption_hpp |
26 | | |
27 | | #include <ql/instruments/floatfloatswaption.hpp> |
28 | | #include <ql/models/shortrate/onefactormodels/gaussian1dmodel.hpp> |
29 | | #include <ql/rebatedexercise.hpp> |
30 | | |
31 | | #include <ql/pricingengines/genericmodelengine.hpp> |
32 | | |
33 | | namespace QuantLib { |
34 | | |
35 | | //! One factor model float float swaption engine |
36 | | /*! \ingroup swaptionengines |
37 | | |
38 | | All float coupons with fixing date greater or |
39 | | equal the respective option expiry are considered |
40 | | part of the exercise into right. Note that this |
41 | | is different from the usual accrual start date |
42 | | greater or equal exercise date if the fixing lag |
43 | | is strictly greater than the exercise lag (which |
44 | | should be a rare case). For the redepmtion flows |
45 | | the criterion is that the associated start date |
46 | | of the redemption flow (i.e. the start date of |
47 | | the regular coupon period with same payment date |
48 | | as the redemption flow) is greater or equal the |
49 | | exercise date. |
50 | | |
51 | | The addtional result underlyingValue is the npv |
52 | | of the underlying (as seen from "today") including |
53 | | all fixings greater (or greater equal depending |
54 | | on includeTodaysExercise) today. |
55 | | */ |
56 | | |
57 | | class Gaussian1dFloatFloatSwaptionEngine |
58 | | : public BasketGeneratingEngine, |
59 | | public GenericModelEngine<Gaussian1dModel, |
60 | | FloatFloatSwaption::arguments, |
61 | | FloatFloatSwaption::results> { |
62 | | public: |
63 | | enum Probabilities { |
64 | | None, |
65 | | Naive, |
66 | | Digital |
67 | | }; |
68 | | |
69 | | Gaussian1dFloatFloatSwaptionEngine( |
70 | | const ext::shared_ptr<Gaussian1dModel> &model, |
71 | | const int integrationPoints = 64, const Real stddevs = 7.0, |
72 | | const bool extrapolatePayoff = true, |
73 | | const bool flatPayoffExtrapolation = false, |
74 | | const Handle<Quote> &oas = |
75 | | Handle<Quote>(), // continously compounded w.r.t. yts daycounter |
76 | | const Handle<YieldTermStructure> &discountCurve = |
77 | | Handle<YieldTermStructure>(), |
78 | | const bool includeTodaysExercise = false, |
79 | | const Probabilities probabilities = None) |
80 | | : BasketGeneratingEngine(model, oas, discountCurve), |
81 | | GenericModelEngine<Gaussian1dModel, FloatFloatSwaption::arguments, |
82 | | FloatFloatSwaption::results>(model), |
83 | | integrationPoints_(integrationPoints), stddevs_(stddevs), |
84 | | extrapolatePayoff_(extrapolatePayoff), |
85 | | flatPayoffExtrapolation_(flatPayoffExtrapolation), |
86 | | oas_(oas), discountCurve_(discountCurve), |
87 | | includeTodaysExercise_(includeTodaysExercise), |
88 | 0 | probabilities_(probabilities) { |
89 | 0 |
|
90 | 0 | if (!discountCurve_.empty()) |
91 | 0 | registerWith(discountCurve_); |
92 | 0 |
|
93 | 0 | if (!oas_.empty()) |
94 | 0 | registerWith(oas_); |
95 | 0 | } |
96 | | |
97 | | Gaussian1dFloatFloatSwaptionEngine( |
98 | | const Handle<Gaussian1dModel> &model, |
99 | | const int integrationPoints = 64, const Real stddevs = 7.0, |
100 | | const bool extrapolatePayoff = true, |
101 | | const bool flatPayoffExtrapolation = false, |
102 | | const Handle<Quote> &oas = |
103 | | Handle<Quote>(), // continously compounded w.r.t. yts daycounter |
104 | | const Handle<YieldTermStructure> &discountCurve = |
105 | | Handle<YieldTermStructure>(), |
106 | | const bool includeTodaysExercise = false, |
107 | | const Probabilities probabilities = None) |
108 | | : BasketGeneratingEngine(model, oas, discountCurve), |
109 | | GenericModelEngine<Gaussian1dModel, FloatFloatSwaption::arguments, |
110 | | FloatFloatSwaption::results>(model), |
111 | | integrationPoints_(integrationPoints), stddevs_(stddevs), |
112 | | extrapolatePayoff_(extrapolatePayoff), |
113 | | flatPayoffExtrapolation_(flatPayoffExtrapolation), |
114 | | oas_(oas), discountCurve_(discountCurve), |
115 | | includeTodaysExercise_(includeTodaysExercise), |
116 | 0 | probabilities_(probabilities) { |
117 | 0 |
|
118 | 0 | if (!discountCurve_.empty()) |
119 | 0 | registerWith(discountCurve_); |
120 | 0 |
|
121 | 0 | if (!oas_.empty()) |
122 | 0 | registerWith(oas_); |
123 | 0 | } |
124 | | |
125 | | void calculate() const override; |
126 | | |
127 | 0 | Handle<YieldTermStructure> discountingCurve() const { |
128 | 0 | return discountCurve_.empty() ? model_->termStructure() |
129 | 0 | : discountCurve_; |
130 | 0 | } |
131 | | |
132 | | protected: |
133 | | Real underlyingNpv(const Date& expiry, Real y) const override; |
134 | | Swap::Type underlyingType() const override; |
135 | | const Date underlyingLastDate() const override; |
136 | | const Array initialGuess(const Date& expiry) const override; |
137 | | |
138 | | private: |
139 | | const int integrationPoints_; |
140 | | const Real stddevs_; |
141 | | const bool extrapolatePayoff_, flatPayoffExtrapolation_; |
142 | | const Handle<Quote> oas_; |
143 | | const Handle<YieldTermStructure> discountCurve_; |
144 | | const bool includeTodaysExercise_; |
145 | | const Probabilities probabilities_; |
146 | | |
147 | | std::pair<Real, Real> npvs(const Date& expiry, |
148 | | Real y, |
149 | | bool includeExerciseOnxpiry, |
150 | | bool considerProbabilities = false) const; |
151 | | |
152 | | mutable ext::shared_ptr<RebatedExercise> rebatedExercise_; |
153 | | }; |
154 | | } |
155 | | |
156 | | #endif |