36#include <boost/make_shared.hpp>
52 void add(
const QuantLib::ext::shared_ptr<ore::data::Report>& report) {
53 QL_FAIL(
"Please use alternative add method, providing a ReportType");
55 void add(
ReportType type,
const QuantLib::ext::shared_ptr<ore::data::Report>& report) {
63 const QuantLib::ext::shared_ptr<ore::data::Report>& get(
ReportType type);
89 QuantLib::Real conf = 0.99, QuantLib::Real exThres = 0.01,
90 bool tdc =
false,
const std::set<std::string>& callTradeIds = {},
91 const std::set<std::string>& postTradeIds = {})
100 QuantLib::ext::shared_ptr<ore::analytics::TradeGroupBase>
tradeGroup;
101 QuantLib::ext::shared_ptr<ore::analytics::MarketRiskGroupBase>
riskGroup;
116 QuantLib::ext::shared_ptr<ore::analytics::VarCalculator>
calculator;
120 QuantLib::Real
var = 0.0)
127 const QuantLib::ext::shared_ptr<ore::data::Portfolio>& portfolio,
128 const std::string& portfolioFilter,
129 std::unique_ptr<BacktestArgs> btArgs,
130 std::unique_ptr<SensiRunArgs> sensiArgs =
nullptr,
131 std::unique_ptr<FullRevalArgs> revalArgs =
nullptr,
132 std::unique_ptr<MultiThreadArgs> mtArgs =
nullptr,
133 const QuantLib::ext::shared_ptr<ore::analytics::HistoricalScenarioGenerator>& hisScenGen =
nullptr,
134 const bool breakdown =
false,
135 const bool requireTradePnl =
false);
142 bool disablesAll(
const QuantLib::ext::shared_ptr<ore::analytics::ScenarioFilter>& filter)
const override;
145 virtual void addPnlRow(
const QuantLib::ext::shared_ptr<BacktestReports>& reports, QuantLib::Size scenarioIdx,
147 QuantLib::Real delta, QuantLib::Real gamma, QuantLib::Real deltaPnl, QuantLib::Real gammaPnl,
149 QuantLib::Real shift_2 = 0.0,
const std::string& tradeId =
"",
150 const std::string& currency =
"", QuantLib::Real fxSpot = 1.0);
158 typedef std::map<VarType, std::pair<QuantLib::ext::shared_ptr<ore::analytics::VarCalculator>, QuantLib::Real>>
168 virtual const std::vector<std::tuple<std::string, ore::data::Report::ReportType, QuantLib::Size>>
summaryColumns() = 0;
169 virtual const std::vector<std::tuple<std::string, ore::data::Report::ReportType, QuantLib::Size, bool>>
detailColumns() = 0;
170 virtual const std::vector<std::tuple<std::string, ore::data::Report::ReportType, QuantLib::Size>>
pnlColumns() = 0;
173 virtual std::string
counterparty(
const std::string& tradeId)
const = 0;
175 virtual void reset(
const QuantLib::ext::shared_ptr<ore::analytics::MarketRiskGroupBase>& riskGroup)
override;
177 void createReports(
const QuantLib::ext::shared_ptr<MarketRiskReport::Reports>& reports)
override;
178 virtual bool runTradeDetail(
const QuantLib::ext::shared_ptr<MarketRiskReport::Reports>& reports)
override;
180 void addPnlCalculators(
const QuantLib::ext::shared_ptr<MarketRiskReport::Reports>& reports)
override;
182 void handleSensiResults(
const QuantLib::ext::shared_ptr<MarketRiskReport::Reports>& reports,
183 const QuantLib::ext::shared_ptr<ore::analytics::MarketRiskGroupBase>& riskGroup,
184 const QuantLib::ext::shared_ptr<ore::analytics::TradeGroupBase>& tradeGroup)
override;
187 const QuantLib::ext::shared_ptr<ore::analytics::MarketRiskGroupBase>& riskGroup,
188 const QuantLib::ext::shared_ptr<ore::analytics::TradeGroupBase>& tradeGroup)
override;
192 const std::vector<QuantLib::Real>& foSensiPnls,
193 const std::vector<QuantLib::Real>& bmFoSensiPnls,
195 const QuantLib::ext::shared_ptr<ore::analytics::MarketRiskGroupBase>& riskGroup){};
198 virtual void addDetailRow(
const QuantLib::ext::shared_ptr<BacktestReports>& reports,
const Data& data,
bool isCall,
199 QuantLib::Real im,
const QuantLib::Date& start,
const QuantLib::Date& end,
bool isFull, QuantLib::Real pnl,
200 const std::string& result,
const std::string& tradeId =
"")
const = 0;
203 virtual void addSummaryRow(
const QuantLib::ext::shared_ptr<BacktestReports>& reports,
const Data& data,
bool isCall,
204 QuantLib::Real im, QuantLib::Size observations,
205 bool isFull, QuantLib::Size exceptions,
const std::vector<QuantLib::Size>& ragBounds,
210 const QuantLib::ext::shared_ptr<ore::analytics::MarketRiskGroupBase>& riskGroup,
211 std::set<std::pair<std::string, QuantLib::Size>>& tradeIdIdxPairs);
213 void writeReports(
const QuantLib::ext::shared_ptr<MarketRiskReport::Reports>& reports,
214 const QuantLib::ext::shared_ptr<ore::analytics::MarketRiskGroupBase>& riskGroup,
215 const QuantLib::ext::shared_ptr<ore::analytics::TradeGroupBase>& tradeGroup)
override;
217 std::vector<ore::data::TimePeriod>
timePeriods()
override;
230 const std::vector<QuantLib::Real>& pnls,
const std::vector<std::string>& tradeIds,
const TradePnLStore& tradePnls);
236 const QuantLib::ext::shared_ptr<MarketRiskBacktest::BacktestReports>& reports)
240 QuantLib::Real shift_1, QuantLib::Real delta, QuantLib::Real gamma, QuantLib::Real deltaPnl,
242 QuantLib::Real shift_2 = 0.0,
const std::string& tradeId =
"")
override;
250 QuantLib::ext::shared_ptr<MarketRiskBacktest::BacktestReports>
reports_;
BacktestPNLCalculator(ore::data::TimePeriod pnlPeriod, const bool &writePnl, MarketRiskBacktest *backtest, const QuantLib::ext::shared_ptr< MarketRiskBacktest::BacktestReports > &reports)
QuantLib::ext::shared_ptr< MarketRiskBacktest::BacktestReports > reports_
const TradePnLStore & foTradePnls()
MarketRiskBacktest * backtest_
const TradePnLStore & tradePnls()
void writePNL(QuantLib::Size scenarioIdx, bool isCall, const RiskFactorKey &key_1, QuantLib::Real shift_1, QuantLib::Real delta, QuantLib::Real gamma, QuantLib::Real deltaPnl, QuantLib::Real gammaPnl, const RiskFactorKey &key_2=RiskFactorKey(), QuantLib::Real shift_2=0.0, const std::string &tradeId="") override
std::vector< ReportType > types_
const bool has(ReportType type) const
void add(ReportType type, const QuantLib::ext::shared_ptr< ore::data::Report > &report)
void add(const QuantLib::ext::shared_ptr< ore::data::Report > &report)
ReportType
Report types that can be populated during a SIMM backtest.
ore::analytics::TradePnLStore tradePnls_
std::set< std::string > postTradeIds_
std::vector< QuantLib::Real > pnls_
bool disablesAll(const QuantLib::ext::shared_ptr< ore::analytics::ScenarioFilter > &filter) const override
virtual void addSummaryRow(const QuantLib::ext::shared_ptr< BacktestReports > &reports, const Data &data, bool isCall, QuantLib::Real im, QuantLib::Size observations, bool isFull, QuantLib::Size exceptions, const std::vector< QuantLib::Size > &ragBounds, const VarBenchmarks &sensiBenchmarks, const VarBenchmarks &fullBenchmarks) const =0
Add a row to the summary report.
VarType
VAR types used as a benchmark against which SIMM can be compared.
ore::analytics::TradePnLStore sensiTradePnls_
VarBenchmarks fullRevalCallBenchmarks_
virtual const std::vector< std::tuple< std::string, ore::data::Report::ReportType, QuantLib::Size, bool > > detailColumns()=0
virtual bool runTradeDetail(const QuantLib::ext::shared_ptr< MarketRiskReport::Reports > &reports) override
std::vector< ore::data::TimePeriod > timePeriods() override
virtual void calculateBenchmarks(VarBenchmarks &benchmarks, QuantLib::Real confidence, const bool isCall, const QuantLib::ext::shared_ptr< ore::analytics::MarketRiskGroupBase > &riskGroup, std::set< std::pair< std::string, QuantLib::Size > > &tradeIdIdxPairs)
Calculate and update the benchmarks.
std::vector< QuantLib::Real > sensiPnls_
virtual void reset(const QuantLib::ext::shared_ptr< ore::analytics::MarketRiskGroupBase > &riskGroup) override
virtual ~MarketRiskBacktest()
void writeReports(const QuantLib::ext::shared_ptr< MarketRiskReport::Reports > &reports, const QuantLib::ext::shared_ptr< ore::analytics::MarketRiskGroupBase > &riskGroup, const QuantLib::ext::shared_ptr< ore::analytics::TradeGroupBase > &tradeGroup) override
ore::analytics::TradePnLStore foTradePnls_
ore::data::TimePeriod covariancePeriod() const override
SummaryResults calculateSummary(const QuantLib::ext::shared_ptr< BacktestReports > &reports, const Data &data, bool isFull, const std::vector< QuantLib::Real > &pnls, const std::vector< std::string > &tradeIds, const TradePnLStore &tradePnls)
void createReports(const QuantLib::ext::shared_ptr< MarketRiskReport::Reports > &reports) override
virtual QuantLib::Real postValue(const Data &data)=0
std::vector< QuantLib::Real > bmPnls_
std::map< VarType, std::pair< QuantLib::ext::shared_ptr< ore::analytics::VarCalculator >, QuantLib::Real > > VarBenchmarks
pointers to the VAR benchmarks
std::vector< QuantLib::Real > foSensiPnls_
virtual QuantLib::Real callValue(const Data &data)=0
virtual void setUpBenchmarks()=0
void addPnlCalculators(const QuantLib::ext::shared_ptr< MarketRiskReport::Reports > &reports) override
VarBenchmarks fullRevalPostBenchmarks_
virtual std::string counterparty(const std::string &tradeId) const =0
std::set< std::string > callTradeIds_
virtual void addDetailRow(const QuantLib::ext::shared_ptr< BacktestReports > &reports, const Data &data, bool isCall, QuantLib::Real im, const QuantLib::Date &start, const QuantLib::Date &end, bool isFull, QuantLib::Real pnl, const std::string &result, const std::string &tradeId="") const =0
Add a row to the detail report.
virtual const std::vector< std::tuple< std::string, ore::data::Report::ReportType, QuantLib::Size > > pnlColumns()=0
virtual void adjustFullRevalPnls(std::vector< QuantLib::Real > &pnls, std::vector< QuantLib::Real > &bmPnls, ore::analytics::TradePnLStore &tradePnls, const std::vector< QuantLib::Real > &foSensiPnls, const std::vector< QuantLib::Real > &bmFoSensiPnls, const ore::analytics::TradePnLStore &foTradePnls, const QuantLib::ext::shared_ptr< ore::analytics::MarketRiskGroupBase > &riskGroup)
VarBenchmarks sensiPostBenchmarks_
std::vector< QuantLib::Real > bmFoSensiPnls_
void handleSensiResults(const QuantLib::ext::shared_ptr< MarketRiskReport::Reports > &reports, const QuantLib::ext::shared_ptr< ore::analytics::MarketRiskGroupBase > &riskGroup, const QuantLib::ext::shared_ptr< ore::analytics::TradeGroupBase > &tradeGroup) override
void initialise() override
virtual void addPnlRow(const QuantLib::ext::shared_ptr< BacktestReports > &reports, QuantLib::Size scenarioIdx, bool isCall, const ore::analytics::RiskFactorKey &key_1, QuantLib::Real shift_1, QuantLib::Real delta, QuantLib::Real gamma, QuantLib::Real deltaPnl, QuantLib::Real gammaPnl, const ore::analytics::RiskFactorKey &key_2=ore::analytics::RiskFactorKey(), QuantLib::Real shift_2=0.0, const std::string &tradeId="", const std::string ¤cy="", QuantLib::Real fxSpot=1.0)
Add a row to the P&L contribution report.
std::vector< QuantLib::Real > bmSensiPnls_
variables for benchmark calculations
void handleFullRevalResults(const QuantLib::ext::shared_ptr< MarketRiskReport::Reports > &reports, const QuantLib::ext::shared_ptr< ore::analytics::MarketRiskGroupBase > &riskGroup, const QuantLib::ext::shared_ptr< ore::analytics::TradeGroupBase > &tradeGroup) override
std::unique_ptr< BacktestArgs > btArgs_
virtual const std::vector< std::tuple< std::string, ore::data::Report::ReportType, QuantLib::Size > > summaryColumns()=0
VarBenchmarks sensiCallBenchmarks_
std::vector< QuantLib::ext::shared_ptr< ore::data::Report > > reports_
TradePnLStore foTradePnls_
std::vector< std::vector< QuantLib::Real > > TradePnLStore
Data types stored in the scenario class.
Class for generating portfolio P&Ls based on historical scenarios.
Class for generating sensi pnl.
Base class for a market risk report.
std::vector< std::vector< QuantLib::Real > > TradePnLStore
Class for calculating the shift multiple between two scenarios for a given key.
Base class for sensitivity record streamer.
std::set< std::string > postTradeIds_
Post side trade IDs to be considered in the backtest. Other trades' PnLs will be removed from the tot...
ore::data::TimePeriod backtestPeriod_
Time period over which to perform the backtest.
QuantLib::Real confidence_
Confidence level in the SIMM backtest.
BacktestArgs(ore::data::TimePeriod btPeriod, ore::data::TimePeriod bmPeriod, QuantLib::Real conf=0.99, QuantLib::Real exThres=0.01, bool tdc=false, const std::set< std::string > &callTradeIds={}, const std::set< std::string > &postTradeIds={})
std::vector< QuantLib::Real > ragLevels_
Confidence levels that feed in to defining the stop light bounds.
ore::data::TimePeriod benchmarkPeriod_
Time period over which to calculate the benchmark VAR.
std::set< std::string > callTradeIds_
Call side trade IDs to be considered in the backtest. Other trades' PnLs will be removed from the tot...
QuantLib::Real exceptionThreshold_
Amount by which absolute P&L value must exceed 0 for exception counting.
bool tradeDetailIncludeAllColumns_
Used to pass information.
QuantLib::ext::shared_ptr< ore::analytics::MarketRiskGroupBase > riskGroup
QuantLib::ext::shared_ptr< ore::analytics::TradeGroupBase > tradeGroup
Used to store results for writing rows in the summary report.
QuantLib::Size observations
std::vector< QuantLib::Size > bounds
QuantLib::Size postExceptions
QuantLib::Size callExceptions
VarBenchmark(VarType type, QuantLib::ext::shared_ptr< ore::analytics::VarCalculator > calculator, QuantLib::Real var=0.0)
QuantLib::ext::shared_ptr< ore::analytics::VarCalculator > calculator
Base class for a var calculation.