Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
multithreadedvaluationengine.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2022 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/*! \file engine/multithreadedvaluationengine.hpp
20 \brief multi-threaded valuation engine
21 \ingroup engine
22*/
23
24#pragma once
25
30
33
34namespace ore {
35namespace analytics {
36
38public:
39 /* if no cube factories are given, we create default ones as follows
40 - cubeFactory : creates DoublePrecisionInMemoryCube
41 - nettingSetCubeFactory: creates nullptr
42 - cptyCubeFactory: creates nullptr */
44 const QuantLib::Size nThreads, const QuantLib::Date& today,
45 const QuantLib::ext::shared_ptr<ore::analytics::DateGrid>& dateGrid, const QuantLib::Size nSamples,
46 const QuantLib::ext::shared_ptr<ore::data::Loader>& loader,
47 const QuantLib::ext::shared_ptr<ore::analytics::ScenarioGenerator>& scenarioGenerator,
48 const QuantLib::ext::shared_ptr<ore::data::EngineData>& engineData,
49 const QuantLib::ext::shared_ptr<ore::data::CurveConfigurations>& curveConfigs,
50 const QuantLib::ext::shared_ptr<ore::data::TodaysMarketParameters>& todaysMarketParams,
51 const std::string& configuration,
52 const QuantLib::ext::shared_ptr<ore::analytics::ScenarioSimMarketParameters>& simMarketData,
53 const bool useSpreadedTermStructures = false, const bool cacheSimData = false,
54 const QuantLib::ext::shared_ptr<ore::analytics::ScenarioFilter>& scenarioFilter =
55 QuantLib::ext::make_shared<ore::analytics::ScenarioFilter>(),
56 const QuantLib::ext::shared_ptr<ore::data::ReferenceDataManager>& referenceData = nullptr,
58 const bool handlePseudoCurrenciesTodaysMarket = true, const bool handlePseudoCurrenciesSimMarket = true,
59 const bool recalibrateModels = true,
60 const std::function<QuantLib::ext::shared_ptr<ore::analytics::NPVCube>(
61 const QuantLib::Date&, const std::set<std::string>&, const std::vector<QuantLib::Date>&,
62 const QuantLib::Size)>& cubeFactory = {},
63 const std::function<QuantLib::ext::shared_ptr<ore::analytics::NPVCube>(
64 const QuantLib::Date&, const std::vector<QuantLib::Date>&, const QuantLib::Size)>& nettingSetCubeFactory =
65 {},
66 const std::function<QuantLib::ext::shared_ptr<ore::analytics::NPVCube>(
67 const QuantLib::Date&, const std::set<std::string>&, const std::vector<QuantLib::Date>&,
68 const QuantLib::Size)>& cptyCubeFactory = {},
69 const std::string& context = "unspecified",
70 const QuantLib::ext::shared_ptr<ore::analytics::Scenario>& offSetScenario = nullptr);
71
72 // can be optionally called to set the agg scen data (which is done in the ssm for single-threaded runs)
73 void setAggregationScenarioData(const QuantLib::ext::shared_ptr<AggregationScenarioData>& aggregationScenarioData);
74
75 /* analoguous to buildCube() in the single-threaded engine, results are retrieved using below constructors
76 if no cptyCalculators is given a function returning an empty vector of calculators will be returned */
77 void
78 buildCube(const QuantLib::ext::shared_ptr<ore::data::Portfolio>& portfolio,
79 const std::function<std::vector<QuantLib::ext::shared_ptr<ore::analytics::ValuationCalculator>>()>& calculators,
80 const std::function<std::vector<QuantLib::ext::shared_ptr<ore::analytics::CounterpartyCalculator>>()>&
81 cptyCalculators = {},
82 bool mporStickyDate = true, bool dryRun = false);
83
84 // result output cubes (mini-cubes, one per thread)
85 std::vector<QuantLib::ext::shared_ptr<ore::analytics::NPVCube>> outputCubes() const { return miniCubes_; }
86
87 // result netting cubes (might be null, if nettingSetCubeFactory is returning null)
88 std::vector<QuantLib::ext::shared_ptr<ore::analytics::NPVCube>> outputNettingSetCubes() const {
90 }
91
92 // result cpty cubes (might be null, if cptyCubeFactory is returning null)
93 std::vector<QuantLib::ext::shared_ptr<ore::analytics::NPVCube>> outputCptyCubes() const { return miniCptyCubes_; }
94
95private:
96 QuantLib::Size nThreads_;
97 QuantLib::Date today_;
98 QuantLib::ext::shared_ptr<ore::data::DateGrid> dateGrid_;
99 QuantLib::Size nSamples_;
100 QuantLib::ext::shared_ptr<ore::data::Loader> loader_;
101 QuantLib::ext::shared_ptr<ore::analytics::ScenarioGenerator> scenarioGenerator_;
102 QuantLib::ext::shared_ptr<ore::data::EngineData> engineData_;
103 QuantLib::ext::shared_ptr<ore::data::CurveConfigurations> curveConfigs_;
104 QuantLib::ext::shared_ptr<ore::data::TodaysMarketParameters> todaysMarketParams_;
105 std::string configuration_;
106 QuantLib::ext::shared_ptr<ore::analytics::ScenarioSimMarketParameters> simMarketData_;
109 QuantLib::ext::shared_ptr<ore::analytics::ScenarioFilter> scenarioFilter_;
110 QuantLib::ext::shared_ptr<ore::data::ReferenceDataManager> referenceData_;
115 std::function<QuantLib::ext::shared_ptr<ore::analytics::NPVCube>(const QuantLib::Date&, const std::set<std::string>&,
116 const std::vector<QuantLib::Date>&, const QuantLib::Size)>
118 std::function<QuantLib::ext::shared_ptr<ore::analytics::NPVCube>(const QuantLib::Date&, const std::vector<QuantLib::Date>&,
119 const QuantLib::Size)>
121 std::function<QuantLib::ext::shared_ptr<ore::analytics::NPVCube>(const QuantLib::Date&, const std::set<std::string>&,
122 const std::vector<QuantLib::Date>&, const QuantLib::Size)>
124 std::string context_;
125 QuantLib::ext::shared_ptr<ore::analytics::Scenario> offsetScenario_;
126 QuantLib::ext::shared_ptr<AggregationScenarioData>
128 std::vector<QuantLib::ext::shared_ptr<ore::analytics::NPVCube>> miniCubes_;
129 std::vector<QuantLib::ext::shared_ptr<ore::analytics::NPVCube>> miniNettingSetCubes_;
130 std::vector<QuantLib::ext::shared_ptr<ore::analytics::NPVCube>> miniCptyCubes_;
131};
132
133} // namespace analytics
134} // namespace ore
QuantLib::ext::shared_ptr< ore::data::CurveConfigurations > curveConfigs_
QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > todaysMarketParams_
QuantLib::ext::shared_ptr< ore::analytics::Scenario > offsetScenario_
std::vector< QuantLib::ext::shared_ptr< ore::analytics::NPVCube > > miniNettingSetCubes_
std::function< QuantLib::ext::shared_ptr< ore::analytics::NPVCube >(const QuantLib::Date &, const std::vector< QuantLib::Date > &, const QuantLib::Size)> nettingSetCubeFactory_
std::vector< QuantLib::ext::shared_ptr< ore::analytics::NPVCube > > miniCubes_
QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarketParameters > simMarketData_
std::vector< QuantLib::ext::shared_ptr< ore::analytics::NPVCube > > outputCubes() const
void setAggregationScenarioData(const QuantLib::ext::shared_ptr< AggregationScenarioData > &aggregationScenarioData)
std::vector< QuantLib::ext::shared_ptr< ore::analytics::NPVCube > > outputCptyCubes() const
QuantLib::ext::shared_ptr< ore::data::DateGrid > dateGrid_
QuantLib::ext::shared_ptr< AggregationScenarioData > aggregationScenarioData_
QuantLib::ext::shared_ptr< ore::data::ReferenceDataManager > referenceData_
QuantLib::ext::shared_ptr< ore::analytics::ScenarioFilter > scenarioFilter_
std::function< QuantLib::ext::shared_ptr< ore::analytics::NPVCube >(const QuantLib::Date &, const std::set< std::string > &, const std::vector< QuantLib::Date > &, const QuantLib::Size)> cptyCubeFactory_
std::vector< QuantLib::ext::shared_ptr< ore::analytics::NPVCube > > miniCptyCubes_
QuantLib::ext::shared_ptr< ore::data::Loader > loader_
std::vector< QuantLib::ext::shared_ptr< ore::analytics::NPVCube > > outputNettingSetCubes() const
void buildCube(const QuantLib::ext::shared_ptr< ore::data::Portfolio > &portfolio, const std::function< std::vector< QuantLib::ext::shared_ptr< ore::analytics::ValuationCalculator > >()> &calculators, const std::function< std::vector< QuantLib::ext::shared_ptr< ore::analytics::CounterpartyCalculator > >()> &cptyCalculators={}, bool mporStickyDate=true, bool dryRun=false)
std::function< QuantLib::ext::shared_ptr< ore::analytics::NPVCube >(const QuantLib::Date &, const std::set< std::string > &, const std::vector< QuantLib::Date > &, const QuantLib::Size)> cubeFactory_
QuantLib::ext::shared_ptr< ore::analytics::ScenarioGenerator > scenarioGenerator_
QuantLib::ext::shared_ptr< ore::data::EngineData > engineData_
static IborFallbackConfig defaultConfig()
Scenario generator base classes.
A Market class that can be updated by Scenarios.
A class to hold Scenario parameters for scenarioSimMarket.
vector< string > curveConfigs
The cube valuation core.