Logo
Reference manual - version orea_version
Public Types | Public Member Functions | List of all members
HistoricalPnlGenerator Class Reference

#include <orea/engine/historicalpnlgenerator.hpp>

+ Inheritance diagram for HistoricalPnlGenerator:

Public Types

using TradePnlStore = std::vector< std::vector< QuantLib::Real > >
 

Public Member Functions

 HistoricalPnlGenerator (const std::string &baseCurrency, const boost::shared_ptr< ore::data::Portfolio > &portfolio, const boost::shared_ptr< ScenarioSimMarket > &simMarket, const boost::shared_ptr< HistoricalScenarioGenerator > &hisScenGen, const boost::shared_ptr< NPVCube > &cube, const set< std::pair< string, boost::shared_ptr< QuantExt::ModelBuilder >>> &modelBuilders={}, bool dryRun=false)
 
 HistoricalPnlGenerator (const string &baseCurrency, const boost::shared_ptr< Portfolio > &portfolio, const boost::shared_ptr< HistoricalScenarioGenerator > &hisScenGen, const boost::shared_ptr< EngineData > &engineData, const Size nThreads, const Date &today, const boost::shared_ptr< ore::data::Loader > &loader, const boost::shared_ptr< ore::data::CurveConfigurations > &curveConfigs, const boost::shared_ptr< ore::data::TodaysMarketParameters > &todaysMarketParams, const std::string &configuration, const boost::shared_ptr< ScenarioSimMarketParameters > &simMarketData, const boost::shared_ptr< ReferenceDataManager > &referenceData=nullptr, const IborFallbackConfig &iborFallbackConfig=IborFallbackConfig::defaultConfig(), bool dryRun=false, const std::string &context="historical pnl generation")
 
void generateCube (const boost::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 boost::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.
 
ore::data::TimePeriod timePeriod () const
 Time period covered by the historical P&L generator.
 
- Public Member Functions inherited from ProgressReporter
void registerProgressIndicator (const boost::shared_ptr< ProgressIndicator > &indicator)
 
void unregisterProgressIndicator (const boost::shared_ptr< ProgressIndicator > &indicator)
 
void unregisterAllProgressIndicators ()
 
void updateProgress (const unsigned long progress, const unsigned long total)
 
void resetProgress ()
 
const std::set< boost::shared_ptr< ProgressIndicator > > & progressIndicators () const
 

Detailed Description

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.

Member Typedef Documentation

◆ TradePnlStore

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.

Constructor & Destructor Documentation

◆ HistoricalPnlGenerator() [1/2]

HistoricalPnlGenerator ( const std::string &  baseCurrency,
const boost::shared_ptr< ore::data::Portfolio > &  portfolio,
const boost::shared_ptr< ScenarioSimMarket > &  simMarket,
const boost::shared_ptr< HistoricalScenarioGenerator > &  hisScenGen,
const boost::shared_ptr< NPVCube > &  cube,
const set< std::pair< string, boost::shared_ptr< QuantExt::ModelBuilder >>> &  modelBuilders = {},
bool  dryRun = false 
)

Constructor to use a single-threaded valuation engine

Parameters
baseCurrencycurrency in which the P&Ls will be calculated
portfolioportfolio of trades for which P&Ls will be calculated
simMarketsimulation market used for valuation
hisScenGenhistorical scenario generator
cubean NPV cube that will be populated by each call to generateCube
modelBuildersmodel builders to update during a val engine run
dryRunfor testing - limit the number of scenarios to one and fill the cube with random data

◆ HistoricalPnlGenerator() [2/2]

HistoricalPnlGenerator ( const string &  baseCurrency,
const boost::shared_ptr< Portfolio > &  portfolio,
const boost::shared_ptr< HistoricalScenarioGenerator > &  hisScenGen,
const boost::shared_ptr< EngineData > &  engineData,
const Size  nThreads,
const Date &  today,
const boost::shared_ptr< ore::data::Loader > &  loader,
const boost::shared_ptr< ore::data::CurveConfigurations > &  curveConfigs,
const boost::shared_ptr< ore::data::TodaysMarketParameters > &  todaysMarketParams,
const std::string &  configuration,
const boost::shared_ptr< ScenarioSimMarketParameters > &  simMarketData,
const boost::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

Member Function Documentation

◆ generateCube()

void generateCube ( const boost::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.

◆ pnl() [1/4]

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.

◆ pnl() [2/4]

std::vector<QuantLib::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.

◆ pnl() [3/4]

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.

◆ pnl() [4/4]

std::vector<QuantLib::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.

◆ tradeLevelPnl() [1/3]

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.

◆ tradeLevelPnl() [2/3]

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.

◆ tradeLevelPnl() [3/3]

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.

◆ cube()

const boost::shared_ptr<NPVCube>& cube ( ) const

Return the last cube generated by generateCube.