|
27 | 27 | #include <orea/app/reportwriter.hpp> |
28 | 28 | #include <orea/app/structuredanalyticserror.hpp> |
29 | 29 | #include <orea/app/structuredanalyticswarning.hpp> |
| 30 | +#include <orea/cube/overlaynpvcube.hpp> |
30 | 31 | #include <orea/cube/jointnpvcube.hpp> |
31 | 32 | #include <orea/cube/npvcube.hpp> |
32 | 33 | #include <orea/cube/sparsenpvcube.hpp> |
@@ -93,6 +94,13 @@ void XvaAnalyticImpl::buildDependencies() { |
93 | 94 | if (correlationAnalytic.second) |
94 | 95 | addDependentAnalytic(corrLookupKey, correlationAnalytic.second); |
95 | 96 | } |
| 97 | + if (inputs_->cubeNpvOverlay()) { |
| 98 | + if (auto pricingAnalytic = |
| 99 | + AnalyticFactory::instance().build("PRICING", inputs_, analytic()->analyticsManager(), false); |
| 100 | + pricingAnalytic.second) { |
| 101 | + addDependentAnalytic("PRICING", pricingAnalytic.second); |
| 102 | + } |
| 103 | + } |
96 | 104 | } |
97 | 105 |
|
98 | 106 | void XvaAnalyticImpl::feedCorrelationToCAM(const std::map<std::pair<RiskFactorKey, RiskFactorKey>, Real>& corrData){ |
@@ -969,6 +977,21 @@ void XvaAnalyticImpl::runAnalytic(const QuantLib::ext::shared_ptr<ore::data::InM |
969 | 977 | Settings::instance().includeReferenceDateEvents() = localIncRefDateEvents; |
970 | 978 | LOG("Simulation IncludeReferenceDateEvents is set to " << (localIncRefDateEvents ? "true" : "false")); |
971 | 979 |
|
| 980 | + std::map<std::string, double> cubeNpvOverlay; |
| 981 | + if (inputs_->cubeNpvOverlay()) { |
| 982 | + auto pricingAnalytic = dependentAnalytic("PRICING"); |
| 983 | + static_cast<PricingAnalyticImpl*>(pricingAnalytic->impl().get()) |
| 984 | + ->overwriteResultCurrency(analytic()->configurations().simMarketParams->baseCcy()); |
| 985 | + pricingAnalytic->runAnalytic(loader,{"NPV"}); |
| 986 | + auto npvReport = pricingAnalytic->reports().at("NPV").at("npv"); |
| 987 | + std::size_t colTradeId = npvReport->columnPosition("TradeId"); |
| 988 | + std::size_t colNpvBase = npvReport->columnPosition("NPV(Base)"); |
| 989 | + for (Size r = 0; r < npvReport->rows(); ++r) { |
| 990 | + cubeNpvOverlay[boost::get<std::string>(npvReport->data(colTradeId, r))] = |
| 991 | + boost::get<double>(npvReport->data(colNpvBase, r)); |
| 992 | + } |
| 993 | + } |
| 994 | + |
972 | 995 | if(inputs_->generateCorrelations()){ |
973 | 996 | auto corrAnalytic = dependentAnalytic(corrLookupKey); |
974 | 997 | corrAnalytic->runAnalytic(loader,{"CORRELATION"}); |
@@ -1108,11 +1131,19 @@ void XvaAnalyticImpl::runAnalytic(const QuantLib::ext::shared_ptr<ore::data::InM |
1108 | 1131 | LOG("We have generated an AMC cube only"); |
1109 | 1132 | cube_ = amcCube_; |
1110 | 1133 | } else { |
1111 | | - WLOG("We have generated a classic cube only"); |
| 1134 | + LOG("We have generated a classic cube only"); |
1112 | 1135 | } |
1113 | 1136 |
|
1114 | 1137 | LOG("NPV cube generation completed"); |
1115 | 1138 |
|
| 1139 | + /************************************************************ |
| 1140 | + * Apply correction pricing t0 npv - sim t0 npv if requested |
| 1141 | + ************************************************************/ |
| 1142 | + |
| 1143 | + if (!cubeNpvOverlay.empty()) { |
| 1144 | + cube_ = QuantLib::ext::make_shared<OverlayNPVCube>(cube_, cubeNpvOverlay); |
| 1145 | + } |
| 1146 | + |
1116 | 1147 | /*********************************************************************** |
1117 | 1148 | * We may have two non-empty portfolios to be merged for post processing |
1118 | 1149 | ***********************************************************************/ |
|
0 commit comments