21#include <ql/errors.hpp>
22#include <ql/time/calendars/weekendsonly.hpp>
23#include <ql/time/daycounters/actualactual.hpp>
24#include <ql/version.hpp>
33 const QuantLib::ext::shared_ptr<InputParameters>& inputs,
34 const QuantLib::ext::shared_ptr<Portfolio>& portfolio,
const QuantLib::ext::shared_ptr<NPVCube>& cube,
35 const QuantLib::ext::shared_ptr<CubeInterpretation>& cubeInterpretation,
36 const QuantLib::ext::shared_ptr<AggregationScenarioData>& scenarioData)
46 QL_FAIL(
"netting set " << nettingSet <<
" not found in expected DIM results");
50 LOG(
"FlatDynamicInitialMarginCalculator:build() called");
52 Size samples =
cube_->samples();
54 if (!
inputs_->collateralBalances()) {
55 ALOG(
"collateral balances not set");
59 LOG(
"Process netting set " << n);
62 if (
inputs_->collateralBalances() &&
inputs_->collateralBalances()->has(n)) {
64 LOG(
"Found initial margin balance " <<
currentIM <<
" for netting set " << n);
67 for (Size j = 0; j <
cube_->dates().
size(); ++j) {
69 for (Size k = 0; k < samples; ++k)
73 LOG(
"DIM by flat extraplation of initial IM done");
82 dimEvolutionReport.
addColumn(
"TimeStep", Size())
92 for (
const auto& [nettingSet, _] :
dimCube_->idsAndIndexes()) {
94 LOG(
"Export DIM evolution for netting set " << nettingSet);
95 for (Size i = 0; i < stopDatesLoop; ++i) {
96 Date defaultDate =
dimCube_->dates()[i];
97 Time t = ActualActual(ActualActual::ISDA).yearFraction(
asof, defaultDate);
100 Real dim = it->second.at(i);
101 dimEvolutionReport.
next()
113 dimEvolutionReport.
end();
114 LOG(
"Exporting expected DIM through time done");
Dynamic Initial Margin Calculator base class.
const map< string, Real > & currentIM() const
t0 IM by netting set, as provided as an arguments
std::set< string > nettingSetIds_
map< string, vector< Real > > nettingSetExpectedDIM_
QuantLib::ext::shared_ptr< CubeInterpretation > cubeInterpretation_
QuantLib::ext::shared_ptr< NPVCube > dimCube_
QuantLib::ext::shared_ptr< InputParameters > inputs_
map< string, vector< vector< Real > > > nettingSetDIM_
QuantLib::ext::shared_ptr< NPVCube > cube_
FlatDynamicInitialMarginCalculator(const QuantLib::ext::shared_ptr< InputParameters > &inputs, const QuantLib::ext::shared_ptr< Portfolio > &portfolio, const QuantLib::ext::shared_ptr< NPVCube > &cube, const QuantLib::ext::shared_ptr< CubeInterpretation > &cubeInterpretation, const QuantLib::ext::shared_ptr< AggregationScenarioData > &scenarioData)
void exportDimEvolution(ore::data::Report &dimEvolutionReport) const override
DIM evolution report.
const vector< Real > & dimResults(const std::string &nettingSet) const
void build() override
Compute dynamic initial margin along all paths and fill result structures.
virtual Report & add(const ReportType &rt)=0
virtual Report & next()=0
virtual Report & addColumn(const string &name, const ReportType &, Size precision=0)=0
Size size(const ValueType &v)