/src/quantlib/ql/experimental/coupons/swapspreadindex.hpp
Line | Count | Source |
1 | | /* |
2 | | Copyright (C) 2014 Peter Caspers |
3 | | |
4 | | This file is part of QuantLib, a free-software/open-source library |
5 | | for financial quantitative analysts and developers - http://quantlib.org/ |
6 | | |
7 | | QuantLib is free software: you can redistribute it and/or modify it |
8 | | under the terms of the QuantLib license. You should have received a |
9 | | copy of the license along with this program; if not, please email |
10 | | <quantlib-dev@lists.sf.net>. The license is also available online at |
11 | | <https://www.quantlib.org/license.shtml>. |
12 | | |
13 | | |
14 | | This program is distributed in the hope that it will be useful, but |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
16 | | or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. */ |
17 | | |
18 | | /*! \file swapspreadindex.hpp |
19 | | \brief swap-rate spread indexes |
20 | | */ |
21 | | |
22 | | #ifndef quantlib_swapspreadindex_hpp |
23 | | #define quantlib_swapspreadindex_hpp |
24 | | |
25 | | #include <ql/indexes/swapindex.hpp> |
26 | | |
27 | | namespace QuantLib { |
28 | | |
29 | | //! class for swap-rate spread indexes |
30 | | class SwapSpreadIndex : public InterestRateIndex { |
31 | | public: |
32 | | SwapSpreadIndex(const std::string& familyName, |
33 | | const ext::shared_ptr<SwapIndex>& swapIndex1, |
34 | | ext::shared_ptr<SwapIndex> swapIndex2, |
35 | | Real gearing1 = 1.0, |
36 | | Real gearing2 = -1.0); |
37 | | |
38 | | //! \name InterestRateIndex interface |
39 | | //@{ |
40 | 0 | Date maturityDate(const Date& valueDate) const override { |
41 | 0 | QL_FAIL("SwapSpreadIndex does not provide a single maturity date"); |
42 | 0 | } |
43 | | Rate forecastFixing(const Date& fixingDate) const override; |
44 | | Rate pastFixing(const Date& fixingDate) const override; |
45 | 0 | bool allowsNativeFixings() override { return false; } |
46 | | //@} |
47 | | |
48 | | //! \name Inspectors |
49 | | //@{ |
50 | 0 | ext::shared_ptr<SwapIndex> swapIndex1() { return swapIndex1_; } |
51 | 0 | ext::shared_ptr<SwapIndex> swapIndex2() { return swapIndex2_; } |
52 | 0 | Real gearing1() const { return gearing1_; } |
53 | 0 | Real gearing2() const { return gearing2_; } |
54 | | //@} |
55 | | |
56 | | |
57 | | private: |
58 | | ext::shared_ptr<SwapIndex> swapIndex1_, swapIndex2_; |
59 | | Real gearing1_, gearing2_; |
60 | | }; |
61 | | |
62 | | |
63 | 0 | inline Rate SwapSpreadIndex::forecastFixing(const Date& fixingDate) const { |
64 | | // this also handles the case when one of indices has |
65 | | // a historic fixing on the evaluation date |
66 | 0 | return gearing1_ * swapIndex1_->fixing(fixingDate,false) + |
67 | 0 | gearing2_ * swapIndex2_->fixing(fixingDate,false); |
68 | |
|
69 | 0 | } |
70 | | |
71 | 0 | inline Rate SwapSpreadIndex::pastFixing(const Date& fixingDate) const { |
72 | |
|
73 | 0 | Real f1 = swapIndex1_->pastFixing(fixingDate); |
74 | 0 | Real f2 = swapIndex2_->pastFixing(fixingDate); |
75 | | // if one of the fixings is missing we return null, indicating |
76 | | // a missing fixing for the spread index |
77 | 0 | if(f1 == Null<Real>() || f2 == Null<Real>()) |
78 | 0 | return Null<Real>(); |
79 | 0 | else |
80 | 0 | return gearing1_ * f1 + gearing2_ * f2; |
81 | 0 | } |
82 | | |
83 | | } |
84 | | |
85 | | #endif |