QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
indexedcashflow.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2009 Chris Kenyon
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
20#include <ql/cashflows/indexedcashflow.hpp>
21#include <ql/index.hpp>
22#include <utility>
23
24namespace QuantLib {
25
27 ext::shared_ptr<Index> index,
28 const Date& baseDate,
29 const Date& fixingDate,
30 const Date& paymentDate,
31 bool growthOnly)
32 : notional_(notional), index_(std::move(index)), baseDate_(baseDate), fixingDate_(fixingDate),
33 paymentDate_(paymentDate), growthOnly_(growthOnly) {
34 QL_REQUIRE(index_, "no index provided");
36 }
37
39 calculate();
40 return amount_;
41 }
42
44 Real I0 = baseFixing();
45 Real I1 = indexFixing();
46
47 if (growthOnly_)
48 amount_ = notional_ * (I1 / I0 - 1.0);
49 else
50 amount_ = notional_ * (I1 / I0);
51 }
52}
Concrete date class.
Definition: date.hpp:125
ext::shared_ptr< Index > index_
void performCalculations() const override
virtual Real indexFixing() const
Real amount() const override
returns the amount of the cash flow
virtual Real baseFixing() const
IndexedCashFlow(Real notional, ext::shared_ptr< Index > index, const Date &baseDate, const Date &fixingDate, const Date &paymentDate, bool growthOnly=false)
virtual void calculate() const
Definition: lazyobject.hpp:253
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
STL namespace.