Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
equityfxlegbuilder.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 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
25#include <ql/cashflows/fixedratecoupon.hpp>
26#include <ql/cashflows/simplecashflow.hpp>
27#include <ql/time/calendars/weekendsonly.hpp>
28#include <ql/time/daycounters/one.hpp>
29
30using namespace ore::data;
31using namespace QuantExt;
32using namespace QuantLib;
33
34using std::string;
35
36namespace ore {
37namespace data {
38
39Leg EquityMarginLegBuilder::buildLeg(const LegData& data, const QuantLib::ext::shared_ptr<EngineFactory>& engineFactory,
40 RequiredFixings& requiredFixings, const string& configuration,
41 const QuantLib::Date& openEndDateReplacement, const bool useXbsCurves) const {
42 auto eqMarginData = QuantLib::ext::dynamic_pointer_cast<EquityMarginLegData>(data.concreteLegData());
43 QL_REQUIRE(eqMarginData, "Wrong LegType, expected EquityMargin");
44
45 QuantLib::ext::shared_ptr<EquityLegData> eqData = eqMarginData->equityLegData();
46
47 string eqName = eqData->eqName();
48 auto eqCurve = *engineFactory->market()->equityCurve(eqName, configuration);
49
50 Currency dataCurrency = parseCurrencyWithMinors(data.currency());
51 Currency eqCurrency = eqCurve->currency();
52
53 QuantLib::ext::shared_ptr<QuantExt::FxIndex> fxIndex = nullptr;
54 // if equity currency differs from the leg currency we need an FxIndex
55 if (dataCurrency != eqCurrency) {
56 QL_REQUIRE(eqData->fxIndex() != "",
57 "No FxIndex - if equity currency differs from leg currency an FxIndex must be provided");
58 fxIndex = buildFxIndex(eqData->fxIndex(), data.currency(), eqCurrency.code(), engineFactory->market(),
59 configuration);
60 }
61
62 Leg result = makeEquityMarginLeg(data, eqCurve, fxIndex, openEndDateReplacement);
63 addToRequiredFixings(result, QuantLib::ext::make_shared<ore::data::FixingDateGetter>(requiredFixings));
64 return result;
65}
66
67} // namespace data
68} // 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=QuantLib::Null< QuantLib::Date >(), const bool useXbsCurves=false) const override
Serializable object holding leg data.
Definition: legdata.hpp:844
Equity & FX leg builders.
leg data for equityfx leg types
Logic for calculating required fixing dates on legs.
Currency parseCurrencyWithMinors(const string &s)
Convert text to QuantLib::Currency.
Definition: parsers.cpp:310
Classes and functions for log message handling.
@ data
Definition: log.hpp:77
market data related utilties
void addToRequiredFixings(const QuantLib::Leg &leg, const QuantLib::ext::shared_ptr< FixingDateGetter > &fixingDateGetter)
QuantExt::Leg makeEquityMarginLeg(const LegData &data, const QuantLib::ext::shared_ptr< EquityIndex2 > &equityCurve, const QuantLib::ext::shared_ptr< QuantExt::FxIndex > &fxIndex, const QuantLib::Date &openEndDateReplacement)
QuantLib::ext::shared_ptr< QuantExt::FxIndex > buildFxIndex(const string &fxIndex, const string &domestic, const string &foreign, const QuantLib::ext::shared_ptr< Market > &market, const string &configuration, bool useXbsCurves)
Definition: marketdata.cpp:137
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Map text representations to QuantLib/QuantExt types.