Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
formulabasedlegbuilder.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
23namespace ore {
24namespace data {
25
26Leg FormulaBasedLegBuilder::buildLeg(const LegData& data, const QuantLib::ext::shared_ptr<EngineFactory>& engineFactory,
27 RequiredFixings& requiredFixings, const string& configuration,
28 const QuantLib::Date& openEndDateReplacement, const bool useXbsCurves) const {
29 auto formulaData = QuantLib::ext::dynamic_pointer_cast<FormulaBasedLegData>(data.concreteLegData());
30 QL_REQUIRE(formulaData, "Wrong LegType, expected Formula");
31 string formula = formulaData->formulaBasedIndex();
32 Calendar cal;
33 if (formulaData->fixingCalendar() != "")
34 cal = parseCalendar(formulaData->fixingCalendar());
35 std::map<std::string, QuantLib::ext::shared_ptr<QuantLib::InterestRateIndex>> indexMaps;
36 auto formulaIndex =
37 makeFormulaBasedIndex(formula, engineFactory->market(), configuration, indexMaps, cal);
38 Leg result = makeFormulaBasedLeg(data, formulaIndex, engineFactory, indexMaps, openEndDateReplacement);
39 // add required fixing dates
40 for (auto const& m : indexMaps) {
41 for (auto const& c : result) {
42 auto f = QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(c);
43 QL_REQUIRE(f != nullptr, "expected FloatingRateCoupon in FormulaBasedLegBuilder");
44 requiredFixings.addFixingDate(f->fixingDate(), m.first, f->date(), false);
45 }
46 }
47 return result;
48}
49
50} // namespace data
51} // namespace ore
QuantLib::Leg buildLeg(const ore::data::LegData &data, const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &engineFactory, ore::data::RequiredFixings &requiredFixings, const std::string &configuration, const QuantLib::Date &openEndDateReplacement=Null< Date >(), const bool useXbsCurves=false) const override
Serializable object holding leg data.
Definition: legdata.hpp:844
void addFixingDate(const QuantLib::Date &fixingDate, const std::string &indexName, const QuantLib::Date &payDate=Date::maxDate(), const bool alwaysAddIfPaysOnSettlement=false, const bool mandatoryFixing=true)
formula based index builder
Formula based leg builder.
leg data for formula based leg types
Calendar parseCalendar(const string &s)
Convert text to QuantLib::Calendar.
Definition: parsers.cpp:157
@ data
Definition: log.hpp:77
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)
Leg makeFormulaBasedLeg(const LegData &data, const QuantLib::ext::shared_ptr< QuantExt::FormulaBasedIndex > &formulaBasedIndex, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, const std::map< std::string, QuantLib::ext::shared_ptr< QuantLib::InterestRateIndex > > &indexMaps, const QuantLib::Date &openEndDateReplacement)
Serializable Credit Default Swap.
Definition: namespaces.docs:23