32#include <ql/math/matrix.hpp>
33#include <ql/shared_ptr.hpp>
35#include <boost/accumulators/accumulators.hpp>
41#include <boost/accumulators/statistics/stats.hpp>
42#include <boost/accumulators/statistics/variance.hpp>
43#include <boost/accumulators/statistics/covariance.hpp>
44#include <boost/accumulators/statistics/variates/covariate.hpp>
53 virtual void writePNL(QuantLib::Size scenarioIdx,
bool isCall,
54 const RiskFactorKey& key_1, QuantLib::Real shift_1, QuantLib::Real delta,
55 QuantLib::Real gamma, QuantLib::Real deltaPnl, Real gammaPnl,
57 QuantLib::Real shift_2 = 0.0,
const std::string& tradeId =
"") {}
58 const bool isInTimePeriod(QuantLib::Date startDate, QuantLib::Date endDate);
60 void populatePNLs(
const std::vector<QuantLib::Real>& allPnls,
const std::vector<QuantLib::Real>&
foPnls,
61 const std::vector<QuantLib::Date>& startDates,
const std::vector<QuantLib::Date>& endDates);
66 const std::vector<QuantLib::Real>&
pnls() {
return pnls_; };
80 std::vector<QuantLib::Real>
pnls_;
89 void initialise(
const std::set<std::pair<RiskFactorKey, QuantLib::Size>>& keys);
90 void updateAccumulators(
const QuantLib::ext::shared_ptr<NPVCube>& shiftCube, QuantLib::Date startDate, QuantLib::Date endDate, QuantLib::Size index);
91 void populateCovariance(
const std::set<std::pair<RiskFactorKey, QuantLib::Size>>& keys);
95 typedef boost::accumulators::accumulator_set<
97 boost::accumulators::stats<boost::accumulators::tag::covariance<QuantLib::Real, boost::accumulators::tag::covariate1>>>
107 const QuantLib::ext::shared_ptr<SensitivityStream>& ss)
110 void populateSensiShifts(QuantLib::ext::shared_ptr<NPVCube>& cube,
const vector<RiskFactorKey>& keys,
111 QuantLib::ext::shared_ptr<ScenarioShiftCalculator> shiftCalculator);
114 const std::vector<RiskFactorKey>& rfKeys,
115 QuantLib::ext::shared_ptr<NPVCube>& shiftCube,
116 const std::vector<QuantLib::ext::shared_ptr<PNLCalculator>>& pnlCalculators,
117 const QuantLib::ext::shared_ptr<CovarianceCalculator>& covarianceCalculator,
118 const std::vector<std::string>& tradeIds = {},
119 const bool includeGammaMargin =
true,
const bool includeDeltaMargin =
true,
120 const bool tradeLevel =
false);
123 QuantLib::ext::shared_ptr<HistoricalScenarioGenerator>
hisScenGen_;
boost::accumulators::accumulator_set< QuantLib::Real, boost::accumulators::stats< boost::accumulators::tag::covariance< QuantLib::Real, boost::accumulators::tag::covariate1 > > > accumulator
CovarianceCalculator(ore::data::TimePeriod covariancePeriod)
void initialise(const std::set< std::pair< RiskFactorKey, QuantLib::Size > > &keys)
const Matrix & covariance() const
void updateAccumulators(const QuantLib::ext::shared_ptr< NPVCube > &shiftCube, QuantLib::Date startDate, QuantLib::Date endDate, QuantLib::Size index)
QuantLib::Matrix covariance_
void populateCovariance(const std::set< std::pair< RiskFactorKey, QuantLib::Size > > &keys)
std::map< std::pair< QuantLib::Size, QuantLib::Size >, accumulator > accCov_
ore::data::TimePeriod covariancePeriod_
QuantLib::ext::shared_ptr< HistoricalScenarioGenerator > hisScenGen_
HistoricalSensiPnlCalculator(const QuantLib::ext::shared_ptr< HistoricalScenarioGenerator > &hisScenGen, const QuantLib::ext::shared_ptr< SensitivityStream > &ss)
QuantLib::ext::shared_ptr< SensitivityStream > sensitivityStream_
Stream of sensitivity records used for the sensitivity based backtest.
void populateSensiShifts(QuantLib::ext::shared_ptr< NPVCube > &cube, const vector< RiskFactorKey > &keys, QuantLib::ext::shared_ptr< ScenarioShiftCalculator > shiftCalculator)
void calculateSensiPnl(const std::set< SensitivityRecord > &srs, const std::vector< RiskFactorKey > &rfKeys, QuantLib::ext::shared_ptr< NPVCube > &shiftCube, const std::vector< QuantLib::ext::shared_ptr< PNLCalculator > > &pnlCalculators, const QuantLib::ext::shared_ptr< CovarianceCalculator > &covarianceCalculator, const std::vector< std::string > &tradeIds={}, const bool includeGammaMargin=true, const bool includeDeltaMargin=true, const bool tradeLevel=false)
const std::vector< QuantLib::Real > & foPnls()
void populateTradePNLs(const TradePnLStore &allPnls, const TradePnLStore &foPnls)
const bool isInTimePeriod(QuantLib::Date startDate, QuantLib::Date endDate)
std::vector< QuantLib::Real > pnls_
ore::data::TimePeriod pnlPeriod_
const std::vector< QuantLib::Real > & pnls()
PNLCalculator(ore::data::TimePeriod pnlPeriod)
const TradePnLStore & foTradePnls()
TradePnLStore foTradePnls_
void populatePNLs(const std::vector< QuantLib::Real > &allPnls, const std::vector< QuantLib::Real > &foPnls, const std::vector< QuantLib::Date > &startDates, const std::vector< QuantLib::Date > &endDates)
std::vector< QuantLib::Real > foPnls_
const TradePnLStore & tradePnls()
virtual void writePNL(QuantLib::Size scenarioIdx, bool isCall, const RiskFactorKey &key_1, QuantLib::Real shift_1, QuantLib::Real delta, QuantLib::Real gamma, QuantLib::Real deltaPnl, Real gammaPnl, const RiskFactorKey &key_2=RiskFactorKey(), QuantLib::Real shift_2=0.0, const std::string &tradeId="")
std::vector< std::vector< QuantLib::Real > > TradePnLStore
Data types stored in the scenario class.
scenario generator that builds from historical shifts
Class for calculating the shift multiple between two scenarios for a given key.
Struct for holding a sensitivity record.
Base class for sensitivity record streamer.