QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
swapspreadindex.cpp
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
19#include <iomanip>
20#include <sstream>
21#include <utility>
22
23namespace QuantLib {
24
25 SwapSpreadIndex::SwapSpreadIndex(const std::string& familyName,
26 const ext::shared_ptr<SwapIndex>& swapIndex1,
27 ext::shared_ptr<SwapIndex> swapIndex2,
28 const Real gearing1,
29 const Real gearing2)
30 : InterestRateIndex(familyName,
31 swapIndex1->tenor(), // does not make sense, but we have to provide one
32 swapIndex1->fixingDays(),
33 swapIndex1->currency(),
34 swapIndex1->fixingCalendar(),
35 swapIndex1->dayCounter()),
36 swapIndex1_(swapIndex1), swapIndex2_(std::move(swapIndex2)), gearing1_(gearing1),
37 gearing2_(gearing2) {
38
41
42 std::ostringstream name;
43 name << std::setprecision(4) << std::fixed << swapIndex1_->name() << "("
44 << gearing1 << ") + " << swapIndex2_->name() << "(" << gearing2
45 << ")";
46 name_ = name.str();
47
48 QL_REQUIRE(swapIndex1_->fixingDays() == swapIndex2_->fixingDays(),
49 "index1 fixing days ("
50 << swapIndex1_->fixingDays() << ")"
51 << "must be equal to index2 fixing days ("
52 << swapIndex2_->fixingDays() << ")");
53
54 QL_REQUIRE(swapIndex1_->fixingCalendar() ==
55 swapIndex2_->fixingCalendar(),
56 "index1 fixingCalendar ("
57 << swapIndex1_->fixingCalendar() << ")"
58 << "must be equal to index2 fixingCalendar ("
59 << swapIndex2_->fixingCalendar() << ")");
60
61 QL_REQUIRE(swapIndex1_->currency() == swapIndex2_->currency(),
62 "index1 currency (" << swapIndex1_->currency() << ")"
63 << "must be equal to index2 currency ("
64 << swapIndex2_->currency() << ")");
65
66 QL_REQUIRE(swapIndex1_->dayCounter() == swapIndex2_->dayCounter(),
67 "index1 dayCounter ("
68 << swapIndex1_->dayCounter() << ")"
69 << "must be equal to index2 dayCounter ("
70 << swapIndex2_->dayCounter() << ")");
71
72 QL_REQUIRE(swapIndex1_->fixedLegTenor() == swapIndex2_->fixedLegTenor(),
73 "index1 fixedLegTenor ("
74 << swapIndex1_->fixedLegTenor() << ")"
75 << "must be equal to index2 fixedLegTenor ("
76 << swapIndex2_->fixedLegTenor());
77
78 QL_REQUIRE(swapIndex1_->fixedLegConvention() ==
79 swapIndex2_->fixedLegConvention(),
80 "index1 fixedLegConvention ("
81 << swapIndex1_->fixedLegConvention() << ")"
82 << "must be equal to index2 fixedLegConvention ("
83 << swapIndex2_->fixedLegConvention());
84 }
85}
base class for interest rate indexes
std::string name() const override
Returns the name of the index.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
ext::shared_ptr< SwapIndex > swapIndex2_
SwapSpreadIndex(const std::string &familyName, const ext::shared_ptr< SwapIndex > &swapIndex1, ext::shared_ptr< SwapIndex > swapIndex2, Real gearing1=1.0, Real gearing2=-1.0)
ext::shared_ptr< SwapIndex > swapIndex1_
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
STL namespace.
swap-rate spread indexes