QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
swapspreadindex.hpp
Go to the documentation of this file.
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 <http://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
26
27namespace QuantLib {
28
29 //! class for swap-rate spread indexes
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 Date maturityDate(const Date& valueDate) const override {
41 QL_FAIL("SwapSpreadIndex does not provide a single maturity date");
42 }
43 Rate forecastFixing(const Date& fixingDate) const override;
44 Rate pastFixing(const Date& fixingDate) const override;
45 bool allowsNativeFixings() override { return false; }
46 //@}
47
48 //! \name Inspectors
49 //@{
50 ext::shared_ptr<SwapIndex> swapIndex1() { return swapIndex1_; }
51 ext::shared_ptr<SwapIndex> swapIndex2() { return swapIndex2_; }
52 Real gearing1() const { return gearing1_; }
53 Real gearing2() const { return gearing2_; }
54 //@}
55
56
57 private:
58 ext::shared_ptr<SwapIndex> swapIndex1_, swapIndex2_;
60 };
61
62
63 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 return gearing1_ * swapIndex1_->fixing(fixingDate,false) +
67 gearing2_ * swapIndex2_->fixing(fixingDate,false);
68
69 }
70
71 inline Rate SwapSpreadIndex::pastFixing(const Date& fixingDate) const {
72
73 Real f1 = swapIndex1_->pastFixing(fixingDate);
74 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 if(f1 == Null<Real>() || f2 == Null<Real>())
78 return Null<Real>();
79 else
80 return gearing1_ * f1 + gearing2_ * f2;
81 }
82
83}
84
85#endif
Concrete date class.
Definition: date.hpp:125
base class for interest rate indexes
virtual Date valueDate(const Date &fixingDate) const
Date fixingDate(const Date &valueDate) const
std::string familyName() const
template class providing a null value for a given type.
Definition: null.hpp:76
class for swap-rate spread indexes
ext::shared_ptr< SwapIndex > swapIndex2_
bool allowsNativeFixings() override
check if index allows for native fixings.
Rate pastFixing(const Date &fixingDate) const override
Date maturityDate(const Date &valueDate) const override
ext::shared_ptr< SwapIndex > swapIndex1()
ext::shared_ptr< SwapIndex > swapIndex2()
ext::shared_ptr< SwapIndex > swapIndex1_
Rate forecastFixing(const Date &fixingDate) const override
It can be overridden to implement particular conventions.
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Definition: errors.hpp:92
QL_REAL Real
real number
Definition: types.hpp:50
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35
swap-rate indexes