| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2016 Klaus Spanderen |
| 5 | |
| 6 | This file is part of QuantLib, a free-software/open-source library |
| 7 | for financial quantitative analysts and developers - http://quantlib.org/ |
| 8 | |
| 9 | QuantLib is free software: you can redistribute it and/or modify it |
| 10 | under the terms of the QuantLib license. You should have received a |
| 11 | copy of the license along with this program; if not, please email |
| 12 | <quantlib-dev@lists.sf.net>. The license is also available online at |
| 13 | <http://quantlib.org/license.shtml>. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 17 | FOR A PARTICULAR PURPOSE. See the license for more details. |
| 18 | */ |
| 19 | |
| 20 | /*! \file normalclvmodel.hpp |
| 21 | \brief CLV model with a normally distributed kernel process |
| 22 | */ |
| 23 | |
| 24 | #ifndef quantlib_normal_clv_model_hpp |
| 25 | #define quantlib_normal_clv_model_hpp |
| 26 | |
| 27 | #include <ql/patterns/lazyobject.hpp> |
| 28 | #include <ql/math/interpolations/linearinterpolation.hpp> |
| 29 | #include <ql/math/interpolations/lagrangeinterpolation.hpp> |
| 30 | #include <ql/math/matrix.hpp> |
| 31 | #include <ql/time/date.hpp> |
| 32 | #include <ql/functional.hpp> |
| 33 | |
| 34 | namespace QuantLib { |
| 35 | /*! References: |
| 36 | |
| 37 | A. Grzelak, 2016, The CLV Framework - |
| 38 | A Fresh Look at Efficient Pricing with Smile |
| 39 | |
| 40 | http://papers.ssrn.com/sol3/papers.cfm?abstract_id=2747541 |
| 41 | */ |
| 42 | |
| 43 | class PricingEngine; |
| 44 | class GBSMRNDCalculator; |
| 45 | class OrnsteinUhlenbeckProcess; |
| 46 | class GeneralizedBlackScholesProcess; |
| 47 | |
| 48 | class NormalCLVModel : public LazyObject { |
| 49 | public: |
| 50 | NormalCLVModel(const ext::shared_ptr<GeneralizedBlackScholesProcess>& bsProcess, |
| 51 | ext::shared_ptr<OrnsteinUhlenbeckProcess> ouProcess, |
| 52 | const std::vector<Date>& maturityDates, |
| 53 | Size lagrangeOrder, |
| 54 | Real pMax = Null<Real>(), |
| 55 | Real pMin = Null<Real>()); |
| 56 | |
| 57 | // cumulative distribution function of the BS process |
| 58 | Real cdf(const Date& d, Real x) const; |
| 59 | |
| 60 | // inverse cumulative distribution function of the BS process |
| 61 | Real invCDF(const Date& d, Real q) const; |
| 62 | |
| 63 | // collocation points of the Ornstein-Uhlenbeck process |
| 64 | Array collocationPointsX(const Date& d) const; |
| 65 | |
| 66 | // collocation points for the underlying Y |
| 67 | Array collocationPointsY(const Date& d) const; |
| 68 | |
| 69 | // CLV mapping function |
| 70 | ext::function<Real(Time, Real)> g() const; |
| 71 | |
| 72 | protected: |
| 73 | void performCalculations() const override; |
| 74 | |
| 75 | private: |
| 76 | class MappingFunction { |
| 77 | public: |
| 78 | explicit MappingFunction(const NormalCLVModel& model); |
| 79 | |
| 80 | Real operator()(Time t, Real x) const; |
| 81 | |
| 82 | private: |
| 83 | mutable Array y_; |
| 84 | const Volatility sigma_; |
| 85 | const ext::shared_ptr<OrnsteinUhlenbeckProcess> ouProcess_; |
| 86 | |
| 87 | struct InterpolationData { |
| 88 | explicit InterpolationData(const NormalCLVModel& model) |
| 89 | : s_(model.x_.size(), model.maturityDates_.size()), |
| 90 | x_(model.x_), |
| 91 | t_(model.maturityTimes_), |
| 92 | lagrangeInterpl_(x_.begin(), x_.end(), x_.begin()) {} |
| 93 | |
| 94 | Matrix s_; |
| 95 | std::vector<LinearInterpolation> interpl_; |
| 96 | |
| 97 | const Array x_; |
| 98 | const std::vector<Time> t_; |
| 99 | const LagrangeInterpolation lagrangeInterpl_; |
| 100 | }; |
| 101 | |
| 102 | const ext::shared_ptr<InterpolationData> data_; |
| 103 | }; |
| 104 | |
| 105 | |
| 106 | const Array x_; |
| 107 | const Volatility sigma_; |
| 108 | const ext::shared_ptr<GeneralizedBlackScholesProcess> bsProcess_; |
| 109 | const ext::shared_ptr<OrnsteinUhlenbeckProcess> ouProcess_; |
| 110 | const std::vector<Date> maturityDates_; |
| 111 | const ext::shared_ptr<GBSMRNDCalculator> rndCalculator_; |
| 112 | |
| 113 | std::vector<Time> maturityTimes_; |
| 114 | mutable ext::function<Real(Time, Real)> g_; |
| 115 | }; |
| 116 | } |
| 117 | |
| 118 | #endif |
| 119 | |