Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
historicalscenariogenerator.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 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
26
27#include <boost/algorithm/string/find.hpp>
28
29using namespace QuantLib;
30
31namespace ore {
32namespace analytics {
33
35 : // Default Configuration for risk factor returns
36 // For all yield curves we have DFs in the Scenario, for credit we have SurvProbs,
37 // so a relative / log change is equivalent to an absolute zero / hazard rate change.
62
63ReturnConfiguration::ReturnConfiguration(const std::map<RiskFactorKey::KeyType, ReturnType>& returnType)
64 : returnType_(returnType) {}
65
66Real ReturnConfiguration::returnValue(const RiskFactorKey& key, const Real v1, const Real v2, const QuantLib::Date& d1,
67 const QuantLib::Date& d2) const {
68
69 // Checks
70 check(key);
71
72 // Calculate the return
73 auto keyType = key.keytype;
74 switch (returnType_.at(keyType)) {
76 return v2 - v1;
77 break;
79 if (!close(v1, 0)) {
80 return v2 / v1 - 1.0;
81 } else {
82 ALOG("Cannot calculate the relative return for key " << key << " so just returning 0: (" << d1 << "," << v1
83 << ") to (" << d2 << "," << v2 << ")");
84 return 0.0;
85 }
86 break;
88 if (!close(v1, 0) && v2 / v1 > 0) {
89 return std::log(v2 / v1);
90 } else {
91 ALOG("Cannot calculate the relative return for key " << key << " so just returning 0: (" << d1 << "," << v1
92 << ") to (" << d2 << "," << v2 << ")");
93 return 0.0;
94 }
95 break;
96 default:
97 QL_FAIL("ReturnConfiguration: return type not covered for key " << key << ".");
98 }
99}
100
101Real ReturnConfiguration::applyReturn(const RiskFactorKey& key, const Real baseValue, const Real returnValue) const {
102
103 // Checks
104 check(key);
105
106 // Apply the return to the base value to generate the return value
107 auto keyType = key.keytype;
108 Real value;
109 switch (returnType_.at(keyType)) {
111 value = baseValue + returnValue;
112 break;
114 value = baseValue * (1.0 + returnValue);
115 break;
117 value = baseValue * std::exp(returnValue);
118 break;
119 default:
120 QL_FAIL("ReturnConfiguration: return type for key " << key << " not covered");
121 }
122
123 // Apply cap / floors to guarantee admissable values
125 (value > 1.0 || value < -1.0)) {
126 DLOG("Base correlation value, " << value << ", is not in range [-1.0, 1.0]");
127 value = std::max(std::min(value, 1.0), -1.0);
128 DLOG("Base correlation value amended to " << value);
129 }
130
132 && (value > 1.0 || value < 0.0)) {
133 DLOG("Value of risk factor " << key << ", " << value << ", is not in range [0.0, 1.0]");
134 value = std::max(std::min(value, 1.0), 0.0);
135 DLOG("Value of risk factor " << key << " amended to " << value);
136 }
137
138 return value;
139}
140
141const std::map<RiskFactorKey::KeyType, ReturnConfiguration::ReturnType> ReturnConfiguration::returnTypes() const {
142 return returnType_;
143}
144
145std::ostream& operator<<(std::ostream& out, const ReturnConfiguration::ReturnType t) {
146 switch (t) {
148 return out << "Absolute";
150 return out << "Relative";
152 return out << "Log";
153 default:
154 return out << "Unknown ReturnType (" << static_cast<int>(t) << ")";
155 }
156}
157
159
160 auto keyType = key.keytype;
161 QL_REQUIRE(keyType != RiskFactorKey::KeyType::None, "unsupported key type none for key " << key);
162 QL_REQUIRE(returnType_.find(keyType) != returnType_.end(),
163 "ReturnConfiguration: key type " << keyType << " for key " << key << " not found");
164}
165
167 const QuantLib::ext::shared_ptr<HistoricalScenarioLoader>& historicalScenarioLoader,
168 const QuantLib::ext::shared_ptr<ScenarioFactory>& scenarioFactory, const QuantLib::Calendar& cal,
169 const QuantLib::ext::shared_ptr<ore::data::AdjustmentFactors>& adjFactors, const Size mporDays,
170 const bool overlapping, const ReturnConfiguration& returnConfiguration,
171 const std::string& labelPrefix)
172 : i_(0), historicalScenarioLoader_(historicalScenarioLoader), scenarioFactory_(scenarioFactory),
173 cal_(cal), mporDays_(mporDays), adjFactors_(adjFactors), overlapping_(overlapping),
174 returnConfiguration_(returnConfiguration), labelPrefix_(labelPrefix) {
175
176 QL_REQUIRE(mporDays > 0, "Invalid mpor days of 0");
177 QL_REQUIRE(historicalScenarioLoader_->numScenarios() > 1,
178 "HistoricalScenarioGenerator: require more than 1 scenario from historicalScenarioLoader_");
179
180 // check they are in order and all before the base scenario
181 // we do not make any assumptions here about the length
182 for (Size i = 1; i < historicalScenarioLoader_->numScenarios(); ++i) {
183 QL_REQUIRE(historicalScenarioLoader_->dates()[i] > historicalScenarioLoader_->dates()[i - 1],
184 "historical scenarios are not ordered");
185 }
186 setDates();
187}
188
190 // construct the vectors of start and end dates
191 for (Size i = 0; i < historicalScenarioLoader_->numScenarios();) {
192 Date sDate = historicalScenarioLoader_->dates()[i];
193 Date eDate = cal_.advance(sDate, mporDays_ * Days);
194 auto it =
195 std::find(historicalScenarioLoader_->dates().begin(), historicalScenarioLoader_->dates().end(), eDate);
196 if (it != historicalScenarioLoader_->dates().end()) {
197 startDates_.push_back(sDate);
198 endDates_.push_back(eDate);
199 }
200 if (overlapping_) {
201 ++i;
202 } else {
203 if (it != historicalScenarioLoader_->dates().end()) {
204 i = std::distance(historicalScenarioLoader_->dates().begin(), it);
205 } else {
206 i = std::distance(historicalScenarioLoader_->dates().begin(),
207 std::upper_bound(historicalScenarioLoader_->dates().begin(),
208 historicalScenarioLoader_->dates().end(), eDate));
209 }
210 }
211 }
212}
213
215 const boost::shared_ptr<HistoricalScenarioLoader>& historicalScenarioLoader,
216 const boost::shared_ptr<ScenarioFactory>& scenarioFactory,
217 const QuantLib::ext::shared_ptr<ore::data::AdjustmentFactors>& adjFactors,
218 const ReturnConfiguration& returnConfiguration, const std::string& labelPrefix)
219 : i_(0), historicalScenarioLoader_(historicalScenarioLoader), scenarioFactory_(scenarioFactory),
220 adjFactors_(adjFactors), returnConfiguration_(returnConfiguration), labelPrefix_(labelPrefix) {
221
222 QL_REQUIRE(historicalScenarioLoader_->numScenarios() > 1,
223 "HistoricalScenarioGenerator: require more than 1 scenario from historicalScenarioLoader_");
224
225 // check they are in order and all before the base scenario and add the dates
226 for (Size i = 1; i < historicalScenarioLoader_->numScenarios(); ++i) {
227 QL_REQUIRE(historicalScenarioLoader_->dates()[i] > historicalScenarioLoader_->dates()[i - 1],
228 "historical scenarios are not ordered");
229 startDates_.push_back(historicalScenarioLoader_->dates()[i - 1]);
230 endDates_.push_back(historicalScenarioLoader_->dates()[i]);
231 }
232}
233
234std::pair<QuantLib::ext::shared_ptr<Scenario>, QuantLib::ext::shared_ptr<Scenario>> HistoricalScenarioGenerator::scenarioPair() {
235 // Get the two historicals we are using
236 QL_REQUIRE(i_ < numScenarios(),
237 "Cannot generate any more scenarios (i=" << i_ << " numScenarios=" << numScenarios() << ")");
238 QuantLib::ext::shared_ptr<Scenario> s1 = historicalScenarioLoader_->getHistoricalScenario(startDates_[i_]);
239 QuantLib::ext::shared_ptr<Scenario> s2 = historicalScenarioLoader_->getHistoricalScenario(endDates_[i_]);
240 return std::pair<QuantLib::ext::shared_ptr<Scenario>, QuantLib::ext::shared_ptr<Scenario>>(s1, s2);
241}
242
244 if (adjFactors_) {
246 // uses the ORE Fixing name convention
247 return price * adjFactors_->getFactor(key.name, d);
248 }
249 }
250 return price;
251}
252
253QuantLib::ext::shared_ptr<Scenario> HistoricalScenarioGenerator::next(const Date& d) {
254
255 QL_REQUIRE(baseScenario_ != nullptr, "HistoricalScenarioGenerator: base scenario not set");
256
257 std::pair<QuantLib::ext::shared_ptr<Scenario>, QuantLib::ext::shared_ptr<Scenario>> scens = scenarioPair();
258 QuantLib::ext::shared_ptr<Scenario> s1 = scens.first;
259 QuantLib::ext::shared_ptr<Scenario> s2 = scens.second;
260
261 // build the scenarios
262 QL_REQUIRE(d >= baseScenario_->asof(), "Cannot generate a scenario in the past");
263 QuantLib::ext::shared_ptr<Scenario> scen = scenarioFactory_->buildScenario(d, true, std::string(), 1.0);
264
265 // loop over all keys
266 calculationDetails_.resize(baseScenario_->keys().size());
267 Size calcDetailsCounter = 0;
268 for (auto const& key : baseScenario_->keys()) {
269 Real base = baseScenario_->get(key);
270 Real v1 = 1.0, v2 = 1.0;
271 if (!s1->has(key) || !s2->has(key)) {
272 DLOG("Missing key in historical scenario (" << io::iso_date(s1->asof()) << "," << io::iso_date(s2->asof())
273 << "): " << key << " => no move in this factor");
274 } else {
275 v1 = adjustedPrice(key, s1->asof(), s1->get(key));
276 v2 = adjustedPrice(key, s2->asof(), s2->get(key));
277 }
278 Real value = 0.0;
279
280 // Calculate the returned value
281 Real returnVal = returnConfiguration_.returnValue(key, v1, v2, s1->asof(), s2->asof());
282 // Adjust return for any scaling
283 Real scaling = this->scaling(key, returnVal);
284 returnVal = returnVal * scaling;
285 // Calculate the shifted value
286 value = returnConfiguration_.applyReturn(key, base, returnVal);
287 if (std::isinf(value)) {
288 ALOG("Value is inf for " << key << " from date " << s1->asof() << " to " << s2->asof());
289 }
290 // Add it
291 scen->add(key, value);
292 // Populate calculation details
293 calculationDetails_[calcDetailsCounter].scenarioDate1 = s1->asof();
294 calculationDetails_[calcDetailsCounter].scenarioDate2 = s2->asof();
295 calculationDetails_[calcDetailsCounter].key = key;
296 calculationDetails_[calcDetailsCounter].baseValue = base;
297 calculationDetails_[calcDetailsCounter].adjustmentFactor1 =
298 adjFactors_ ? adjFactors_->getFactor(key.name, s1->asof()) : 1.0;
299 calculationDetails_[calcDetailsCounter].adjustmentFactor2 =
300 adjFactors_ ? adjFactors_->getFactor(key.name, s2->asof()) : 1.0;
301 calculationDetails_[calcDetailsCounter].scenarioValue1 = v1;
302 calculationDetails_[calcDetailsCounter].scenarioValue2 = v2;
303 calculationDetails_[calcDetailsCounter].returnType = returnConfiguration_.returnTypes().at(key.keytype);
304 calculationDetails_[calcDetailsCounter].scaling = scaling;
305 calculationDetails_[calcDetailsCounter].returnValue = returnVal;
306 calculationDetails_[calcDetailsCounter].scenarioValue = value;
307 ++calcDetailsCounter;
308 }
309
310 // Label the scenario
311 string label = labelPrefix_ + ore::data::to_string(io::iso_date(s1->asof())) + "_" +
312 ore::data::to_string(io::iso_date(s2->asof()));
313 scen->label(label);
314
315 // return it.
316 ++i_;
317 return scen;
318}
319
320const std::vector<HistoricalScenarioGenerator::HistoricalScenarioCalculationDetails>&
322 return calculationDetails_;
323}
324
326 // We have a start date for each valid scenario
327 return startDates_.size();
328}
329
330std::vector<std::pair<Date, Date>> HistoricalScenarioGenerator::filteredScenarioDates(const TimePeriod& period) const {
331 std::vector<std::pair<Date, Date>> result;
332 for (Size s = 0; s < startDates_.size(); ++s) {
333 if (period.contains(startDates_[s]) && period.contains(endDates_[s])) {
334 result.push_back(std::make_pair(startDates_[s], endDates_[s]));
335 }
336 }
337 return result;
338}
339
340QuantLib::ext::shared_ptr<Scenario> HistoricalScenarioGeneratorRandom::next(const Date& d) {
341
342 QL_REQUIRE(baseScenario() != nullptr, "HistoricalScenarioGeneratorRandom: base scenario not set");
343
344 // build the scenarios
345 QL_REQUIRE(d >= baseScenario()->asof(),
346 "HistoricalScenarioGeneratorRandom: Cannot generate a scenario in the past");
347 QuantLib::ext::shared_ptr<Scenario> scen = scenarioFactory_->buildScenario(d, true, std::string(), 1.0);
348
349 // loop over all keys
350 for (auto key : baseScenario()->keys()) {
351 Real base = baseScenario()->get(key);
352 Real value = 0.0;
353 switch (key.keytype) {
359 if (close_enough(base, 0.0))
360 value = 0.0;
361 else
362 value = 1.0 - (1.0 - base) * (1.0 + normalrng_->next().value * 0.05);
363 break;
366 value = base + (normalrng_->next().value * 0.0010);
367 break;
377 value = base * (1.0 + normalrng_->next().value * 0.02);
378 break;
380 value = base + (normalrng_->next().value * 0.05);
381 value = std::max(std::min(value, 0.9999), -0.9999);
382 break;
383 default:
384 QL_FAIL("HistoricalScenarioGeneratorRandom: unexpected key type in key " << key);
385 }
386 scen->add(key, value);
387 }
388
389 // return it.
390 ++i_;
391 return scen;
392}
393
396 normalrng_ = QuantLib::ext::make_shared<QuantLib::PseudoRandom::rng_type>(MersenneTwisterUniformRng(42));
397}
398
399QuantLib::ext::shared_ptr<Scenario> HistoricalScenarioGeneratorTransform::next(const Date& d) {
400 QuantLib::ext::shared_ptr<Scenario> scenario = HistoricalScenarioGenerator::next(d)->clone();
401 const vector<RiskFactorKey>& keys = baseScenario()->keys();
402 Date asof = baseScenario()->asof();
403 vector<Period> tenors;
404 Date endDate;
405 DayCounter dc;
406
407 for (Size k = 0; k < keys.size(); ++k) {
408 if ((keys[k].keytype == RiskFactorKey::KeyType::DiscountCurve) ||
409 (keys[k].keytype == RiskFactorKey::KeyType::IndexCurve) ||
410 (keys[k].keytype == RiskFactorKey::KeyType::SurvivalProbability)) {
411 if ((keys[k].keytype == RiskFactorKey::KeyType::DiscountCurve)) {
412 dc = simMarket_->discountCurve(keys[k].name)->dayCounter();
413 tenors = simMarketConfig_->yieldCurveTenors(keys[k].name);
414 } else if (keys[k].keytype == RiskFactorKey::KeyType::IndexCurve) {
415 dc = simMarket_->iborIndex(keys[k].name)->dayCounter();
416 tenors = simMarketConfig_->yieldCurveTenors(keys[k].name);
417 } else if (keys[k].keytype == RiskFactorKey::KeyType::SurvivalProbability) {
418 dc = simMarket_->defaultCurve(keys[k].name)->curve()->dayCounter();
419 tenors = simMarketConfig_->defaultTenors(keys[k].name);
420 }
421
422 endDate = asof + tenors[keys[k].index];
423
424 auto toZero = [&dc, &asof, &endDate](double compound) {
425 return InterestRate::impliedRate(compound, dc, QuantLib::Compounding::Continuous,
426 QuantLib::Frequency::Annual, asof, endDate)
427 .rate();
428 };
429
430 Real zero = toZero(1.0 / scenario->get(keys[k]));
431 scenario->add(keys[k], zero);
432 // update calc details
433 calculationDetails_[k].baseValue = toZero(1.0 / calculationDetails_[k].baseValue);
434 calculationDetails_[k].scenarioValue1 = toZero(1.0 / calculationDetails_[k].scenarioValue1);
435 calculationDetails_[k].scenarioValue2 = toZero(1.0 / calculationDetails_[k].scenarioValue2);
437 calculationDetails_[k].returnValue =
438 calculationDetails_[k].scaling *
439 (calculationDetails_[k].scenarioValue2 - calculationDetails_[k].scenarioValue1);
440 calculationDetails_[k].scenarioValue = toZero(1.0 / calculationDetails_[k].scenarioValue);
441 }
442 }
443 return scenario;
444}
445
447 const std::vector<TimePeriod>& filter, const QuantLib::ext::shared_ptr<HistoricalScenarioGenerator>& gen)
449 gen_(gen), i_orig_(0) {
450
451 // set base scenario
452
453 baseScenario_ = gen->baseScenario();
454
455 for (auto const& f : filter) {
456 // Check that backtest and benchmark periods are covered by the historical scenario generator
457 Date minDate = *std::min_element(f.startDates().begin(), f.startDates().end());
458 Date maxDate = *std::max_element(f.endDates().begin(), f.endDates().end());
459
460 QL_REQUIRE(startDates_.front() <= minDate && maxDate <= endDates_.back(),
461 "The backtesting period " << f << " is not covered by the historical scenario generator: Required dates = ["
462 << ore::data::to_string(minDate) << "," << ore::data::to_string(maxDate)
463 << "], Covered dates = [" << startDates_.front() << "," << endDates_.back() << "]");
464 }
465
466 // filter start / end dates on relevant scenarios
467
468 isRelevantScenario_ = std::vector<bool>(gen->numScenarios(), false);
469
470 std::vector<Date> newStartDates, newEndDates;
471
472 for (Size i = 0; i < startDates_.size(); ++i) {
473 isRelevantScenario_[i] = false;
474 for (auto const& f : filter) {
475 if (f.contains(startDates_[i]) && f.contains(endDates_[i]))
476 isRelevantScenario_[i] = true;
477 }
478 if (isRelevantScenario_[i]) {
479 newStartDates.push_back(startDates_[i]);
480 newEndDates.push_back(endDates_[i]);
481 }
482 }
483
484 startDates_ = newStartDates;
485 endDates_ = newEndDates;
486}
487
489 gen_->reset();
491 i_orig_ = 0;
492}
493
494QuantLib::ext::shared_ptr<Scenario> HistoricalScenarioGeneratorWithFilteredDates::next(const Date& d) {
495 while (i_orig_ < gen_->numScenarios() && !isRelevantScenario_[i_orig_]) {
496 gen_->next(d);
497 ++i_orig_;
498 }
499 QL_REQUIRE(i_orig_ < gen_->numScenarios(),
500 "HistoricalScenarioGeneratorWithFilteredDates:next(): no more scenarios available");
501 ++i_orig_;
502 return gen_->next(d);
503}
504
505QuantLib::ext::shared_ptr<HistoricalScenarioGenerator> buildHistoricalScenarioGenerator(
506 const QuantLib::ext::shared_ptr<HistoricalScenarioReader>& hsr,
507 const QuantLib::ext::shared_ptr<ore::data::AdjustmentFactors>& adjFactors, const TimePeriod& period,
508 Calendar calendar, Size mporDays,
509 const QuantLib::ext::shared_ptr<ScenarioSimMarketParameters>& simParams,
510 const QuantLib::ext::shared_ptr<TodaysMarketParameters>& marketParams, const bool overlapping) {
511
512 hsr->load(simParams, marketParams);
513
514 auto scenarioFactory = QuantLib::ext::make_shared<SimpleScenarioFactory>(true);
515
516 QuantLib::ext::shared_ptr<HistoricalScenarioLoader> scenarioLoader = QuantLib::ext::make_shared<HistoricalScenarioLoader>(
517 hsr, period.startDates().front(), period.endDates().front(), calendar);
518
519 // Create the historical scenario generator
520 return QuantLib::ext::make_shared<HistoricalScenarioGenerator>(scenarioLoader, scenarioFactory, calendar, adjFactors,
521 mporDays, overlapping, ReturnConfiguration(), "hs_");
522}
523
524QuantLib::ext::shared_ptr<HistoricalScenarioGenerator> buildHistoricalScenarioGenerator(
525 const QuantLib::ext::shared_ptr<HistoricalScenarioReader>& hsr,
526 const QuantLib::ext::shared_ptr<ore::data::AdjustmentFactors>& adjFactors, const std::set<QuantLib::Date>& dates,
527 const QuantLib::ext::shared_ptr<ScenarioSimMarketParameters>& simParams,
528 const QuantLib::ext::shared_ptr<TodaysMarketParameters>& marketParams) {
529
530 hsr->load(simParams, marketParams);
531
532 auto scenarioFactory = QuantLib::ext::make_shared<SimpleScenarioFactory>();
533
534 QuantLib::ext::shared_ptr<HistoricalScenarioLoader> scenarioLoader =
535 QuantLib::ext::make_shared<HistoricalScenarioLoader>(
536 hsr, dates);
537
538 // Create the historical scenario generator
539 return QuantLib::ext::make_shared<HistoricalScenarioGenerator>(scenarioLoader, scenarioFactory,
540 adjFactors, ReturnConfiguration(), "hs_");
541}
542
543} // namespace analytics
544} // namespace ore
virtual void setDates()
set the start and end dates, can be overwritten in derived class
std::vector< HistoricalScenarioCalculationDetails > calculationDetails_
QuantLib::ext::shared_ptr< Scenario > baseScenario_
QuantLib::ext::shared_ptr< HistoricalScenarioLoader > historicalScenarioLoader_
QuantLib::ext::shared_ptr< Scenario > next(const QuantLib::Date &d) override
Return the next scenario for the given date.
QuantLib::ext::shared_ptr< ore::data::AdjustmentFactors > adjFactors_
const std::vector< HistoricalScenarioCalculationDetails > & lastHistoricalScenarioCalculationDetails() const
Return the calculation details of the last generated scenario *‍/.
virtual QuantLib::Real scaling(const RiskFactorKey &key, const QuantLib::Real &keyReturn)
Scaling.
QuantLib::ext::shared_ptr< Scenario > & baseScenario()
Set base scenario, this also defines the asof date.
HistoricalScenarioGenerator(const QuantLib::ext::shared_ptr< HistoricalScenarioLoader > &historicalScenarioLoader, const QuantLib::ext::shared_ptr< ScenarioFactory > &scenarioFactory, const QuantLib::Calendar &cal, const QuantLib::ext::shared_ptr< ore::data::AdjustmentFactors > &adjFactors=nullptr, const Size mporDays=10, const bool overlapping=true, const ReturnConfiguration &returnConfiguration=ReturnConfiguration(), const std::string &labelPrefix="")
Default constructor.
virtual QuantLib::Size numScenarios() const
Number of scenarios this generator can generate.
std::vector< std::pair< QuantLib::Date, QuantLib::Date > > filteredScenarioDates(const ore::data::TimePeriod &period) const
Get (start, end) scenario date pairs filtered on the given period.
QuantLib::ext::shared_ptr< ScenarioFactory > scenarioFactory_
QuantLib::Real adjustedPrice(RiskFactorKey key, QuantLib::Date d, QuantLib::Real price)
Returns the adjusted price.
std::pair< QuantLib::ext::shared_ptr< Scenario >, QuantLib::ext::shared_ptr< Scenario > > scenarioPair()
The Scenario Pairs for a given index.
void reset() override
Reset the generator so calls to next() return the first scenario.
QuantLib::ext::shared_ptr< Scenario > next(const QuantLib::Date &d) override
void reset() override
Reset the generator so calls to next() return the first scenario.
QuantLib::ext::shared_ptr< QuantLib::PseudoRandom::rng_type > normalrng_
QuantLib::ext::shared_ptr< ScenarioSimMarketParameters > simMarketConfig_
QuantLib::ext::shared_ptr< ScenarioSimMarket > simMarket_
QuantLib::ext::shared_ptr< Scenario > next(const QuantLib::Date &d) override
HistoricalScenarioGeneratorWithFilteredDates(const std::vector< ore::data::TimePeriod > &filter, const QuantLib::ext::shared_ptr< HistoricalScenarioGenerator > &gen)
QuantLib::ext::shared_ptr< Scenario > next(const QuantLib::Date &d) override
QuantLib::ext::shared_ptr< HistoricalScenarioGenerator > gen_
void reset() override
Reset the generator so calls to next() return the first scenario.
Return type for historical scenario generation (absolute, relative, log)
const std::map< RiskFactorKey::KeyType, ReturnType > returnType_
QuantLib::Real applyReturn(const RiskFactorKey &key, const QuantLib::Real baseValue, const QuantLib::Real returnValue) const
apply return from v1, v2 to base value
ReturnConfiguration()
default return types per risk factor
const std::map< RiskFactorKey::KeyType, ReturnType > returnTypes() const
get return types
void check(const RiskFactorKey &key) const
Perform checks on key.
QuantLib::Real returnValue(const RiskFactorKey &key, const QuantLib::Real v1, const QuantLib::Real v2, const QuantLib::Date &d1, const QuantLib::Date &d2) const
Data types stored in the scenario class.
Definition: scenario.hpp:48
KeyType keytype
Key type.
Definition: scenario.hpp:89
std::string name
Key name.
Definition: scenario.hpp:94
const std::vector< Date > & endDates() const
const std::vector< Date > & startDates() const
bool contains(const Date &d) const
SafeStack< ValueType > value
SafeStack< Filter > filter
scenario generator that builds from historical shifts
#define DLOG(text)
#define ALOG(text)
Calendar calendar
Filter close_enough(const RandomVariable &x, const RandomVariable &y)
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
bool close(const Real &t_1, const Real &t_2)
QuantLib::ext::shared_ptr< HistoricalScenarioGenerator > buildHistoricalScenarioGenerator(const QuantLib::ext::shared_ptr< HistoricalScenarioReader > &hsr, const QuantLib::ext::shared_ptr< ore::data::AdjustmentFactors > &adjFactors, const TimePeriod &period, Calendar calendar, Size mporDays, const QuantLib::ext::shared_ptr< ScenarioSimMarketParameters > &simParams, const QuantLib::ext::shared_ptr< TodaysMarketParameters > &marketParams, const bool overlapping)
std::string to_string(const LocationInfo &l)
Simple scenario class.
factory classes for simple scenarios
Date asof(14, Jun, 2018)
string name