Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
scriptedtrade.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 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
19#pragma once
20
28
30
32
33#include <ql/processes/blackscholesprocess.hpp>
34
35namespace ore {
36namespace data {
37
39public:
40 //! constructor that builds a usual pricing engine
41 ScriptedTradeEngineBuilder() : EngineBuilder("Generic", "Generic", {"ScriptedTrade"}) {}
42
43 //! constructor that builds an AMC - enabled pricing engine
44 ScriptedTradeEngineBuilder(const QuantLib::ext::shared_ptr<QuantExt::CrossAssetModel>& amcCam,
45 const std::vector<Date>& amcGrid)
46 : EngineBuilder("Generic", "Generic", {"ScriptedTrade"}), buildingAmc_(true), amcCam_(amcCam),
47 amcGrid_(amcGrid) {}
48
49 //! constructor that builds an AMCCG pricing engine
50 ScriptedTradeEngineBuilder(const QuantLib::ext::shared_ptr<ore::data::ModelCG>& amcCgModel,
51 const std::vector<Date>& amcGrid)
52 : EngineBuilder("Generic", "Generic", {"ScriptedTrade"}), buildingAmc_(true), amcCgModel_(amcCgModel),
53 amcGrid_(amcGrid) {}
54
55 QuantLib::ext::shared_ptr<QuantExt::ScriptedInstrument::engine>
56 engine(const std::string& id, const ScriptedTrade& scriptedTrade,
57 const QuantLib::ext::shared_ptr<ore::data::ReferenceDataManager>& referenceData = nullptr,
58 const IborFallbackConfig& iborFallbackConfig = IborFallbackConfig::defaultConfig());
59
60 // these are guaranteed to be set only after engine() was called
61 const std::string& npvCurrency() const { return model_ ? model_->baseCcy() : modelCG_->baseCcy(); }
62 const QuantLib::Date& lastRelevantDate() const { return lastRelevantDate_; }
63 const std::string& simmProductClass() const { return simmProductClass_; }
64 const std::string& scheduleProductClass() const { return scheduleProductClass_; }
65 const std::string& sensitivityTemplate() const { return sensitivityTemplate_; }
66 const std::map<std::string, std::set<Date>>& fixings() const { return fixings_; }
67
68protected:
69 // hook for correlation retrieval - by default the correlation for a pair of indices is queried from the market
70 // other implementations might want to estimate the correlation on the fly based on historical data
71 virtual QuantLib::Handle<QuantExt::CorrelationTermStructure> correlationCurve(const std::string& index1,
72 const std::string& index2);
73
74 // sub tasks for engine building
75 void clear();
76 void extractIndices(const QuantLib::ext::shared_ptr<ore::data::ReferenceDataManager>& referenceData = nullptr);
77 void deriveProductClass(const std::vector<ScriptedTradeValueTypeData>& indices);
79 void populateFixingsMap(const IborFallbackConfig& iborFallbackConfig);
80 void extractPayCcys();
81 void determineBaseCcy();
84 void setupCorrelations();
86 virtual void setupBlackScholesProcesses(); // hook for custom building of processes
87 void setupIrReversions();
89 void buildBlackScholes(const std::string& id, const IborFallbackConfig& iborFallbackConfig);
90 void buildFdBlackScholes(const std::string& id, const IborFallbackConfig& iborFallbackConfig);
91 void buildLocalVol(const std::string& id, const IborFallbackConfig& iborFallbackConfig);
92 void buildGaussianCam(const std::string& id, const IborFallbackConfig& iborFallbackConfig,
93 const std::vector<std::string>& conditionalExpectationModelStates);
94 void buildFdGaussianCam(const std::string& id, const IborFallbackConfig& iborFallbackConfig);
95 void buildGaussianCamAMC(const std::string& id, const IborFallbackConfig& iborFallbackConfig,
96 const std::vector<std::string>& conditionalExpectationModelStates);
97 void buildAMCCGModel(const std::string& id, const IborFallbackConfig& iborFallbackConfig,
98 const std::vector<std::string>& conditionalExpectationModelStates);
99 void addAmcGridToContext(QuantLib::ext::shared_ptr<Context>& context) const;
100 void setupCalibrationStrikes(const ScriptedTradeScriptData& script, const QuantLib::ext::shared_ptr<Context>& context);
101
102 // gets eq ccy from market
103 std::string getEqCcy(const IndexInfo& e);
104
105 // gets comm ccy from market
106 std::string getCommCcy(const IndexInfo& e);
107
108 // input data (for amc, amcCam_, amcCgModel_ are mutually exclusive)
109 bool buildingAmc_ = false;
110 const QuantLib::ext::shared_ptr<QuantExt::CrossAssetModel> amcCam_;
111 const QuantLib::ext::shared_ptr<ore::data::ModelCG> amcCgModel_;
112 const std::vector<Date> amcGrid_;
113
114 // cache for parsed asts
115 std::map<std::string, ASTNodePtr> astCache_;
116
117 // populated by a call to engine()
119 std::string npvCurrency_;
120 QuantLib::Date lastRelevantDate_;
121 std::string simmProductClass_;
124 std::map<std::string, std::set<Date>> fixings_;
125
126 // temporary variables used during engine building
127 QuantLib::ext::shared_ptr<StaticAnalyser> staticAnalyser_;
130 std::set<std::string> payCcys_;
131 std::string baseCcy_;
132 std::vector<std::string> modelCcys_;
133 std::vector<Handle<YieldTermStructure>> modelCurves_;
134 std::vector<Handle<Quote>> modelFxSpots_;
135 std::vector<std::string> modelIndices_, modelIndicesCurrencies_;
136 std::vector<std::pair<std::string, QuantLib::ext::shared_ptr<InterestRateIndex>>> modelIrIndices_;
137 std::vector<std::pair<std::string, QuantLib::ext::shared_ptr<ZeroInflationIndex>>> modelInfIndices_;
138 std::map<std::pair<std::string, std::string>, Handle<QuantExt::CorrelationTermStructure>> correlations_;
139 std::vector<QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess>> processes_;
140 std::map<std::string, Real> irReversions_;
142 QuantLib::ext::shared_ptr<Model> model_;
143 QuantLib::ext::shared_ptr<ModelCG> modelCG_;
144 std::map<std::string, std::vector<Real>> calibrationStrikes_;
145
146 // model / engine parameters
152 std::vector<Real> calibrationMoneyness_;
159 std::string calibration_;
160 bool useCg_;
161 bool useAd_;
167};
168
169} // namespace data
170} // namespace ore
abstract syntax tree for payoff scripting
std::string script
Base PricingEngine Builder class for a specific model and engine.
const string & engine() const
Return the engine name.
static IborFallbackConfig defaultConfig()
std::map< std::string, Real > irReversions_
const QuantLib::Date & lastRelevantDate() const
QuantLib::ext::shared_ptr< StaticAnalyser > staticAnalyser_
void buildLocalVol(const std::string &id, const IborFallbackConfig &iborFallbackConfig)
const std::string & sensitivityTemplate() const
std::vector< std::string > modelIndices_
void buildFdGaussianCam(const std::string &id, const IborFallbackConfig &iborFallbackConfig)
ScriptedTradeEngineBuilder()
constructor that builds a usual pricing engine
void buildAMCCGModel(const std::string &id, const IborFallbackConfig &iborFallbackConfig, const std::vector< std::string > &conditionalExpectationModelStates)
void buildFdBlackScholes(const std::string &id, const IborFallbackConfig &iborFallbackConfig)
void extractIndices(const QuantLib::ext::shared_ptr< ore::data::ReferenceDataManager > &referenceData=nullptr)
std::vector< std::string > modelIndicesCurrencies_
const std::map< std::string, std::set< Date > > & fixings() const
const std::string & scheduleProductClass() const
std::map< std::pair< std::string, std::string >, Handle< QuantExt::CorrelationTermStructure > > correlations_
std::vector< Handle< Quote > > modelFxSpots_
std::map< std::string, std::set< Date > > fixings_
const QuantLib::ext::shared_ptr< QuantExt::CrossAssetModel > amcCam_
const std::string & npvCurrency() const
const QuantLib::ext::shared_ptr< ore::data::ModelCG > amcCgModel_
QuantLib::ext::shared_ptr< Model > model_
void buildGaussianCam(const std::string &id, const IborFallbackConfig &iborFallbackConfig, const std::vector< std::string > &conditionalExpectationModelStates)
std::vector< std::string > modelCcys_
void buildGaussianCamAMC(const std::string &id, const IborFallbackConfig &iborFallbackConfig, const std::vector< std::string > &conditionalExpectationModelStates)
const std::vector< Date > amcGrid_
void setupCalibrationStrikes(const ScriptedTradeScriptData &script, const QuantLib::ext::shared_ptr< Context > &context)
QuantLib::ext::shared_ptr< ModelCG > modelCG_
void addAmcGridToContext(QuantLib::ext::shared_ptr< Context > &context) const
std::vector< std::pair< std::string, QuantLib::ext::shared_ptr< ZeroInflationIndex > > > modelInfIndices_
void buildBlackScholes(const std::string &id, const IborFallbackConfig &iborFallbackConfig)
std::string getCommCcy(const IndexInfo &e)
ScriptedTradeEngineBuilder(const QuantLib::ext::shared_ptr< QuantExt::CrossAssetModel > &amcCam, const std::vector< Date > &amcGrid)
constructor that builds an AMC - enabled pricing engine
std::map< std::string, std::vector< Real > > calibrationStrikes_
const std::string & simmProductClass() const
std::vector< Handle< YieldTermStructure > > modelCurves_
ScriptedTradeEngineBuilder(const QuantLib::ext::shared_ptr< ore::data::ModelCG > &amcCgModel, const std::vector< Date > &amcGrid)
constructor that builds an AMCCG pricing engine
void populateFixingsMap(const IborFallbackConfig &iborFallbackConfig)
std::vector< std::pair< std::string, QuantLib::ext::shared_ptr< InterestRateIndex > > > modelIrIndices_
void deriveProductClass(const std::vector< ScriptedTradeValueTypeData > &indices)
std::map< std::string, ASTNodePtr > astCache_
virtual QuantLib::Handle< QuantExt::CorrelationTermStructure > correlationCurve(const std::string &index1, const std::string &index2)
std::string getEqCcy(const IndexInfo &e)
std::vector< QuantLib::ext::shared_ptr< GeneralizedBlackScholesProcess > > processes_
Pricing Engine Factory.
@ data
Definition: log.hpp:77
interface for model against which a script can be run
interface for model against which a script can be run
QuantLib::ext::shared_ptr< ASTNode > ASTNodePtr
Definition: ast.hpp:46
Serializable Credit Default Swap.
Definition: namespaces.docs:23
scripted instrument
scripted trade data model
some utility functions
static script analyser