Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
crossassetstateprocess.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 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 crossassetstateprocess.hpp
20 \brief crossasset model state process
21 \ingroup crossassetmodel
22 \ingroup processes
23*/
24
25#ifndef quantext_crossasset_stateprocess_hpp
26#define quantext_crossasset_stateprocess_hpp
27
28#include <ql/math/matrixutilities/pseudosqrt.hpp>
29#include <ql/stochasticprocess.hpp>
30
31#include <boost/unordered_map.hpp>
32
33namespace QuantExt {
34using namespace QuantLib;
35
36class CrossAssetModel;
37
38//! Cross Asset Model State Process
39/*! \ingroup crossassetmodel
40 \ingroup processes
41 */
43public:
44 CrossAssetStateProcess(QuantLib::ext::shared_ptr<const CrossAssetModel> model);
45
46 /*! StochasticProcess interface */
47 Size size() const override;
48 Size factors() const override;
49 Array initialValues() const override;
50 Array drift(Time t, const Array& x) const override;
51 Matrix diffusion(Time t, const Array& x) const override;
52 Array evolve(Time t0, const Array& x0, Time dt, const Array& dw) const override;
53
54 // enables and resets the cache, once enabled the simulated times must stay the stame
55 void resetCache(const Size timeSteps) const;
56
57protected:
58 virtual Matrix diffusionOnCorrelatedBrownians(Time t, const Array& x) const;
59 virtual Matrix diffusionOnCorrelatedBrowniansImpl(Time t, const Array& x) const;
60 void updateSqrtCorrelation() const;
61
62 QuantLib::ext::shared_ptr<const CrossAssetModel> model_;
63
64 std::vector<QuantLib::ext::shared_ptr<StochasticProcess>> crCirpp_;
66
67 mutable Matrix sqrtCorrelation_;
68
69 class ExactDiscretization : public StochasticProcess::discretization {
70 public:
71 ExactDiscretization(QuantLib::ext::shared_ptr<const CrossAssetModel> model,
72 SalvagingAlgorithm::Type salvaging = SalvagingAlgorithm::Spectral);
73 virtual Array drift(const StochasticProcess&, Time t0, const Array& x0, Time dt) const override;
74 virtual Matrix diffusion(const StochasticProcess&, Time t0, const Array& x0, Time dt) const override;
75 virtual Matrix covariance(const StochasticProcess&, Time t0, const Array& x0, Time dt) const override;
76 void resetCache(const Size timeSteps) const;
77
78 protected:
79 virtual Array driftImpl1(const StochasticProcess&, Time t0, const Array& x0, Time dt) const;
80 virtual Array driftImpl2(const StochasticProcess&, Time t0, const Array& x0, Time dt) const;
81 virtual Matrix covarianceImpl(const StochasticProcess&, Time t0, const Array& x0, Time dt) const;
82
83 QuantLib::ext::shared_ptr<const CrossAssetModel> model_;
84 SalvagingAlgorithm::Type salvaging_;
85
86 mutable bool cacheNotReady_m_ = true;
87 mutable bool cacheNotReady_d_ = true;
88 mutable bool cacheNotReady_v_ = true;
89 mutable Size timeStepsToCache_m_ = 0;
90 mutable Size timeStepsToCache_d_ = 0;
91 mutable Size timeStepsToCache_v_ = 0;
92 mutable Size timeStepCache_m_ = 0;
93 mutable Size timeStepCache_d_ = 0;
94 mutable Size timeStepCache_v_ = 0;
95 mutable std::vector<Array> cache_m_;
96 mutable std::vector<Matrix> cache_v_, cache_d_;
97 }; // ExactDiscretization
98
99 mutable bool cacheNotReady_m_ = true;
100 mutable bool cacheNotReady_d_ = true;
101 mutable Size timeStepsToCache_m_ = 0;
102 mutable Size timeStepCache_m_ = 0;
103 mutable Size timeStepsToCache_d_ = 0;
104 mutable Size timeStepCache_d_ = 0;
105 mutable std::vector<Array> cache_m_;
106 mutable std::vector<Matrix> cache_d_;
107}; // CrossAssetStateProcess
108
109} // namespace QuantExt
110
111#endif
virtual Matrix diffusion(const StochasticProcess &, Time t0, const Array &x0, Time dt) const override
virtual Matrix covariance(const StochasticProcess &, Time t0, const Array &x0, Time dt) const override
virtual Array driftImpl2(const StochasticProcess &, Time t0, const Array &x0, Time dt) const
virtual Matrix covarianceImpl(const StochasticProcess &, Time t0, const Array &x0, Time dt) const
virtual Array drift(const StochasticProcess &, Time t0, const Array &x0, Time dt) const override
QuantLib::ext::shared_ptr< const CrossAssetModel > model_
virtual Array driftImpl1(const StochasticProcess &, Time t0, const Array &x0, Time dt) const
Cross Asset Model State Process.
std::vector< QuantLib::ext::shared_ptr< StochasticProcess > > crCirpp_
Array drift(Time t, const Array &x) const override
Array evolve(Time t0, const Array &x0, Time dt, const Array &dw) const override
virtual Matrix diffusionOnCorrelatedBrowniansImpl(Time t, const Array &x) const
Matrix diffusion(Time t, const Array &x) const override
virtual Matrix diffusionOnCorrelatedBrownians(Time t, const Array &x) const
QuantLib::ext::shared_ptr< const CrossAssetModel > model_
void resetCache(const Size timeSteps) const