Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
balanceguaranteedswap.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#include <qle/pricingengines/numericlgmbgsflexiswapengine.hpp>
21
22#include <ql/quotes/compositequote.hpp>
23
24namespace ore {
25namespace data {
26
27QuantLib::ext::shared_ptr<PricingEngine>
28BalanceGuaranteedSwapFlexiSwapLGMGridEngineBuilder::engineImpl(const string& id, const string& id2, const string& ccy,
29 const std::vector<Date>& expiries, const Date& maturity,
30 const std::vector<Real>& strikes) {
31 DLOG("Building LGM Grid BGS Flexi Swap engine for trade " << id);
32
33 QuantLib::ext::shared_ptr<QuantExt::LGM> lgm = model(id, ccy, expiries, maturity, strikes);
34
35 DLOG("Get engine data");
36 Real sy = parseReal(engineParameter("sy"));
37 Size ny = parseInteger(engineParameter("ny"));
38 Real sx = parseReal(engineParameter("sx"));
39 Size nx = parseInteger(engineParameter("nx"));
40 QuantExt::NumericLgmFlexiSwapEngine::Method method;
41 if (engineParameter("method") == "SingleSwaptions")
42 method = QuantExt::NumericLgmFlexiSwapEngine::Method::SingleSwaptions;
43 else if (engineParameter("method") == "SwaptionArray")
44 method = QuantExt::NumericLgmFlexiSwapEngine::Method::SwaptionArray;
45 else if (engineParameter("method") == "Automatic")
46 method = QuantExt::NumericLgmFlexiSwapEngine::Method::Automatic;
47 else {
48 QL_FAIL("FlexiSwap engine parameter method (" << engineParameter("method") << ") not recognised");
49 }
50 Real singleSwaptionThreshold = parseReal(engineParameter("singleSwaptionThreshold"));
51
52 Handle<Quote> minCprMult(QuantLib::ext::make_shared<SimpleQuote>(parseReal(modelParameter("MinCPRMultiplier"))));
53 Handle<Quote> maxCprMult(QuantLib::ext::make_shared<SimpleQuote>(parseReal(modelParameter("MaxCPRMultiplier"))));
54 Handle<Quote> cpr = market_->cpr(id2, configuration(MarketContext::pricing));
55 // use makeCompositeQuote from ql 1.16 onwards...
56 Handle<Quote> minCpr(
57 QuantLib::ext::make_shared<CompositeQuote<std::multiplies<Real>>>(minCprMult, cpr, std::multiplies<Real>()));
58 Handle<Quote> maxCpr(
59 QuantLib::ext::make_shared<CompositeQuote<std::multiplies<Real>>>(maxCprMult, cpr, std::multiplies<Real>()));
60
61 // Build engine
62 DLOG("Build engine (configuration " << configuration(MarketContext::pricing) << ")");
63 Handle<YieldTermStructure> dscCurve = market_->discountCurve(ccy, configuration(MarketContext::pricing));
64 return QuantLib::ext::make_shared<QuantExt::NumericLgmBgsFlexiSwapEngine>(lgm, sy, ny, sx, nx, minCpr, maxCpr, dscCurve,
65 method, singleSwaptionThreshold);
66}
67
68} // namespace data
69} // namespace ore
virtual QuantLib::ext::shared_ptr< QuantLib::PricingEngine > engineImpl(const std::string &id, const std::string &id2, const std::string &ccy, const std::vector< QuantLib::Date > &dates, const QuantLib::Date &maturity, const std::vector< QuantLib::Real > &strikes) override
QuantLib::ext::shared_ptr< Market > market_
const string & model() const
Return the model name.
std::string modelParameter(const std::string &p, const std::vector< std::string > &qualifiers={}, const bool mandatory=true, const std::string &defaultValue="") const
std::string engineParameter(const std::string &p, const std::vector< std::string > &qualifiers={}, const bool mandatory=true, const std::string &defaultValue="") const
const string & configuration(const MarketContext &key)
Return a configuration (or the default one if key not found)
Real parseReal(const string &s)
Convert text to Real.
Definition: parsers.cpp:112
Integer parseInteger(const string &s)
Convert text to QuantLib::Integer.
Definition: parsers.cpp:136
@ data
Definition: log.hpp:77
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
Time maturity
Definition: utilities.cpp:66
Serializable Credit Default Swap.
Definition: namespaces.docs:23
vector< Real > strikes