Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
formulabasedindex.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2018 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
20
21#include <ql/time/daycounters/simpledaycounter.hpp>
22
23namespace QuantExt {
24
25FormulaBasedIndex::FormulaBasedIndex(const std::string& familyName,
26 const std::vector<QuantLib::ext::shared_ptr<InterestRateIndex>>& indices,
27 const CompiledFormula& formula, const Calendar& fixingCalendar)
28 : InterestRateIndex(familyName, 0 * Days, indices.front()->fixingDays(), Currency(), fixingCalendar,
29 SimpleDayCounter()),
30 indices_(indices), formula_(formula) {
31
32 std::ostringstream name;
33 name << familyName << "(";
34 for (Size i = 0; i < indices_.size(); ++i) {
35 registerWith(indices_[i]);
36 name << indices_[i]->name();
37 if (i < indices_.size() - 1)
38 name << ", ";
39 }
40 name << ")";
41 name_ = name.str();
42} // FormulaBasedIndex
43
44Rate FormulaBasedIndex::forecastFixing(const Date& fixingDate) const {
45 std::vector<Real> values;
46 for (auto const& i : indices_) {
47 // this also handles the case when one of indices has
48 // a historic fixing on the evaluation date
49 values.push_back(i->fixing(fixingDate, false));
50 }
51 return formula_(values.begin(), values.end());
52}
53
54Rate FormulaBasedIndex::pastFixing(const Date& fixingDate) const {
55 std::vector<Real> values;
56 for (auto const& i : indices_) {
57 Real f = i->pastFixing(fixingDate);
58 // if one of the fixings is missing, the fixing of the composed
59 // index is also missing, this is indicated by a null value
60 if (f == Null<Real>())
61 return Null<Real>();
62 values.push_back(f);
63 }
64 return formula_(values.begin(), values.end());
65}
66
67} // namespace QuantExt
helper class representing a formula with variables given by an id v
FormulaBasedIndex(const std::string &familyName, const std::vector< QuantLib::ext::shared_ptr< InterestRateIndex > > &indices, const CompiledFormula &formula, const Calendar &fixingCalendar)
Rate pastFixing(const Date &fixingDate) const override
const CompiledFormula formula_
const std::vector< QuantLib::ext::shared_ptr< InterestRateIndex > > indices_
Rate forecastFixing(const Date &fixingDate) const override
formula based index