Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
deltascenario.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file scenario/deltascenario.hpp
20 \brief Delta scenario class
21 \ingroup scenario
22*/
23
24#pragma once
25
27
28namespace ore {
29namespace analytics {
30using namespace QuantLib;
31
32//-----------------------------------------------------------------------------------------------
33//! Delta Scenario class
34/*! This implementation stores a pointer to a "base scenario", as well as a smaller "delta" scenario,
35 which stores values for any keys where the value is different to base.
36 This is intended as an efficient storage mechanism for e.g. sensitivity scenarios,
37 where many scenario instances are managed in memory but the actual differences are minor.
38
39 \ingroup scenario
40*/
42public:
43 //! Constructor
45 //! Constructor
46 DeltaScenario(const QuantLib::ext::shared_ptr<ore::analytics::Scenario>& baseScenario,
47 const QuantLib::ext::shared_ptr<ore::analytics::Scenario>& incrementalScenario);
48
49 const Date& asof() const override { return delta_->asof(); }
50 void setAsof(const Date& d) override { delta_->setAsof(d); }
51
52 //! Return the scenario label
53 const std::string& label() const override { return delta_->label(); }
54 //! set the label
55 void label(const string& s) override { delta_->label(s); }
56
57 //! Get Numeraire ratio n = N(t) / N(0) so that Price(0) = N(0) * E [Price(t) / N(t) ]
58 Real getNumeraire() const override;
59 //! Set the Numeraire ratio n = N(t) / N(0) so that Price(0) = N(0) * E [Price(t) / N(t) ]
60 void setNumeraire(Real n) override { delta_->setNumeraire(n); }
61
62 //! Check, get, add a single market point
63 bool has(const ore::analytics::RiskFactorKey& key) const override { return baseScenario_->has(key); }
64 const std::vector<ore::analytics::RiskFactorKey>& keys() const override { return baseScenario_->keys(); }
65 void add(const ore::analytics::RiskFactorKey& key, Real value) override;
66 Real get(const ore::analytics::RiskFactorKey& key) const override;
67
68 bool isAbsolute() const override { return baseScenario_->isAbsolute(); }
69 void setAbsolute(const bool b) override { baseScenario_->setAbsolute(b); }
70
71 const std::map<std::pair<RiskFactorKey::KeyType, std::string>, std::vector<std::vector<Real>>>&
72 coordinates() const override {
73 return baseScenario_->coordinates();
74 }
75
76 //! Get base
77 QuantLib::ext::shared_ptr<Scenario> base() const { return baseScenario_; }
78
79 //! Get delta
80 QuantLib::ext::shared_ptr<Scenario> delta() const { return delta_; }
81
82 QuantLib::ext::shared_ptr<Scenario> clone() const override;
83
84 bool isCloseEnough(const QuantLib::ext::shared_ptr<Scenario>& s) const override;
85
86protected:
87 QuantLib::ext::shared_ptr<Scenario> baseScenario_;
88 QuantLib::ext::shared_ptr<Scenario> delta_;
89};
90
91} // namespace sensitivity
92} // namespace ore
Delta Scenario class.
const std::map< std::pair< RiskFactorKey::KeyType, std::string >, std::vector< std::vector< Real > > > & coordinates() const override
Get coordinates.
void setAbsolute(const bool b) override
Set if this is an absolute scenario.
const std::string & label() const override
Return the scenario label.
const Date & asof() const override
Return the scenario asof date.
QuantLib::ext::shared_ptr< Scenario > baseScenario_
QuantLib::ext::shared_ptr< Scenario > clone() const override
clones a scenario and returns a pointer to the new object
void add(const ore::analytics::RiskFactorKey &key, Real value) override
Add an element to the scenario.
bool isAbsolute() const override
Is this an absolute or difference scenario?
QuantLib::ext::shared_ptr< Scenario > delta_
bool isCloseEnough(const QuantLib::ext::shared_ptr< Scenario > &s) const override
checks for equality up to numerical differences
bool has(const ore::analytics::RiskFactorKey &key) const override
Check, get, add a single market point.
void setAsof(const Date &d) override
Set the asof date.
const std::vector< ore::analytics::RiskFactorKey > & keys() const override
Risk factor keys for which this scenario provides data.
void setNumeraire(Real n) override
Set the Numeraire ratio n = N(t) / N(0) so that Price(0) = N(0) * E [Price(t) / N(t) ].
void label(const string &s) override
set the label
QuantLib::ext::shared_ptr< Scenario > delta() const
Get delta.
Real getNumeraire() const override
Get Numeraire ratio n = N(t) / N(0) so that Price(0) = N(0) * E [Price(t) / N(t) ].
QuantLib::ext::shared_ptr< Scenario > base() const
Get base.
Data types stored in the scenario class.
Definition: scenario.hpp:48
Scenario Base Class.
Definition: scenario.hpp:138
Scenario class.