| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2008 Yee Man Chan |
| 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 gjrgarchprocess.hpp |
| 21 | \brief GJR-GARCH(1,1) stochastic process |
| 22 | */ |
| 23 | |
| 24 | #ifndef quantlib_gjrgarch_process_hpp |
| 25 | #define quantlib_gjrgarch_process_hpp |
| 26 | |
| 27 | #include <ql/stochasticprocess.hpp> |
| 28 | #include <ql/termstructures/yieldtermstructure.hpp> |
| 29 | #include <ql/quote.hpp> |
| 30 | |
| 31 | namespace QuantLib { |
| 32 | |
| 33 | //! Stochastic-volatility GJR-GARCH(1,1) process |
| 34 | // parameters supplied should be daily constants |
| 35 | // they are annualized by setting the parameter daysPerYear |
| 36 | /*! This class describes the stochastic volatility |
| 37 | process governed by |
| 38 | \f[ |
| 39 | \begin{array}{rcl} |
| 40 | dS(t, S) &=& \mu S dt + \sqrt{v} S dW_1 \\ |
| 41 | dv(t, S) &=& (\omega + (\beta + \alpha * q_{2} |
| 42 | + \gamma * q_{3} - 1) v) dt + (\alpha \sigma_{12} |
| 43 | + \gamma \sigma_{13}) v dW_1 |
| 44 | + \sqrt{\alpha^{2} (\sigma^{2}_{2} - \sigma^{2}_{12}) |
| 45 | + \gamma^{2} (\sigma^{2}_{3} - \sigma^{2}_{13}) |
| 46 | + 2 \alpha \gamma (\sigma_{23} - \sigma_{12} \sigma_{13})} v dW_2 \ \ |
| 47 | N = normalCDF(\lambda) \\ |
| 48 | n &=& \exp{-\lambda^{2}/2} / \sqrt{2 \pi} \\ |
| 49 | q_{2} &=& 1 + \lambda^{2} \\ |
| 50 | q_{3} &=& \lambda n + N + \lambda^2 N \\ |
| 51 | \sigma^{2}_{2} = 2 + 4 \lambda^{4} \\ |
| 52 | \sigma^{2}_{3} = \lambda^{3} n + 5 \lambda n + 3N |
| 53 | + \lambda^{4} N + 6 \lambda^{2} N -\\lambda^{2} n^{2} - N^{2} |
| 54 | - \lambda^{4} N^{2} - 2 \lambda n N - 2 \lambda^{3} nN |
| 55 | - 2 \lambda^{2} N^{2} \ \ |
| 56 | \sigma_{12} = -2 \lambda \\ |
| 57 | \sigma_{13} = -2 n - 2 \lambda N \\ |
| 58 | \sigma_{23} = 2N + \sigma_{12} \sigma_{13} \\ |
| 59 | \end{array} |
| 60 | \f] |
| 61 | |
| 62 | \ingroup processes |
| 63 | */ |
| 64 | class GJRGARCHProcess : public StochasticProcess { |
| 65 | public: |
| 66 | enum Discretization { PartialTruncation, FullTruncation, |
| 67 | Reflection}; |
| 68 | |
| 69 | GJRGARCHProcess(Handle<YieldTermStructure> riskFreeRate, |
| 70 | Handle<YieldTermStructure> dividendYield, |
| 71 | Handle<Quote> s0, |
| 72 | Real v0, |
| 73 | Real omega, |
| 74 | Real alpha, |
| 75 | Real beta, |
| 76 | Real gamma, |
| 77 | Real lambda, |
| 78 | Real daysPerYear = 252.0, |
| 79 | Discretization d = FullTruncation); |
| 80 | |
| 81 | Size size() const override; |
| 82 | Array initialValues() const override; |
| 83 | Array drift(Time t, const Array& x) const override; |
| 84 | Matrix diffusion(Time t, const Array& x) const override; |
| 85 | Array apply(const Array& x0, const Array& dx) const override; |
| 86 | Array evolve(Time t0, const Array& x0, Time dt, const Array& dw) const override; |
| 87 | |
| 88 | Real v0() const { return v0_; } |
| 89 | Real lambda() const { return lambda_; } |
| 90 | Real omega() const { return omega_; } |
| 91 | Real alpha() const { return alpha_; } |
| 92 | Real beta() const { return beta_; } |
| 93 | Real gamma() const { return gamma_; } |
| 94 | Real daysPerYear() const { return daysPerYear_; } |
| 95 | |
| 96 | const Handle<Quote>& s0() const; |
| 97 | const Handle<YieldTermStructure>& dividendYield() const; |
| 98 | const Handle<YieldTermStructure>& riskFreeRate() const; |
| 99 | |
| 100 | Time time(const Date&) const override; |
| 101 | |
| 102 | private: |
| 103 | Handle<YieldTermStructure> riskFreeRate_, dividendYield_; |
| 104 | Handle<Quote> s0_; |
| 105 | Real v0_, omega_, alpha_, beta_, gamma_, lambda_, daysPerYear_; |
| 106 | Discretization discretization_; |
| 107 | }; |
| 108 | |
| 109 | } |
| 110 | |
| 111 | |
| 112 | #endif |
| 113 | |