35 Date
asof,
const string& baseCurrency,
const QuantLib::ext::shared_ptr<Portfolio>& portfolio,
36 const QuantLib::ext::shared_ptr<NettingSetManager>& netting,
37 const QuantLib::ext::shared_ptr<CollateralBalances>& collateralBalances,
38 const QuantLib::ext::shared_ptr<EngineData>& engineData,
39 const QuantLib::ext::shared_ptr<CurveConfigurations>& curveConfigs,
40 const QuantLib::ext::shared_ptr<TodaysMarketParameters>& todaysMarketParams,
41 const QuantLib::ext::shared_ptr<ScenarioSimMarketParameters>& simMarketData,
42 const QuantLib::ext::shared_ptr<ScenarioGeneratorData>& scenarioGeneratorData,
43 const QuantLib::ext::shared_ptr<CrossAssetModelData>& crossAssetModelData,
44 const QuantLib::ext::shared_ptr<ReferenceDataManager>& referenceData,
45 const IborFallbackConfig& iborFallbackConfig, Real dimQuantile, Size dimHorizonCalendarDays,
46 map<string, bool> analytics,
string calculationType,
string dvaName,
string fvaBorrowingCurve,
47 string fvaLendingCurve,
bool fullInitialCollateralisation,
bool storeFlows)
48 : inputs_(inputs), asof_(
asof), baseCurrency_(baseCurrency), portfolio_(portfolio), netting_(netting),
49 collateralBalances_(collateralBalances), engineData_(engineData),
50 curveConfigs_(
curveConfigs), todaysMarketParams_(todaysMarketParams), simMarketData_(simMarketData),
51 scenarioGeneratorData_(scenarioGeneratorData), crossAssetModelData_(crossAssetModelData),
52 referenceData_(referenceData), iborFallbackConfig_(iborFallbackConfig), dimQuantile_(dimQuantile),
53 dimHorizonCalendarDays_(dimHorizonCalendarDays), analytics_(analytics), inputCalculationType_(calculationType),
54 dvaName_(dvaName), fvaBorrowingCurve_(fvaBorrowingCurve), fvaLendingCurve_(fvaLendingCurve),
55 fullInitialCollateralisation_(fullInitialCollateralisation), storeFlows_(storeFlows) {
58 WLOG(
"post processor analytics not set, using defaults");
66QuantLib::ext::shared_ptr<ScenarioSimMarketParameters>
68 QL_FAIL(
"XvaRunner::projectSsmData() is only available in ORE+");
71QuantLib::ext::shared_ptr<ore::analytics::ScenarioGenerator>
73 const QuantLib::ext::shared_ptr<Market>& market,
74 const QuantLib::ext::shared_ptr<ScenarioSimMarketParameters>& projectedSsmData,
75 const QuantLib::ext::shared_ptr<ScenarioFactory>& sf,
const bool continueOnErr)
const {
76 QL_REQUIRE(!currencyFilter,
77 "XvaRunner::getProjectedScenarioGenerator() with currency filter is only available in ORE+");
84 LOG(
"XvaRunner::buildCamModel() called");
86 Settings::instance().evaluationDate() =
asof_;
96 LOG(
"XvaRunner::bufferSimulationPaths() called");
98 auto stateProcess =
model_->stateProcess();
99 if (
auto tmp = QuantLib::ext::dynamic_pointer_cast<CrossAssetStateProcess>(stateProcess)) {
108 bufferedPaths_ = QuantLib::ext::make_shared<std::vector<std::vector<Path>>>(
113 const MultiPath& path = pathGen->next().value;
114 for (Size d = 0; d < stateProcess->size(); ++d) {
115 (*bufferedPaths_)[p][d] = path[d];
119 LOG(
"XvaRunner::bufferSimulationPaths() finished");
123 const boost::optional<std::set<std::string>>& currencyFilter,
const bool continueOnErr) {
124 LOG(
"XvaRunner::buildSimMarket() called");
126 Settings::instance().evaluationDate() =
asof_;
128 QuantLib::ext::shared_ptr<ScenarioSimMarketParameters> projectedSsmData;
129 if (currencyFilter) {
136 QuantLib::ext::shared_ptr<ScenarioFactory> sf = QuantLib::ext::make_shared<SimpleScenarioFactory>(
true);
137 QuantLib::ext::shared_ptr<ScenarioGenerator> sg =
144 DLOG(
"build scenario data");
146 scenarioData_.linkTo(QuantLib::ext::make_shared<InMemoryAggregationScenarioData>(
150 auto ed = QuantLib::ext::make_shared<EngineData>(*
engineData_);
151 ed->globalParameters()[
"RunType"] =
"Exposure";
158 LOG(
"XvaRunner::buildCube called");
160 Settings::instance().evaluationDate() =
asof_;
162 QuantLib::ext::shared_ptr<Portfolio> portfolio = QuantLib::ext::make_shared<Portfolio>();
164 for (
auto const& t : *tradeIds) {
165 QL_REQUIRE(
portfolio_->has(t),
"XvaRunner::buildCube(): portfolio does not contain trade with id '"
166 << t <<
"' specified in the filter");
173 DLOG(
"build portfolio");
177 for (
auto const& [tid, t] :
portfolio_->trades()) {
187 DLOG(
"build calculators");
189 std::vector<QuantLib::ext::shared_ptr<ValuationCalculator>> calculators;
190 QuantLib::ext::shared_ptr<NPVCalculator> npvCalculator = QuantLib::ext::make_shared<NPVCalculator>(
baseCurrency_);
197 calculators.push_back(QuantLib::ext::make_shared<MPORCalculator>(npvCalculator,
cubeInterpreter_->defaultDateNpvIndex(),
201 ALOG(
"Forcing calculation type " <<
calculationType_ <<
" for simulations with close-out grid");
208 calculators.push_back(QuantLib::ext::make_shared<CashflowCalculator>(
214 calculators.push_back(npvCalculator);
218 DLOG(
"get netting cube");
222 DLOG(
"run valuation engine");
229 const QuantLib::ext::shared_ptr<NPVCube>& npvCube,
230 const QuantLib::ext::shared_ptr<NPVCube>& nettingCube,
231 const QuantLib::ext::shared_ptr<AggregationScenarioData>& scenarioData,
232 const bool continueOnErr,
233 const std::map<std::string, QuantLib::Real>& currentIM) {
235 LOG(
"XvaRunner::generatePostProcessor called");
237 QL_REQUIRE(
analytics_.size() > 0,
"analytics map not set");
239 QuantLib::ext::shared_ptr<DynamicInitialMarginCalculator> dimCalculator =
250 const std::map<std::string, QuantLib::Real>& currentIM) {
252 LOG(
"XvaRunner::runXva called");
261 const QuantLib::ext::shared_ptr<NPVCube>& cube,
const QuantLib::ext::shared_ptr<CubeInterpretation>& cubeInterpreter,
262 const QuantLib::ext::shared_ptr<AggregationScenarioData>& scenarioData,
263 const QuantLib::ext::shared_ptr<QuantExt::CrossAssetModel>& model,
const QuantLib::ext::shared_ptr<NPVCube>& nettingCube,
264 const std::map<std::string, QuantLib::Real>& currentIM) {
266 QuantLib::ext::shared_ptr<DynamicInitialMarginCalculator> dimCalculator;
267 Size dimRegressionOrder = 0;
268 vector<string> dimRegressors;
269 Size dimLocalRegressionEvaluations = 0;
270 Real dimLocalRegressionBandwidth = 0.25;
272 dimCalculator = QuantLib::ext::make_shared<RegressionDynamicInitialMarginCalculator>(
274 dimRegressors, dimLocalRegressionEvaluations, dimLocalRegressionBandwidth, currentIM);
276 return dimCalculator;
281 std::set<std::string> nettingSetIds;
282 for (
auto const& [tradeId,trade] : portfolio ==
nullptr ?
portfolio_->trades() : portfolio->trades())
283 nettingSetIds.insert(trade->envelope().nettingSetId());
284 return nettingSetIds;
288 const std::vector<Date>& dates,
const Size samples,
289 const Size depth)
const {
291 return QuantLib::ext::make_shared<SinglePrecisionInMemoryCube>(
asof, ids, dates, samples, 0.0f);
293 return QuantLib::ext::make_shared<SinglePrecisionInMemoryCubeN>(
asof, ids, dates, samples, depth, 0.0f);
boost::shared_ptr< MultiPathGeneratorBase > build(const SequenceType s, const boost::shared_ptr< StochasticProcess > &process, const TimeGrid &timeGrid, const BigNatural seed, const SobolBrownianGenerator::Ordering ordering, const SobolRsg::DirectionIntegers directionIntegers) override
Build a ScenarioGenerator.
QuantLib::ext::shared_ptr< ScenarioGenerator > build(QuantLib::ext::shared_ptr< QuantExt::CrossAssetModel > model, QuantLib::ext::shared_ptr< ScenarioFactory > sf, QuantLib::ext::shared_ptr< ScenarioSimMarketParameters > marketConfig, Date asof, QuantLib::ext::shared_ptr< ore::data::Market > initMarket, const std::string &configuration=ore::data::Market::defaultConfiguration, const QuantLib::ext::shared_ptr< PathGeneratorFactory > &pf=QuantLib::ext::make_shared< MultiPathGeneratorFactory >())
Build function.
void buildCube(const QuantLib::ext::shared_ptr< data::Portfolio > &portfolio, QuantLib::ext::shared_ptr< analytics::NPVCube > outputCube, std::vector< QuantLib::ext::shared_ptr< ValuationCalculator > > calculators, bool mporStickyDate=true, QuantLib::ext::shared_ptr< analytics::NPVCube > outputCubeNettingSet=nullptr, QuantLib::ext::shared_ptr< analytics::NPVCube > outputCptyCube=nullptr, std::vector< QuantLib::ext::shared_ptr< CounterpartyCalculator > > cptyCalculators={}, bool dryRun=false)
Build NPV cube.
QuantLib::ext::shared_ptr< ore::data::CurveConfigurations > curveConfigs_
QuantLib::ext::shared_ptr< QuantExt::CrossAssetModel > model_
QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > todaysMarketParams_
string fvaBorrowingCurve_
QuantLib::Size dimHorizonCalendarDays_
std::string calculationType_
QuantLib::ext::shared_ptr< CubeInterpretation > cubeInterpreter_
std::string baseCurrency_
void bufferSimulationPaths()
bool fullInitialCollateralisation_
QuantLib::ext::shared_ptr< ScenarioSimMarket > simMarket_
XvaRunner(const QuantLib::ext::shared_ptr< InputParameters > &inputs, QuantLib::Date asof, const std::string &baseCurrency, const QuantLib::ext::shared_ptr< ore::data::Portfolio > &portfolio, const QuantLib::ext::shared_ptr< ore::data::NettingSetManager > &netting, const QuantLib::ext::shared_ptr< ore::data::CollateralBalances > &collateralBalances, const QuantLib::ext::shared_ptr< ore::data::EngineData > &engineData, const QuantLib::ext::shared_ptr< ore::data::CurveConfigurations > &curveConfigs, const QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > &todaysMarketParams, const QuantLib::ext::shared_ptr< ScenarioSimMarketParameters > &simMarketData, const QuantLib::ext::shared_ptr< ScenarioGeneratorData > &scenarioGeneratorData, const QuantLib::ext::shared_ptr< ore::data::CrossAssetModelData > &crossAssetModelData, const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceData=nullptr, const IborFallbackConfig &iborFallbackConfig=IborFallbackConfig::defaultConfig(), QuantLib::Real dimQuantile=0.99, QuantLib::Size dimHorizonCalendarDays=14, map< string, bool > analytics={}, string calculationType="Symmetric", string dvaName="", string fvaBorrowingCurve="", string fvaLendingCurve="", bool fullInitialCollateralisation=true, bool storeFlows=false)
QuantLib::ext::shared_ptr< std::vector< std::vector< QuantLib::Path > > > bufferedPaths_
QuantLib::RelinkableHandle< AggregationScenarioData > scenarioData_
void runXva(const QuantLib::ext::shared_ptr< ore::data::Market > &market, bool continueOnErr=true, const std::map< std::string, QuantLib::Real > ¤tIM=std::map< std::string, QuantLib::Real >())
virtual QuantLib::ext::shared_ptr< NPVCube > getNpvCube(const Date &asof, const std::set< std::string > &ids, const std::vector< Date > &dates, const Size samples, const Size depth) const
string inputCalculationType_
void buildCamModel(const QuantLib::ext::shared_ptr< ore::data::Market > &market, bool continueOnErr=true)
QuantLib::ext::shared_ptr< NPVCube > npvCube() const
map< string, bool > analytics_
QuantLib::ext::shared_ptr< ore::data::Portfolio > portfolio_
QuantLib::ext::shared_ptr< ScenarioGeneratorData > scenarioGeneratorData_
std::set< std::string > getNettingSetIds(const QuantLib::ext::shared_ptr< Portfolio > &portfolio=nullptr) const
void generatePostProcessor(const QuantLib::ext::shared_ptr< Market > &market, const QuantLib::ext::shared_ptr< NPVCube > &npvCube, const QuantLib::ext::shared_ptr< NPVCube > &nettingCube, const QuantLib::ext::shared_ptr< AggregationScenarioData > &scenarioData, const bool continueOnErr=true, const std::map< std::string, QuantLib::Real > ¤tIM=std::map< std::string, QuantLib::Real >())
void buildCube(const boost::optional< std::set< std::string > > &tradeIds, bool continueOnErr=true)
QuantLib::Real dimQuantile_
QuantLib::Handle< AggregationScenarioData > aggregationScenarioData()
QuantLib::ext::shared_ptr< EngineFactory > simFactory_
virtual QuantLib::ext::shared_ptr< NPVCube > getNettingSetCube(std::vector< QuantLib::ext::shared_ptr< ValuationCalculator > > &calculators, const QuantLib::ext::shared_ptr< Portfolio > &portfolio)
virtual void buildSimMarket(const QuantLib::ext::shared_ptr< ore::data::Market > &market, const boost::optional< std::set< std::string > > ¤cyFilter=boost::none, const bool continueOnErr=true)
QuantLib::ext::shared_ptr< ore::data::CrossAssetModelData > crossAssetModelData_
QuantLib::ext::shared_ptr< ScenarioSimMarketParameters > simMarketData_
IborFallbackConfig iborFallbackConfig_
QuantLib::ext::shared_ptr< ReferenceDataManager > referenceData_
QuantLib::ext::shared_ptr< NPVCube > nettingCube() const
virtual QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarketParameters > projectSsmData(const std::set< std::string > ¤cyFilter) const
QuantLib::ext::shared_ptr< PostProcess > postProcess_
virtual QuantLib::ext::shared_ptr< ore::analytics::ScenarioGenerator > getProjectedScenarioGenerator(const boost::optional< std::set< std::string > > ¤cyFilter, const QuantLib::ext::shared_ptr< Market > &market, const QuantLib::ext::shared_ptr< ScenarioSimMarketParameters > &projectedSsmData, const QuantLib::ext::shared_ptr< ScenarioFactory > &scenarioFactory, const bool continueOnErr) const
QuantLib::ext::shared_ptr< InputParameters > inputs_
QuantLib::ext::shared_ptr< ore::data::NettingSetManager > netting_
QuantLib::ext::shared_ptr< ore::data::CollateralBalances > collateralBalances_
QuantLib::ext::shared_ptr< NPVCube > cube_
virtual QuantLib::ext::shared_ptr< DynamicInitialMarginCalculator > getDimCalculator(const QuantLib::ext::shared_ptr< NPVCube > &cube, const QuantLib::ext::shared_ptr< CubeInterpretation > &cubeInterpreter, const QuantLib::ext::shared_ptr< AggregationScenarioData > &scenarioData, const QuantLib::ext::shared_ptr< QuantExt::CrossAssetModel > &model=nullptr, const QuantLib::ext::shared_ptr< NPVCube > &nettingCube=nullptr, const std::map< std::string, QuantLib::Real > ¤tIM=std::map< std::string, QuantLib::Real >())
QuantLib::ext::shared_ptr< NPVCube > nettingCube_
QuantLib::ext::shared_ptr< ore::data::EngineData > engineData_
Handle< QuantExt::CrossAssetModel > model() const
static const string defaultConfiguration
Dynamic Initial Margin calculator by regression.
The cube valuation calculator interface.
Build a scenariogenerator.
factory classes for simple scenarios
vector< string > curveConfigs
A class to run the xva analysis.