/src/quantlib/ql/experimental/swaptions/irregularswaption.hpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2001, 2002, 2003 Sadruddin Rejeb |
5 | | Copyright (C) 2006 Cristina Duminuco |
6 | | Copyright (C) 2006 Marco Bianchetti |
7 | | Copyright (C) 2007 StatPro Italia srl |
8 | | Copyright (C) 2010 Andre Miemiec |
9 | | |
10 | | This file is part of QuantLib, a free-software/open-source library |
11 | | for financial quantitative analysts and developers - http://quantlib.org/ |
12 | | |
13 | | QuantLib is free software: you can redistribute it and/or modify it |
14 | | under the terms of the QuantLib license. You should have received a |
15 | | copy of the license along with this program; if not, please email |
16 | | <quantlib-dev@lists.sf.net>. The license is also available online at |
17 | | <https://www.quantlib.org/license.shtml>. |
18 | | |
19 | | This program is distributed in the hope that it will be useful, but WITHOUT |
20 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
21 | | FOR A PARTICULAR PURPOSE. See the license for more details. |
22 | | */ |
23 | | |
24 | | /*! \file irregularswaption.hpp |
25 | | \brief Irregular swaption class |
26 | | */ |
27 | | |
28 | | #ifndef quantlib_instruments_irregular_swaption_hpp |
29 | | #define quantlib_instruments_irregular_swaption_hpp |
30 | | |
31 | | #include <ql/option.hpp> |
32 | | #include <ql/experimental/swaptions/irregularswap.hpp> |
33 | | #include <ql/termstructures/yieldtermstructure.hpp> |
34 | | |
35 | | namespace QuantLib { |
36 | | |
37 | | //! %settlement information |
38 | | struct IrregularSettlement { |
39 | | enum Type { Physical, Cash }; |
40 | | }; |
41 | | |
42 | | std::ostream& operator<<(std::ostream& out, |
43 | | IrregularSettlement::Type type); |
44 | | |
45 | | //! Irregular %Swaption class |
46 | | /*! \ingroup instruments */ |
47 | | class IrregularSwaption : public Option { |
48 | | public: |
49 | | class arguments; |
50 | | class engine; |
51 | | IrregularSwaption(ext::shared_ptr<IrregularSwap> swap, |
52 | | const ext::shared_ptr<Exercise>& exercise, |
53 | | IrregularSettlement::Type delivery = IrregularSettlement::Physical); |
54 | | //! \name Instrument interface |
55 | | //@{ |
56 | | bool isExpired() const override; |
57 | | void setupArguments(PricingEngine::arguments*) const override; |
58 | | //@} |
59 | | //! \name Inspectors |
60 | | //@{ |
61 | 0 | IrregularSettlement::Type settlementType() const { return settlementType_; } |
62 | 0 | Swap::Type type() const { return swap_->type(); } |
63 | 0 | const ext::shared_ptr<IrregularSwap>& underlyingSwap() const { |
64 | 0 | return swap_; |
65 | 0 | } |
66 | | //@} |
67 | | //! implied volatility |
68 | | Volatility impliedVolatility( |
69 | | Real price, |
70 | | const Handle<YieldTermStructure>& discountCurve, |
71 | | Volatility guess, |
72 | | Real accuracy = 1.0e-4, |
73 | | Natural maxEvaluations = 100, |
74 | | Volatility minVol = 1.0e-7, |
75 | | Volatility maxVol = 4.0) const; |
76 | | private: |
77 | | // arguments |
78 | | ext::shared_ptr<IrregularSwap> swap_; |
79 | | IrregularSettlement::Type settlementType_; |
80 | | }; |
81 | | |
82 | | //! %Arguments for irregular-swaption calculation |
83 | | class IrregularSwaption::arguments : public IrregularSwap::arguments, |
84 | | public Option::arguments { |
85 | | public: |
86 | 0 | arguments() = default; |
87 | | ext::shared_ptr<IrregularSwap> swap; |
88 | | IrregularSettlement::Type settlementType = IrregularSettlement::Physical; |
89 | | void validate() const override; |
90 | | }; |
91 | | |
92 | | //! base class for irregular-swaption engines |
93 | | class IrregularSwaption::engine |
94 | | : public GenericEngine<IrregularSwaption::arguments, IrregularSwaption::results> {}; |
95 | | |
96 | | } |
97 | | |
98 | | #endif |