Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
deltascenario.cpp
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
21#include <ql/errors.hpp>
22
23namespace ore {
24namespace analytics {
25
26// Delta Scenario class
27
28DeltaScenario::DeltaScenario(const QuantLib::ext::shared_ptr<ore::analytics::Scenario>& baseScenario,
29 const QuantLib::ext::shared_ptr<ore::analytics::Scenario>& incrementalScenario)
30 : baseScenario_(baseScenario), delta_(incrementalScenario) {
31 QL_REQUIRE(
32 baseScenario->isAbsolute() == incrementalScenario->isAbsolute(),
33 "DeltaScenario(): base and incremental scenario must be both absolute or both difference, got isAbsolute = "
34 << std::boolalpha << baseScenario->isAbsolute() << ", " << incrementalScenario->isAbsolute());
35}
36
38 QL_REQUIRE(baseScenario_->has(key), "base scenario must also possess key");
39 if (baseScenario_->get(key) != value)
40 delta_->add(key, value);
41}
42
44 if (delta_->has(key)) {
45 return delta_->get(key);
46 } else {
47 return baseScenario_->get(key);
48 }
49}
50
51QuantLib::ext::shared_ptr<ore::analytics::Scenario> DeltaScenario::clone() const {
52 // NOTE - we are not cloning the base here (is this appropriate?)
53 QuantLib::ext::shared_ptr<Scenario> newDelta = delta_->clone();
54 return QuantLib::ext::make_shared<DeltaScenario>(baseScenario_, newDelta);
55}
56
58 Real deltaNum = delta_->getNumeraire();
59 if (deltaNum == 0.0)
60 deltaNum = baseScenario_->getNumeraire();
61 return deltaNum;
62}
63
64bool DeltaScenario::isCloseEnough(const QuantLib::ext::shared_ptr<Scenario>& s) const {
65 if (auto d = QuantLib::ext::dynamic_pointer_cast<DeltaScenario>(s)) {
66 return (baseScenario_.get() == d->baseScenario_.get() || baseScenario_->isCloseEnough(s)) &&
67 (delta_.get() == d->delta_.get() || delta_->isCloseEnough(s));
68 } else {
70 }
71}
72
73} // namespace analytic
74} // namespace ore
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.
QuantLib::ext::shared_ptr< Scenario > delta_
bool isCloseEnough(const QuantLib::ext::shared_ptr< Scenario > &s) const override
checks for equality up to numerical differences
Real get(const ore::analytics::RiskFactorKey &key) const override
Get an element from the scenario.
Real getNumeraire() const override
Get Numeraire ratio n = N(t) / N(0) so that Price(0) = N(0) * E [Price(t) / N(t) ].
Data types stored in the scenario class.
Definition: scenario.hpp:48
virtual bool isCloseEnough(const QuantLib::ext::shared_ptr< Scenario > &s) const
checks for equality up to numerical differences
Definition: scenario.cpp:38
SafeStack< ValueType > value
Delta scenario class.