1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
Copyright (C) 2015 Peter Caspers
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/
QuantLib is free software: you can redistribute it and/or modify it
under the terms of the QuantLib license. You should have received a
copy of the license along with this program; if not, please email
<quantlib-dev@lists.sf.net>. The license is also available online at
<https://www.quantlib.org/license.shtml>.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/
/*! \file gsrprocesscore.hpp
\brief Core computations for the gsr process in risk neutral
and T-forward measure.
\warning Results are cached for performance reasons, so if
parameters change, you need to call flushCache() to
avoid inconsistent results.
*/
#ifndef quantlib_gsr_process_core_hpp
#define quantlib_gsr_process_core_hpp
#include <ql/math/array.hpp>
#include <ql/math/comparison.hpp>
#include <map>
namespace QuantLib::detail {
class GsrProcessCore {
public:
GsrProcessCore(const Array& times, const Array& vols, const Array& reversions, Real T = 60.0);
// conditional expectation, x0 dependent part
Real expectation_x0dep_part(Time w, Real xw, Time dt) const;
// conditional expectation, x0 independent part
// in the risk neutral measure
Real expectation_rn_part(Time w, Time dt) const;
// conditional expectation, drift adjustment for
// the T-forward measure
Real expectation_tf_part(Time w, Time dt) const;
// conditional variance
Real variance(Time w, Time dt) const;
// y(t)
Real y(Time t) const;
// G(t,w)
Real G(Time t, Time w) const;
// sigma
Real sigma(Time t) const;
// reversion
Real reversion(Time t) const;
// reset cache
void flushCache() const;
protected:
const Array ×_, &vols_, &reversions_;
private:
int lowerIndex(Time t) const;
int upperIndex(Time t) const;
Real time2(Size index) const;
Real cappedTime(Size index, Real cap = Null<Real>()) const;
Real flooredTime(Size index, Real floor = Null<Real>()) const;
Real vol(Size index) const;
Real rev(Size index) const;
bool revZero(Size index) const;
mutable std::map<std::pair<Real, Real>, Real> cache1_, cache2a_, cache2b_,
cache3_, cache5_;
mutable std::map<Real, Real> cache4_;
Time T_;
mutable std::vector<bool> revZero_;
}; // GsrProcessCore
// inline definitions
inline Real GsrProcessCore::sigma(const Time t) const {
return vol(lowerIndex(t));
}
inline Real GsrProcessCore::reversion(const Time t) const {
return rev(lowerIndex(t));
}
} // namespace QuantLib
#endif
|