Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
ClonedScenarioGenerator Class Reference

#include <orea/scenario/clonedscenariogenerator.hpp>

+ Inheritance diagram for ClonedScenarioGenerator:
+ Collaboration diagram for ClonedScenarioGenerator:

Public Member Functions

 ClonedScenarioGenerator (const QuantLib::ext::shared_ptr< ScenarioGenerator > &scenarioGenerator, const std::vector< Date > &dates, const Size nSamples)
 
QuantLib::ext::shared_ptr< Scenarionext (const Date &d) override
 Return the next scenario for the given date. More...
 
virtual void reset () override
 Reset the generator so calls to next() return the first scenario. More...
 
- Public Member Functions inherited from ScenarioGenerator
virtual ~ScenarioGenerator ()
 Default destructor. More...
 
virtual QuantLib::ext::shared_ptr< Scenarionext (const Date &d)=0
 Return the next scenario for the given date. More...
 
virtual void reset ()=0
 Reset the generator so calls to next() return the first scenario. More...
 

Private Attributes

std::map< Date, size_t > dates_
 
Date firstDate_
 
Size nSim_ = 0
 
std::vector< QuantLib::ext::shared_ptr< Scenario > > scenarios_
 

Detailed Description

Definition at line 31 of file clonedscenariogenerator.hpp.

Constructor & Destructor Documentation

◆ ClonedScenarioGenerator()

ClonedScenarioGenerator ( const QuantLib::ext::shared_ptr< ScenarioGenerator > &  scenarioGenerator,
const std::vector< Date > &  dates,
const Size  nSamples 
)

Definition at line 26 of file clonedscenariogenerator.cpp.

27 {
28 DLOG("Build cloned scenario generator for " << dates.size() << " dates and " << nSamples << " samples.");
29 for (size_t i = 0; i < dates.size(); ++i) {
30 dates_[dates[i]] = i;
31 }
32 firstDate_ = dates.front();
33 scenarioGenerator->reset();
34 scenarios_.resize(nSamples * dates_.size());
35 for (Size i = 0; i < nSamples; ++i) {
36 for (Size j = 0; j < dates.size(); ++j) {
37 scenarios_[i * dates.size() + j] = scenarioGenerator->next(dates[j])->clone();
38 }
39 }
40}
std::vector< QuantLib::ext::shared_ptr< Scenario > > scenarios_
#define DLOG(text)

Member Function Documentation

◆ next()

QuantLib::ext::shared_ptr< Scenario > next ( const Date &  d)
overridevirtual

Return the next scenario for the given date.

Implements ScenarioGenerator.

Definition at line 42 of file clonedscenariogenerator.cpp.

42 {
43 if (d == firstDate_) { // new path
44 ++nSim_;
45 }
46 auto stepIdx = dates_.find(d);
47 QL_REQUIRE(stepIdx != dates_.end(), "ClonedScenarioGenerator::next(" << d << "): invalid date " << d);
48 size_t timePos = stepIdx->second;
49 size_t currentStep = (nSim_ - 1) * dates_.size() + timePos;
50 QL_REQUIRE(currentStep < scenarios_.size(),
51 "ClonedScenarioGenerator::next(" << d << "): no more scenarios stored.");
52 return scenarios_[currentStep];
53}

◆ reset()

void reset ( )
overridevirtual

Reset the generator so calls to next() return the first scenario.

This allows re-generation of scenarios if required.

Implements ScenarioGenerator.

Definition at line 55 of file clonedscenariogenerator.cpp.

55 {
56 nSim_ = 0;
57}

Member Data Documentation

◆ dates_

std::map<Date, size_t> dates_
private

Definition at line 39 of file clonedscenariogenerator.hpp.

◆ firstDate_

Date firstDate_
private

Definition at line 40 of file clonedscenariogenerator.hpp.

◆ nSim_

Size nSim_ = 0
private

Definition at line 41 of file clonedscenariogenerator.hpp.

◆ scenarios_

std::vector<QuantLib::ext::shared_ptr<Scenario> > scenarios_
private

Definition at line 42 of file clonedscenariogenerator.hpp.