Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
formulabasedindexbuilder.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
21
23
24#include <ql/time/calendars/jointcalendar.hpp>
25#include <ql/time/calendars/nullcalendar.hpp>
26
27#include <boost/make_shared.hpp>
28
29namespace ore {
30namespace data {
31
32QuantLib::ext::shared_ptr<QuantExt::FormulaBasedIndex>
33makeFormulaBasedIndex(const std::string& formula, const QuantLib::ext::shared_ptr<ore::data::Market> market,
34 const std::string& configuration,
35 std::map<std::string, QuantLib::ext::shared_ptr<QuantLib::InterestRateIndex>>& indexMaps,
36 const Calendar& fixingCalendar) {
37
38 indexMaps.clear();
39 std::vector<QuantLib::ext::shared_ptr<QuantLib::InterestRateIndex>> indices;
40 std::vector<std::string> variables;
41 QuantExt::CompiledFormula compiledFormula = parseFormula(formula, variables);
42 Calendar fixCal = NullCalendar();
43 for (auto const& v : variables) {
44 QuantLib::ext::shared_ptr<InterestRateIndex> index;
45 QuantLib::ext::shared_ptr<IborIndex> dummyIborIndex;
46 if (ore::data::tryParseIborIndex(v, dummyIborIndex)) {
47 index = *market->iborIndex(v, configuration);
48 } else {
49 // if it is not an ibor index, we know it must be a swap index
50 index = *market->swapIndex(v, configuration);
51 }
52 QL_REQUIRE(index != nullptr, "makeFormulaBasedIndex("
53 << formula << "): variable \"" << v
54 << "\" could not resolved as an ibor or swap index in the given market");
55 indices.push_back(index);
56 fixCal = JointCalendar(fixCal, index->fixingCalendar());
57 indexMaps[v] = index;
58 }
59
60 QuantLib::ext::shared_ptr<QuantExt::FormulaBasedIndex> fbi = QuantLib::ext::make_shared<QuantExt::FormulaBasedIndex>(
61 "FormulaBasedIndex", indices, compiledFormula, fixingCalendar == Calendar() ? fixCal : fixingCalendar);
62 return fbi;
63}
64
65} // namespace data
66} // namespace ore
formula based index builder
generic formula parser
bool tryParseIborIndex(const string &s, QuantLib::ext::shared_ptr< IborIndex > &index)
Try to convert std::string to QuantLib::IborIndex.
Map text representations to QuantLib/QuantExt types.
@ data
Definition: log.hpp:77
QuantExt::CompiledFormula parseFormula(const std::string &text, std::vector< std::string > &variables)
QuantLib::ext::shared_ptr< QuantExt::FormulaBasedIndex > makeFormulaBasedIndex(const std::string &formula, const QuantLib::ext::shared_ptr< ore::data::Market > market, const std::string &configuration, std::map< std::string, QuantLib::ext::shared_ptr< QuantLib::InterestRateIndex > > &indexMaps, const Calendar &fixingCalendar)
Serializable Credit Default Swap.
Definition: namespaces.docs:23