29#include <ql/errors.hpp>
30#include <ql/time/date.hpp>
31#include <ql/types.hpp>
35#include <boost/bimap.hpp>
36#include <ql/shared_ptr.hpp>
45 typedef std::pair<RiskFactorKey, RiskFactorKey>
crossPair;
60 const std::map<RiskFactorKey, QuantLib::Real>& targetShiftSizes,
61 const std::map<RiskFactorKey, QuantLib::Real>& actualShiftSizes,
62 const std::map<RiskFactorKey, ShiftScheme>& shiftSchemes);
66 const std::map<RiskFactorKey, QuantLib::Real>& targetShiftSizes,
67 const std::map<RiskFactorKey, QuantLib::Real>& actualshiftSizes,
68 const std::map<RiskFactorKey, ShiftScheme>& shiftSchemes);
72 const QuantLib::ext::shared_ptr<NPVSensiCube>&
npvCube()
const {
return cube_; }
77 bool hasTrade(
const std::string& tradeId)
const;
80 const std::map<std::string, QuantLib::Size>&
tradeIdx()
const {
return cube_->idsAndIndexes(); };
96 const std::set<RiskFactorKey>&
factors()
const;
105 const std::map<crossPair, std::tuple<SensitivityCube::FactorData, SensitivityCube::FactorData, QuantLib::Size>>&
118 QuantLib::Real
npv(
const std::string& tradeId)
const;
121 QuantLib::Real
npv(QuantLib::Size
id)
const;
127 QuantLib::Real
delta(
const std::string& tradeId,
const RiskFactorKey& riskFactorKey)
const;
133 QuantLib::Real
gamma(
const std::string& tradeId,
const RiskFactorKey& riskFactorKey)
const;
141 QuantLib::Real
crossGamma(
const std::string& tradeId,
const crossPair& riskFactorKeyPair)
const;
144 QuantLib::Real
crossGamma(QuantLib::Size
tradeIdx, QuantLib::Size upIdx_1, QuantLib::Size upIdx_2,
145 QuantLib::Size crossId, QuantLib::Real scaling1, QuantLib::Real scaling2)
const;
154 QuantLib::ext::shared_ptr<NPVSensiCube>
cube_;
172 std::map<crossPair, std::tuple<FactorData, FactorData, QuantLib::Size>>
crossFactors_;
Data types stored in the scenario class.
SensitivityCube is a wrapper for an npvCube that gives easier access to the underlying cube elements.
std::map< RiskFactorKey, ShiftScheme > shiftSchemes_
std::string factorDescription(const RiskFactorKey &riskFactorKey) const
void initialise()
Initialise method used by the constructors.
std::vector< ShiftScenarioDescription > scenarioDescriptions_
std::map< std::string, QuantLib::Size > tradeIdx_
std::map< QuantLib::Size, RiskFactorKey > downIndexToKey_
const QuantLib::ext::shared_ptr< NPVSensiCube > & npvCube() const
bool hasTrade(const std::string &tradeId) const
Check if the cube has scenario NPVs for trade with ID tradeId.
std::map< RiskFactorKey, QuantLib::Real > targetShiftSizes_
QuantLib::Real actualShiftSize(const RiskFactorKey &riskFactorKey) const
Returns the absolute actual shift size for given risk factor key.
const std::map< std::string, QuantLib::Size > & tradeIdx() const
Return the map of up trade id's to index in cube.
std::map< ShiftScenarioDescription, QuantLib::Size > scenarioIdx_
QuantLib::Real targetShiftSize(const RiskFactorKey &riskFactorKey) const
Returns the absolute target shift size for given risk factor key.
std::map< RiskFactorKey, FactorData > upFactors_
const std::map< RiskFactorKey, SensitivityCube::FactorData > & upFactors() const
Return the map of up risk factors to its factor data.
const std::map< RiskFactorKey, SensitivityCube::FactorData > & downFactors() const
Return the map of down risk factors to its factor data.
std::map< crossPair, std::tuple< FactorData, FactorData, QuantLib::Size > > crossFactors_
QuantLib::ext::shared_ptr< NPVSensiCube > cube_
QuantLib::Real gamma(const Size tradeIdx, const RiskFactorKey &riskFactorKey) const
Get the trade gamma for trade with index tradeIdx and for the given risk factor key riskFactorKey.
bool hasScenario(const ShiftScenarioDescription &scenarioDescription) const
Check if the cube has scenario NPVs for scenario with description scenarioDescription.
std::map< QuantLib::Size, crossPair > crossIndexToKey_
std::map< QuantLib::Size, RiskFactorKey > upIndexToKey_
QuantLib::Real npv(QuantLib::Size id) const
Get the NPV for trade given the index of trade in the cube.
QuantLib::Real delta(const Size tradeIdx, const RiskFactorKey &riskFactorKey) const
Get the trade delta for trade with index tradeIdx and for the given risk factor key riskFactorKey.
std::set< RiskFactorKey > factors_
RiskFactorKey upDownFactor(const Size index) const
const std::vector< ShiftScenarioDescription > & scenarioDescriptions() const
QuantLib::Real crossGamma(const Size tradeIdx, const crossPair &riskFactorKeyPair) const
std::map< RiskFactorKey, QuantLib::Real > actualShiftSizes_
const std::set< RiskFactorKey > & factors() const
Returns the set of risk factor keys for which a delta and gamma can be calculated.
const std::map< crossPair, std::tuple< SensitivityCube::FactorData, SensitivityCube::FactorData, QuantLib::Size > > & crossFactors() const
Returns the set of pairs of risk factor keys for which a cross gamma is available.
ShiftScheme shiftScheme(const RiskFactorKey &riskFactorKey) const
Returns the shift scheme for given risk factor key.
crossPair crossFactor(const Size crossIndex) const
QuantLib::Real npv(const std::string &tradeId) const
Get the base NPV for trade with ID tradeId.
std::map< RiskFactorKey, FactorData > downFactors_
std::pair< RiskFactorKey, RiskFactorKey > crossPair
std::set< RiskFactorKey > relevantRiskFactors() const
Get the relevant risk factors.
ShiftScenarioGenerator::ScenarioDescription ShiftScenarioDescription
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
SensitivityCube::crossPair crossPair
An NPV cube for storing NPVs resulting from risk factor shifts.
Shift scenario generation.
QuantLib::Real targetShiftSize
QuantLib::Real actualShiftSize
bool operator<(const FactorData &fd) const