QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
forwardswapquote.cpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2007 Ferdinando Ametrano
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 license. 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 <http://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
21#include <ql/settings.hpp>
22#include <utility>
23
24namespace QuantLib {
25
26 ForwardSwapQuote::ForwardSwapQuote(ext::shared_ptr<SwapIndex> swapIndex,
27 Handle<Quote> spread,
28 const Period& fwdStart)
29 : swapIndex_(std::move(swapIndex)), spread_(std::move(spread)), fwdStart_(fwdStart) {
32 registerWith(Settings::instance().evaluationDate());
35 }
36
38 valueDate_ = swapIndex_->fixingCalendar().advance(
40 swapIndex_->fixingDays()*Days,
41 Following);
42 startDate_ = swapIndex_->fixingCalendar().advance(valueDate_,
44 Following);
45 fixingDate_ = swapIndex_->fixingDate(startDate_);
46 swap_ = swapIndex_->underlyingSwap(fixingDate_);
47 }
48
50 if (evaluationDate_ != Settings::instance().evaluationDate()) {
53 }
55 }
56
58 calculate();
59 return valueDate_;
60 }
61
63 calculate();
64 return startDate_;
65 }
66
68 calculate();
69 return fixingDate_;
70 }
71
73 calculate();
74 return result_;
75 }
76
78 bool swapIndexIsValid = true;
79 try {
80 swap_->recalculate();
81 } catch (...) {
82 swapIndexIsValid = false;
83 }
84 bool spreadIsValid = spread_.empty() ? true : spread_->isValid();
85 return swapIndexIsValid && spreadIsValid;
86 }
87
89 // we didn't register as observers - force calculation
90 swap_->recalculate();
91 // weak implementation... to be improved
92 static const Spread basisPoint = 1.0e-4;
93 Real floatingLegNPV = swap_->floatingLegNPV();
94 Spread spread = spread_.empty() ? 0.0 : spread_->value();
95 Real spreadNPV = swap_->floatingLegBPS()/basisPoint*spread;
96 Real totNPV = - (floatingLegNPV+spreadNPV);
97 result_ = totNPV/(swap_->fixedLegBPS()/basisPoint);
98 }
99}
Concrete date class.
Definition: date.hpp:125
void performCalculations() const override
ext::shared_ptr< VanillaSwap > swap_
ext::shared_ptr< SwapIndex > swapIndex_
ForwardSwapQuote(ext::shared_ptr< SwapIndex > swapIndex, Handle< Quote > spread, const Period &fwdStart)
const Date & valueDate() const
const Date & startDate() const
const Date & fixingDate() const
Real value() const override
returns the current value
bool isValid() const override
returns true if the Quote holds a valid value
Shared handle to an observable.
Definition: handle.hpp:41
virtual void calculate() const
Definition: lazyobject.hpp:253
void update() override
Definition: lazyobject.hpp:188
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
DateProxy & evaluationDate()
the date at which pricing is to be performed.
Definition: settings.hpp:147
static Settings & instance()
access to the unique instance
Definition: singleton.hpp:104
quote for a forward starting swap
QL_REAL Real
real number
Definition: types.hpp:50
Real Spread
spreads on interest rates
Definition: types.hpp:74
Definition: any.hpp:35
STL namespace.
global repository for run-time library settings