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

Scenario Generator using LGM model paths. More...

#include <orea/scenario/lgmscenariogenerator.hpp>

+ Inheritance diagram for LgmScenarioGenerator:
+ Collaboration diagram for LgmScenarioGenerator:

Public Member Functions

 LgmScenarioGenerator (QuantLib::ext::shared_ptr< QuantExt::LGM > model, QuantLib::ext::shared_ptr< QuantExt::MultiPathGeneratorBase > multiPathGenerator, QuantLib::ext::shared_ptr< ScenarioFactory > scenarioFactory, QuantLib::ext::shared_ptr< ScenarioSimMarketParameters > simMarketConfig, Date today, DateGrid grid)
 Constructor. More...
 
 ~LgmScenarioGenerator ()
 Destructor. More...
 
std::vector< QuantLib::ext::shared_ptr< Scenario > > nextPath () override
 
void reset () override
 Reset the generator so calls to next() return the first scenario. More...
 
- Public Member Functions inherited from ScenarioPathGenerator
 ScenarioPathGenerator (Date today, const vector< Date > &dates, TimeGrid timeGrid)
 Constructor. More...
 
virtual QuantLib::ext::shared_ptr< Scenarionext (const Date &d) override
 Return the next scenario for the given date. 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

QuantLib::ext::shared_ptr< QuantExt::LGMmodel_
 
QuantLib::ext::shared_ptr< QuantExt::MultiPathGeneratorBasepathGenerator_
 
QuantLib::ext::shared_ptr< ScenarioFactoryscenarioFactory_
 
QuantLib::ext::shared_ptr< ScenarioSimMarketParameterssimMarketConfig_
 

Additional Inherited Members

virtual std::vector< QuantLib::ext::shared_ptr< Scenario > > nextPath ()=0
 
- Protected Attributes inherited from ScenarioPathGenerator
Date today_
 
vector< Date > dates_
 
Size pathStep_
 
TimeGrid timeGrid_
 
std::vector< QuantLib::ext::shared_ptr< Scenario > > path_
 

Detailed Description

Scenario Generator using LGM model paths.

The generator expects

Definition at line 50 of file lgmscenariogenerator.hpp.

Constructor & Destructor Documentation

◆ LgmScenarioGenerator()

LgmScenarioGenerator ( QuantLib::ext::shared_ptr< QuantExt::LGM model,
QuantLib::ext::shared_ptr< QuantExt::MultiPathGeneratorBase multiPathGenerator,
QuantLib::ext::shared_ptr< ScenarioFactory scenarioFactory,
QuantLib::ext::shared_ptr< ScenarioSimMarketParameters simMarketConfig,
Date  today,
DateGrid  grid 
)

Constructor.

Definition at line 26 of file lgmscenariogenerator.cpp.

31 : ScenarioPathGenerator(today, grid.dates(), grid.timeGrid()), model_(model), pathGenerator_(pathGenerator),
32 scenarioFactory_(scenarioFactory), simMarketConfig_(simMarketConfig) {
33 QL_REQUIRE(timeGrid_.size() == dates_.size() + 1, "date/time grid size mismatch");
34}
QuantLib::ext::shared_ptr< ScenarioSimMarketParameters > simMarketConfig_
QuantLib::ext::shared_ptr< QuantExt::MultiPathGeneratorBase > pathGenerator_
QuantLib::ext::shared_ptr< ScenarioFactory > scenarioFactory_
QuantLib::ext::shared_ptr< QuantExt::LGM > model_
ScenarioPathGenerator(Date today, const vector< Date > &dates, TimeGrid timeGrid)
Constructor.

◆ ~LgmScenarioGenerator()

Destructor.

Definition at line 58 of file lgmscenariogenerator.hpp.

58{};

Member Function Documentation

◆ nextPath()

std::vector< QuantLib::ext::shared_ptr< Scenario > > nextPath ( )
overridevirtual

Implements ScenarioPathGenerator.

Definition at line 36 of file lgmscenariogenerator.cpp.

36 {
37 std::vector<QuantLib::ext::shared_ptr<Scenario>> scenarios(dates_.size());
38 Sample<MultiPath> sample = pathGenerator_->next();
39
40 DayCounter dc = model_->parametrization()->termStructure()->dayCounter();
41
42 std::string ccy = model_->parametrization()->currency().code();
43 vector<RiskFactorKey> keys;
44 for (Size k = 0; k < simMarketConfig_->yieldCurveTenors(ccy).size(); k++)
45 keys.emplace_back(RiskFactorKey::KeyType::DiscountCurve, ccy, k);
46
47 for (Size i = 0; i < dates_.size(); i++) {
48 Real t = timeGrid_[i + 1]; // recall: time grid has inserted t=0
49
50 scenarios[i] = scenarioFactory_->buildScenario(dates_[i], true);
51
52 // Set numeraire, numeraire currency and the (deterministic) domestic discount
53 // Asset index 0 in sample.value[0][i+1] refers to the domestic currency process,
54 // the only one here.
55 Real z0 = sample.value[0][i + 1]; // second index = 0 holds initial values
56 scenarios[i]->setNumeraire(model_->numeraire(t, z0));
57
58 Real z = sample.value[0][i + 1]; // LGM factor value, second index = 0 holds initial values
59 for (Size k = 0; k < simMarketConfig_->yieldCurveTenors(ccy).size(); k++) {
60 Date d = dates_[i] + simMarketConfig_->yieldCurveTenors(ccy)[k];
61 Real T = dc.yearFraction(dates_[i], d);
62 Real discount = model_->discountBond(t, t + T, z);
63 scenarios[i]->add(keys[k], discount);
64 }
65 }
66 return scenarios;
67}
Size size(const ValueType &v)
+ Here is the call graph for this function:

◆ 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 60 of file lgmscenariogenerator.hpp.

60{ pathGenerator_->reset(); }

Member Data Documentation

◆ model_

QuantLib::ext::shared_ptr<QuantExt::LGM> model_
private

Definition at line 63 of file lgmscenariogenerator.hpp.

◆ pathGenerator_

QuantLib::ext::shared_ptr<QuantExt::MultiPathGeneratorBase> pathGenerator_
private

Definition at line 64 of file lgmscenariogenerator.hpp.

◆ scenarioFactory_

QuantLib::ext::shared_ptr<ScenarioFactory> scenarioFactory_
private

Definition at line 65 of file lgmscenariogenerator.hpp.

◆ simMarketConfig_

QuantLib::ext::shared_ptr<ScenarioSimMarketParameters> simMarketConfig_
private

Definition at line 66 of file lgmscenariogenerator.hpp.