44 {
45
47 return;
48
49 Settings::instance().evaluationDate() =
inputs_->asof();
51 ObservationMode::instance().setMode(
inputs_->observationModel());
52
53 QL_REQUIRE(
inputs_->portfolio(),
"PnlAnalytic::run: No portfolio loaded.");
54 QL_REQUIRE(
inputs_->portfolio()->size() > 0,
"PnlAnalytic::run: Portfolio is empty.");
55
56 std::string effectiveResultCurrency =
58
59
60
61
62
63
64
66
67
68
69
70
71
72
73
74 QL_REQUIRE(
analytic()->configurations().simMarketParams,
"scenario sim market parameters not set");
75 QL_REQUIRE(
analytic()->configurations().todaysMarketParams,
"today's market parameters not set");
76
77 auto simMarket = QuantLib::ext::make_shared<ScenarioSimMarket>(
79 *
analytic()->configurations().curveConfig, *
analytic()->configurations().todaysMarketParams,
81 auto sgen = QuantLib::ext::make_shared<StaticScenarioGenerator>();
82 simMarket->scenarioGenerator() = sgen;
83
86
87 boost::shared_ptr<InMemoryReport> t0NpvReport = boost::make_shared<InMemoryReport>();
88 ReportWriter(
inputs_->reportNaString())
89 .writeNpv(*t0NpvReport, effectiveResultCurrency,
analytic()->market(),
inputs_->marketConfig(
"pricing"),
92
93 if (
inputs_->outputAdditionalResults()) {
94 CONSOLEW(
"Pricing: Additional t0 Results");
95 boost::shared_ptr<InMemoryReport> t0AddReport = boost::make_shared<InMemoryReport>();
96 ReportWriter(
inputs_->reportNaString())
97 .writeAdditionalResultsReport(*t0AddReport,
analytic()->portfolio(),
analytic()->market(),
98 effectiveResultCurrency);
101 }
102
103
104
105
106
107
108
109 boost::shared_ptr<InMemoryReport> t0CashFlowReport = boost::make_shared<InMemoryReport>();
110 string marketConfig =
inputs_->marketConfig(
"pricing");
111 ReportWriter(
inputs_->reportNaString())
112 .writeCashflow(*t0CashFlowReport, effectiveResultCurrency,
analytic()->portfolio(),
114 marketConfig,
inputs_->includePastCashflows());
116
117
118
119
120
121
122
123
124
125
126 Settings::instance().evaluationDate() =
mporDate();
127
128
130 mporAnalytic->configurations().asofDate =
mporDate();
133
134
135 mporAnalytic->runAnalytic(loader);
136
137
138 Settings::instance().evaluationDate() =
inputs_->asof();
139
140 QuantLib::ext::shared_ptr<Scenario> asofBaseScenario = simMarket->baseScenarioAbsolute();
141 auto sai = static_cast<ScenarioAnalyticImpl*>(mporAnalytic->impl().get());
142 QuantLib::ext::shared_ptr<Scenario> mporBaseScenario = sai->scenarioSimMarket()->baseScenarioAbsolute();
143
144 QuantLib::ext::shared_ptr<ore::analytics::Scenario>
t0Scenario =
147
148
149
150 QuantLib::ext::shared_ptr<ore::analytics::Scenario>
t1Scenario =
153
154
155
156
157
158
159
160
162 simMarket->update(simMarket->asofDate());
164
165
167
168
170
171 QuantLib::ext::shared_ptr<InMemoryReport> t0NpvLaggedReport = QuantLib::ext::make_shared<InMemoryReport>();
172 ReportWriter(
inputs_->reportNaString())
173 .writeNpv(*t0NpvLaggedReport, effectiveResultCurrency,
analytic()->market(),
inputs_->marketConfig(
"pricing"),
175
176 if (
inputs_->outputAdditionalResults()) {
177 CONSOLEW(
"Pricing: Additional Results, t0 lagged");
178 boost::shared_ptr<InMemoryReport> t0LaggedAddReport = boost::make_shared<InMemoryReport>();
179 ReportWriter(
inputs_->reportNaString())
180 .writeAdditionalResultsReport(*t0LaggedAddReport,
analytic()->portfolio(),
analytic()->market(),
181 effectiveResultCurrency);
184 }
186
187
188
189
190
191
192
193
195 Settings::instance().evaluationDate() = d1;
197 auto simMarket1 = sai->scenarioSimMarket();
198 auto sgen1 = QuantLib::ext::make_shared<StaticScenarioGenerator>();
201 simMarket1->scenarioGenerator() = sgen1;
202 simMarket1->update(d1);
204
205 QuantLib::ext::shared_ptr<InMemoryReport> t1NpvLaggedReport = QuantLib::ext::make_shared<InMemoryReport>();
206 ReportWriter(
inputs_->reportNaString())
207 .writeNpv(*t1NpvLaggedReport, effectiveResultCurrency,
analytic()->market(),
inputs_->marketConfig(
"pricing"),
209
211
212 if (
inputs_->outputAdditionalResults()) {
213 CONSOLEW(
"Pricing: Additional Results t1");
214 boost::shared_ptr<InMemoryReport> t1AddReport = boost::make_shared<InMemoryReport>();
215 ReportWriter(
inputs_->reportNaString())
216 .writeAdditionalResultsReport(*t1AddReport,
analytic()->portfolio(),
analytic()->market(),
217 effectiveResultCurrency);
220 }
221
222
223
224
225
226
227
228
229 sgen1->setScenario(sai->scenarioSimMarket()->baseScenario());
230 simMarket1->scenarioGenerator() = sgen1;
231 simMarket1->update(d1);
233
234 QuantLib::ext::shared_ptr<InMemoryReport> t1NpvReport = QuantLib::ext::make_shared<InMemoryReport>();
235 ReportWriter(
inputs_->reportNaString())
236 .writeNpv(*t1NpvReport, effectiveResultCurrency,
analytic()->market(),
inputs_->marketConfig(
"pricing"),
238
240
241 if (
inputs_->outputAdditionalResults()) {
242 CONSOLEW(
"Pricing: Additional t1 Results");
243 boost::shared_ptr<InMemoryReport> t1AddReport = boost::make_shared<InMemoryReport>();
244 ReportWriter(
inputs_->reportNaString())
245 .writeAdditionalResultsReport(*t1AddReport,
analytic()->portfolio(),
analytic()->market(),
246 effectiveResultCurrency);
249 }
250
251
252
253
254
255
256
257
258 QuantLib::ext::shared_ptr<InMemoryReport> pnlReport = QuantLib::ext::make_shared<InMemoryReport>();
259 ReportWriter(
inputs_->reportNaString())
260 .writePnlReport(*pnlReport, t0NpvReport, t0NpvLaggedReport, t1NpvLaggedReport, t1NpvReport,
264
265
266
267
268
269
270
271 boost::shared_ptr<InMemoryReport> t0ScenarioReport = boost::make_shared<InMemoryReport>();
272 auto t0sw = ScenarioWriter(nullptr, t0ScenarioReport);
273 t0sw.writeScenario(asofBaseScenario, true);
275
276 boost::shared_ptr<InMemoryReport> t1ScenarioReport = boost::make_shared<InMemoryReport>();
277 auto t1sw = ScenarioWriter(nullptr, t1ScenarioReport);
278 t1sw.writeScenario(mporBaseScenario, true);
280}
Analytic * analytic() const
const std::string & label() const
QuantLib::ext::shared_ptr< T > dependentAnalytic(const std::string &key) const
analytic_reports & reports()
Result reports.
Configurations & configurations()
virtual void modifyPortfolio()
virtual void buildMarket(const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader, const bool marketRequired=true)
void setMarket(const QuantLib::ext::shared_ptr< ore::data::Market > &market)
virtual void buildPortfolio()
const QuantLib::ext::shared_ptr< ore::analytics::Scenario > & t1Scenario() const
void setT1Scenario(const QuantLib::ext::shared_ptr< ore::analytics::Scenario > &scenario)
void setT0Scenario(const QuantLib::ext::shared_ptr< ore::analytics::Scenario > &scenario)
const QuantLib::Date & mporDate() const
bool useSpreadedTermStructures() const
const QuantLib::ext::shared_ptr< ore::analytics::Scenario > & t0Scenario() const
Real getDifferenceScenario(const RiskFactorKey::KeyType keyType, const Real v1, const Real v2)
QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > todaysMarketParams
QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarketParameters > simMarketParams