Historical Scenario Generator. More...
#include <orea/scenario/historicalscenariogenerator.hpp>
Classes | |
struct | HistoricalScenarioCalculationDetails |
Public Member Functions | |
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. More... | |
HistoricalScenarioGenerator (const boost::shared_ptr< HistoricalScenarioLoader > &historicalScenarioLoader, const boost::shared_ptr< ScenarioFactory > &scenarioFactory, const boost::shared_ptr< ore::data::AdjustmentFactors > &adjFactors=nullptr, const ReturnConfiguration &returnConfiguration=ReturnConfiguration(), const std::string &labelPrefix="") | |
Constructor with no mporDays/Calendar, construct historical shift scenario between each scneario. More... | |
QuantLib::ext::shared_ptr< Scenario > & | baseScenario () |
Set base scenario, this also defines the asof date. More... | |
const QuantLib::ext::shared_ptr< Scenario > & | baseScenario () const |
Get base scenario. More... | |
const QuantLib::Calendar & | cal () const |
Get calendar. More... | |
QuantLib::Size | mporDays () const |
Get mpor days. More... | |
bool | overlapping () const |
Are scenarios overlapping. More... | |
const ReturnConfiguration & | returnConfiguration () const |
Return configuration. More... | |
virtual QuantLib::Real | scaling (const RiskFactorKey &key, const QuantLib::Real &keyReturn) |
Scaling. More... | |
QuantLib::ext::shared_ptr< Scenario > | next (const QuantLib::Date &d) override |
Return the next scenario for the given date. More... | |
const std::vector< HistoricalScenarioCalculationDetails > & | lastHistoricalScenarioCalculationDetails () const |
Return the calculation details of the last generated scenario */. More... | |
void | reset () override |
Reset the generator so calls to next() return the first scenario. More... | |
virtual QuantLib::Size | numScenarios () const |
Number of scenarios this generator can generate. More... | |
virtual void | setDates () |
set the start and end dates, can be overwritten in derived class More... | |
const std::vector< QuantLib::Date > & | startDates () const |
start dates from which the scenarios were generated from More... | |
const std::vector< QuantLib::Date > & | endDates () const |
end dates from which the scenarios were generated from More... | |
const QuantLib::ext::shared_ptr< HistoricalScenarioLoader > & | scenarioLoader () const |
Get the HistoricalScenarioLoader. More... | |
const QuantLib::ext::shared_ptr< ScenarioFactory > & | scenarioFactory () const |
Get the ScenarioFactory. More... | |
const QuantLib::ext::shared_ptr< ore::data::AdjustmentFactors > & | adjFactors () const |
Get the adj factors. More... | |
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. More... | |
const std::string & | labelPrefix () const |
Get the scenario label prefix. More... | |
Public Member Functions inherited from ScenarioGenerator | |
virtual | ~ScenarioGenerator () |
Default destructor. More... | |
virtual QuantLib::ext::shared_ptr< Scenario > | next (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... | |
Protected Member Functions | |
std::pair< QuantLib::ext::shared_ptr< Scenario >, QuantLib::ext::shared_ptr< Scenario > > | scenarioPair () |
The Scenario Pairs for a given index. More... | |
QuantLib::Real | adjustedPrice (RiskFactorKey key, QuantLib::Date d, QuantLib::Real price) |
Returns the adjusted price. More... | |
Protected Attributes | |
Size | i_ |
QuantLib::ext::shared_ptr< HistoricalScenarioLoader > | historicalScenarioLoader_ |
std::vector< QuantLib::Date > | startDates_ |
std::vector< QuantLib::Date > | endDates_ |
QuantLib::ext::shared_ptr< ScenarioFactory > | scenarioFactory_ |
QuantLib::ext::shared_ptr< Scenario > | baseScenario_ |
std::vector< HistoricalScenarioCalculationDetails > | calculationDetails_ |
QuantLib::Calendar | cal_ |
QuantLib::Size | mporDays_ = 10 |
Private Attributes | |
QuantLib::ext::shared_ptr< ore::data::AdjustmentFactors > | adjFactors_ |
bool | overlapping_ = true |
ReturnConfiguration | returnConfiguration_ |
std::string | labelPrefix_ |
Historical Scenario Generator.
A Scenario Generator that takes historical scenarios and builds new scenarios by applying historical shifts to the base scenario (which typically comes from todays market).
This generator can be used for historical VAR and backtesting calculations, unlike a PRNG based generator it is limited in the number of scenarios it can generate.
The scenarios generated are based on the scenario differences between t and t+mpor, these differences are typically a relative change and this change is then applied to the baseScenario to give a new scenario which is asof Today or Today+mpor.
Definition at line 85 of file historicalscenariogenerator.hpp.
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.
historicalScenarioLoader | Historical Scenario Loader containing all scenarios |
scenarioFactory | Scenario factory to use |
cal | Calendar to use |
adjFactors | optional adjustment factors for stock splits etc |
mporDays | Mpor days or step size |
overlapping | overlapping scenarios |
returnConfiguration | return configuration |
labelPrefix | string prepended to label of all scenarios generated |
Definition at line 166 of file historicalscenariogenerator.cpp.
HistoricalScenarioGenerator | ( | const boost::shared_ptr< HistoricalScenarioLoader > & | historicalScenarioLoader, |
const boost::shared_ptr< ScenarioFactory > & | scenarioFactory, | ||
const boost::shared_ptr< ore::data::AdjustmentFactors > & | adjFactors = nullptr , |
||
const ReturnConfiguration & | returnConfiguration = ReturnConfiguration() , |
||
const std::string & | labelPrefix = "" |
||
) |
Constructor with no mporDays/Calendar, construct historical shift scenario between each scneario.
QuantLib::ext::shared_ptr< Scenario > & baseScenario | ( | ) |
Set base scenario, this also defines the asof date.
Definition at line 136 of file historicalscenariogenerator.hpp.
const QuantLib::ext::shared_ptr< Scenario > & baseScenario | ( | ) | const |
const QuantLib::Calendar & cal | ( | ) | const |
QuantLib::Size mporDays | ( | ) | const |
Get mpor days.
Definition at line 143 of file historicalscenariogenerator.hpp.
bool overlapping | ( | ) | const |
const ReturnConfiguration & returnConfiguration | ( | ) | const |
|
virtual |
Scaling.
Definition at line 151 of file historicalscenariogenerator.hpp.
|
override |
Return the next scenario for the given date.
Date should be asof or asof+mporDays, this class only checks that date is >= the asof date. Whatever you put in here will be in the returned scenario.
Generator returns scenarios in order of shifts and throws if we have run out of historicals
If Mpor > 1 than the scenarios will overlap.
Definition at line 253 of file historicalscenariogenerator.cpp.
const std::vector< HistoricalScenarioGenerator::HistoricalScenarioCalculationDetails > & lastHistoricalScenarioCalculationDetails | ( | ) | const |
Return the calculation details of the last generated scenario */.
Definition at line 321 of file historicalscenariogenerator.cpp.
|
overridevirtual |
Reset the generator so calls to next() return the first scenario.
This allows re-generation of scenarios if required.
Implements ScenarioGenerator.
Reimplemented in HistoricalScenarioGeneratorRandom, and HistoricalScenarioGeneratorWithFilteredDates.
Definition at line 168 of file historicalscenariogenerator.hpp.
|
virtual |
Number of scenarios this generator can generate.
Definition at line 325 of file historicalscenariogenerator.cpp.
|
virtual |
set the start and end dates, can be overwritten in derived class
Definition at line 189 of file historicalscenariogenerator.cpp.
const std::vector< QuantLib::Date > & startDates | ( | ) | const |
start dates from which the scenarios were generated from
Definition at line 177 of file historicalscenariogenerator.hpp.
const std::vector< QuantLib::Date > & endDates | ( | ) | const |
end dates from which the scenarios were generated from
Definition at line 179 of file historicalscenariogenerator.hpp.
const QuantLib::ext::shared_ptr< HistoricalScenarioLoader > & scenarioLoader | ( | ) | const |
const QuantLib::ext::shared_ptr< ScenarioFactory > & scenarioFactory | ( | ) | const |
const QuantLib::ext::shared_ptr< ore::data::AdjustmentFactors > & adjFactors | ( | ) | const |
std::vector< std::pair< Date, Date > > filteredScenarioDates | ( | const ore::data::TimePeriod & | period | ) | const |
Get (start, end) scenario date pairs filtered on the given period.
Definition at line 330 of file historicalscenariogenerator.cpp.
const std::string & labelPrefix | ( | ) | const |
|
protected |
The Scenario Pairs for a given index.
Definition at line 234 of file historicalscenariogenerator.cpp.
|
protected |
Returns the adjusted price.
Scenarios may contian unadjusted market prices e.g equity spot prices, apply adjustment factors to ensure no jumps between 2 scenarios Only handles equity spot adjustments at the moment
Definition at line 243 of file historicalscenariogenerator.cpp.
|
protected |
Definition at line 198 of file historicalscenariogenerator.hpp.
|
protected |
Definition at line 200 of file historicalscenariogenerator.hpp.
|
protected |
Definition at line 201 of file historicalscenariogenerator.hpp.
|
protected |
Definition at line 201 of file historicalscenariogenerator.hpp.
|
protected |
Definition at line 203 of file historicalscenariogenerator.hpp.
|
protected |
Definition at line 204 of file historicalscenariogenerator.hpp.
|
protected |
Definition at line 216 of file historicalscenariogenerator.hpp.
|
protected |
Definition at line 219 of file historicalscenariogenerator.hpp.
|
protected |
Definition at line 220 of file historicalscenariogenerator.hpp.
|
private |
Definition at line 223 of file historicalscenariogenerator.hpp.
|
private |
Definition at line 224 of file historicalscenariogenerator.hpp.
|
private |
Definition at line 225 of file historicalscenariogenerator.hpp.
|
private |
Definition at line 226 of file historicalscenariogenerator.hpp.