#include <orea/engine/historicalpnlgenerator.hpp>
Public Types | |
using | TradePnlStore = std::vector< std::vector< QuantLib::Real > > |
Public Member Functions | |
HistoricalPnlGenerator (const std::string &baseCurrency, const QuantLib::ext::shared_ptr< ore::data::Portfolio > &portfolio, const QuantLib::ext::shared_ptr< ScenarioSimMarket > &simMarket, const QuantLib::ext::shared_ptr< HistoricalScenarioGenerator > &hisScenGen, const QuantLib::ext::shared_ptr< NPVCube > &cube, const set< std::pair< string, QuantLib::ext::shared_ptr< QuantExt::ModelBuilder > > > &modelBuilders={}, bool dryRun=false) | |
HistoricalPnlGenerator (const string &baseCurrency, const QuantLib::ext::shared_ptr< Portfolio > &portfolio, const QuantLib::ext::shared_ptr< HistoricalScenarioGenerator > &hisScenGen, const QuantLib::ext::shared_ptr< EngineData > &engineData, const Size nThreads, const Date &today, const QuantLib::ext::shared_ptr< ore::data::Loader > &loader, const QuantLib::ext::shared_ptr< ore::data::CurveConfigurations > &curveConfigs, const QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > &todaysMarketParams, const std::string &configuration, const QuantLib::ext::shared_ptr< ScenarioSimMarketParameters > &simMarketData, const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceData=nullptr, const IborFallbackConfig &iborFallbackConfig=IborFallbackConfig::defaultConfig(), bool dryRun=false, const std::string &context="historical pnl generation") | |
void | generateCube (const QuantLib::ext::shared_ptr< ScenarioFilter > &filter) |
std::vector< QuantLib::Real > | pnl (const ore::data::TimePeriod &period, const std::set< std::pair< std::string, QuantLib::Size > > &tradeIds) const |
std::vector< QuantLib::Real > | pnl (const ore::data::TimePeriod &period) const |
std::vector< QuantLib::Real > | pnl (const std::set< std::pair< std::string, QuantLib::Size > > &tradeIds) const |
std::vector< QuantLib::Real > | pnl () const |
TradePnlStore | tradeLevelPnl (const ore::data::TimePeriod &period, const std::set< std::pair< std::string, QuantLib::Size > > &tradeIds) const |
TradePnlStore | tradeLevelPnl (const ore::data::TimePeriod &period) const |
TradePnlStore | tradeLevelPnl (const std::set< std::pair< std::string, QuantLib::Size > > &tradeIds) const |
TradePnlStore | tradeLevelPnl () const |
const QuantLib::ext::shared_ptr< NPVCube > & | cube () const |
std::set< std::pair< std::string, QuantLib::Size > > | tradeIdIndexPairs () const |
Set of trade ID and index pairs for all trades. More... | |
ore::data::TimePeriod | timePeriod () const |
Time period covered by the historical P&L generator. More... | |
Public Member Functions inherited from ProgressReporter | |
ProgressReporter () | |
void | registerProgressIndicator (const QuantLib::ext::shared_ptr< ProgressIndicator > &indicator) |
void | unregisterProgressIndicator (const QuantLib::ext::shared_ptr< ProgressIndicator > &indicator) |
void | unregisterAllProgressIndicators () |
void | updateProgress (const unsigned long progress, const unsigned long total, const std::string &detail="") |
void | resetProgress () |
const std::set< QuantLib::ext::shared_ptr< ProgressIndicator > > & | progressIndicators () const |
Private Member Functions | |
QuantLib::Size | indexAsof () const |
Get the index of the as of date in the cube. More... | |
Private Attributes | |
bool | useSingleThreadedEngine_ |
QuantLib::ext::shared_ptr< ore::data::Portfolio > | portfolio_ |
QuantLib::ext::shared_ptr< ScenarioSimMarket > | simMarket_ |
QuantLib::ext::shared_ptr< HistoricalScenarioGenerator > | hisScenGen_ |
QuantLib::ext::shared_ptr< NPVCube > | cube_ |
QuantLib::ext::shared_ptr< ValuationEngine > | valuationEngine_ |
QuantLib::ext::shared_ptr< ore::data::EngineData > | engineData_ |
Size | nThreads_ |
Date | today_ |
QuantLib::ext::shared_ptr< ore::data::Loader > | loader_ |
QuantLib::ext::shared_ptr< ore::data::CurveConfigurations > | curveConfigs_ |
QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > | todaysMarketParams_ |
std::string | configuration_ |
QuantLib::ext::shared_ptr< ScenarioSimMarketParameters > | simMarketData_ |
QuantLib::ext::shared_ptr< ore::data::ReferenceDataManager > | referenceData_ |
ore::data::IborFallbackConfig | iborFallbackConfig_ |
bool | dryRun_ |
std::string | context_ |
std::function< std::vector< QuantLib::ext::shared_ptr< ValuationCalculator > >()> | npvCalculator_ |
Class for generating historical P&L vectors for a given portfolio in a given currency.
In particular, assume that the portfolio has a base NPV, \(\Pi_0\), today i.e. at \(t_0\). This class takes a HistoricalScenarioGenerator which holds a set of historical market moves, over a given period \(\tau\) e.g. 10 business days, for a set of past dates \(\{d_1, d_2, \ldots, d_N\}\). This class calculates the P&L changes on the portfolio, \(\{\Delta_1, \Delta_2, \ldots, \Delta_N\}\), resulting from applying these market moves to the base market. In other words, \(\Delta_i = \Pi_i - \Pi_0 \) where \(\Pi_i\) is the portfolio NPV under the shifted market corresponding to date \(d_i\) for \(i = 1, 2, \ldots, N\).
In the calculation of P&L, the class allows the scenario shifts to be filtered and also the trades to be filtered.
Definition at line 52 of file historicalpnlgenerator.hpp.
using TradePnlStore = std::vector<std::vector<QuantLib::Real> > |
Return a vector of historical trade level P&L values restricted to scenarios falling in period
and restricted to the given tradeIds
. The P&L values are calculated from the last cube generated by generateCube. The first dimension is time and the second dimension is tradeId.
Definition at line 117 of file historicalpnlgenerator.hpp.
HistoricalPnlGenerator | ( | const std::string & | baseCurrency, |
const QuantLib::ext::shared_ptr< ore::data::Portfolio > & | portfolio, | ||
const QuantLib::ext::shared_ptr< ScenarioSimMarket > & | simMarket, | ||
const QuantLib::ext::shared_ptr< HistoricalScenarioGenerator > & | hisScenGen, | ||
const QuantLib::ext::shared_ptr< NPVCube > & | cube, | ||
const set< std::pair< string, QuantLib::ext::shared_ptr< QuantExt::ModelBuilder > > > & | modelBuilders = {} , |
||
bool | dryRun = false |
||
) |
Constructor to use a single-threaded valuation engine
baseCurrency | currency in which the P&Ls will be calculated |
portfolio | portfolio of trades for which P&Ls will be calculated |
simMarket | simulation market used for valuation |
hisScenGen | historical scenario generator |
cube | an NPV cube that will be populated by each call to generateCube |
modelBuilders | model builders to update during a val engine run |
dryRun | for testing - limit the number of scenarios to one and fill the cube with random data |
HistoricalPnlGenerator | ( | const string & | baseCurrency, |
const QuantLib::ext::shared_ptr< Portfolio > & | portfolio, | ||
const QuantLib::ext::shared_ptr< HistoricalScenarioGenerator > & | hisScenGen, | ||
const QuantLib::ext::shared_ptr< EngineData > & | engineData, | ||
const Size | nThreads, | ||
const Date & | today, | ||
const QuantLib::ext::shared_ptr< ore::data::Loader > & | loader, | ||
const QuantLib::ext::shared_ptr< ore::data::CurveConfigurations > & | curveConfigs, | ||
const QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > & | todaysMarketParams, | ||
const std::string & | configuration, | ||
const QuantLib::ext::shared_ptr< ScenarioSimMarketParameters > & | simMarketData, | ||
const QuantLib::ext::shared_ptr< ReferenceDataManager > & | referenceData = nullptr , |
||
const IborFallbackConfig & | iborFallbackConfig = IborFallbackConfig::defaultConfig() , |
||
bool | dryRun = false , |
||
const std::string & | context = "historical pnl generation" |
||
) |
Constructor to use a multi-threaded valuation engine
void generateCube | ( | const QuantLib::ext::shared_ptr< ScenarioFilter > & | filter | ) |
Generate a "cube" of P&L values for the trades in the portfolio on each of the scenarios provided by the historical scenario generator. The historical scenarios will have the given filter
applied.
Definition at line 96 of file historicalpnlgenerator.cpp.
std::vector< QuantLib::Real > pnl | ( | const ore::data::TimePeriod & | period, |
const std::set< std::pair< std::string, QuantLib::Size > > & | tradeIds | ||
) | const |
Return a vector of historical portfolio P&L values restricted to scenarios falling in period
and restricted to the given tradeIds
. The P&L values are calculated from the last cube generated by generateCube.
vector< Real > pnl | ( | const ore::data::TimePeriod & | period | ) | const |
Return a vector of historical portfolio P&L values restricted to scenarios falling in period
. The P&L values are calculated from the last cube generated by generateCube.
Definition at line 161 of file historicalpnlgenerator.cpp.
std::vector< QuantLib::Real > pnl | ( | const std::set< std::pair< std::string, QuantLib::Size > > & | tradeIds | ) | const |
Return a vector of historical portfolio P&L values restricted to the given tradeIds
. The P&L values are calculated from the last cube generated by generateCube.
vector< Real > pnl | ( | ) | const |
Return a vector of historical portfolio P&L values for all scenarios generated by the historical scenario generator. The P&L values are calculated from the last cube generated by generateCube.
Definition at line 167 of file historicalpnlgenerator.cpp.
TradePnlStore tradeLevelPnl | ( | const ore::data::TimePeriod & | period, |
const std::set< std::pair< std::string, QuantLib::Size > > & | tradeIds | ||
) | const |
TradePnlStore tradeLevelPnl | ( | const ore::data::TimePeriod & | period | ) | const |
Return a vector of historical trade level P&L values restricted to scenarios falling in period
. The P&L values are calculated from the last cube generated by generateCube. The first dimension is time and the second dimension is tradeId.
Definition at line 216 of file historicalpnlgenerator.cpp.
TradePnlStore tradeLevelPnl | ( | const std::set< std::pair< std::string, QuantLib::Size > > & | tradeIds | ) | const |
Return a vector of historical trade level P&L values restricted to the given tradeIds
. The P&L values are calculated from the last cube generated by generateCube. The first dimension is time and the second dimension is tradeId.
TradePnlStore tradeLevelPnl | ( | ) | const |
Return a vector of historical trade level P&L values for all scenarios generated by the historical scenario generator. The P&L values are calculated from the last cube generated by generateCube. The first dimension is time and the second dimension is tradeId.
Definition at line 224 of file historicalpnlgenerator.cpp.
const QuantLib::ext::shared_ptr< NPVCube > & cube | ( | ) | const |
Return the last cube generated by generateCube.
Definition at line 226 of file historicalpnlgenerator.cpp.
set< pair< string, Size > > tradeIdIndexPairs | ( | ) | const |
Set of trade ID and index pairs for all trades.
Definition at line 228 of file historicalpnlgenerator.cpp.
TimePeriod timePeriod | ( | ) | const |
Time period covered by the historical P&L generator.
Definition at line 236 of file historicalpnlgenerator.cpp.
|
private |
Get the index of the as of date in the cube.
Definition at line 241 of file historicalpnlgenerator.cpp.
|
private |
Definition at line 150 of file historicalpnlgenerator.hpp.
|
private |
Definition at line 152 of file historicalpnlgenerator.hpp.
|
private |
Definition at line 153 of file historicalpnlgenerator.hpp.
|
private |
Definition at line 154 of file historicalpnlgenerator.hpp.
|
private |
Definition at line 155 of file historicalpnlgenerator.hpp.
|
private |
Definition at line 156 of file historicalpnlgenerator.hpp.
|
private |
Definition at line 159 of file historicalpnlgenerator.hpp.
|
private |
Definition at line 160 of file historicalpnlgenerator.hpp.
|
private |
Definition at line 161 of file historicalpnlgenerator.hpp.
|
private |
Definition at line 162 of file historicalpnlgenerator.hpp.
|
private |
Definition at line 163 of file historicalpnlgenerator.hpp.
|
private |
Definition at line 164 of file historicalpnlgenerator.hpp.
|
private |
Definition at line 165 of file historicalpnlgenerator.hpp.
|
private |
Definition at line 166 of file historicalpnlgenerator.hpp.
|
private |
Definition at line 167 of file historicalpnlgenerator.hpp.
|
private |
Definition at line 168 of file historicalpnlgenerator.hpp.
|
private |
Definition at line 170 of file historicalpnlgenerator.hpp.
|
private |
Definition at line 171 of file historicalpnlgenerator.hpp.
|
private |
Definition at line 173 of file historicalpnlgenerator.hpp.