/src/quantlib/ql/models/equity/gjrgarchmodel.cpp
Line | Count | Source |
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 | | <https://www.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 | | #include <ql/models/equity/gjrgarchmodel.hpp> |
21 | | #include <ql/quotes/simplequote.hpp> |
22 | | #include <ql/shared_ptr.hpp> |
23 | | |
24 | | namespace QuantLib { |
25 | | |
26 | | class GJRGARCHModel::VolatilityConstraint : public Constraint { |
27 | | private: |
28 | | class Impl final : public Constraint::Impl { |
29 | | public: |
30 | 0 | bool test(const Array& params) const override { |
31 | 0 | const Real beta = params[2]; |
32 | 0 | const Real gamma = params[3]; |
33 | |
|
34 | 0 | return (beta+gamma >= 0.0); |
35 | 0 | } |
36 | | }; |
37 | | public: |
38 | | VolatilityConstraint() |
39 | 0 | : Constraint(ext::shared_ptr<Constraint::Impl>( |
40 | 0 | new VolatilityConstraint::Impl)) {} |
41 | | }; |
42 | | |
43 | | GJRGARCHModel::GJRGARCHModel( |
44 | | const ext::shared_ptr<GJRGARCHProcess> & process) |
45 | 0 | : CalibratedModel(6), process_(process) { |
46 | 0 | arguments_[0] = ConstantParameter(process->omega(), |
47 | 0 | PositiveConstraint()); |
48 | 0 | arguments_[1] = ConstantParameter(process->alpha(), |
49 | 0 | BoundaryConstraint( 0.0, 1.0)); |
50 | 0 | arguments_[2] = ConstantParameter(process->beta(), |
51 | 0 | BoundaryConstraint( 0.0, 1.0)); |
52 | 0 | arguments_[3] = ConstantParameter(process->gamma(), |
53 | 0 | BoundaryConstraint(-1.0, 1.0)); |
54 | 0 | arguments_[4] = ConstantParameter(process->lambda(), NoConstraint()); |
55 | 0 | arguments_[5] = ConstantParameter(process->v0(), |
56 | 0 | PositiveConstraint()); |
57 | |
|
58 | 0 | constraint_ = ext::shared_ptr<Constraint>( |
59 | 0 | new CompositeConstraint(*constraint_, VolatilityConstraint())); |
60 | |
|
61 | 0 | GJRGARCHModel::generateArguments(); |
62 | |
|
63 | 0 | registerWith(process_->riskFreeRate()); |
64 | 0 | registerWith(process_->dividendYield()); |
65 | 0 | registerWith(process_->s0()); |
66 | 0 | } Unexecuted instantiation: QuantLib::GJRGARCHModel::GJRGARCHModel(boost::shared_ptr<QuantLib::GJRGARCHProcess> const&) Unexecuted instantiation: QuantLib::GJRGARCHModel::GJRGARCHModel(boost::shared_ptr<QuantLib::GJRGARCHProcess> const&) |
67 | | |
68 | 0 | void GJRGARCHModel::generateArguments() { |
69 | 0 | process_ = ext::make_shared<GJRGARCHProcess>(process_->riskFreeRate(), |
70 | 0 | process_->dividendYield(), |
71 | 0 | process_->s0(), |
72 | 0 | v0(), omega(), |
73 | 0 | alpha(), beta(), |
74 | 0 | gamma(), lambda(), |
75 | 0 | process_->daysPerYear()); |
76 | 0 | } |
77 | | } |
78 | | |