25#ifndef quantlib_garch_volatility_model_hpp
26#define quantlib_garch_volatility_model_hpp
45 [[deprecated(
"If needed, use time_series::const_iterator instead.")]]
54 [[deprecated(
"If needed, use auto or time_series::const_value_iterator. Prefer time_series::const_iterator instead.")]]
99 const auto values = quoteSeries.
values();
100 calibrate(values.cbegin(), values.cend());
112 const auto values = quoteSeries.
values();
113 calibrate(values.cbegin(), values.cend(),
114 method, endCriteria);
120 const Array& initialGuess) {
121 const auto values = quoteSeries.
values();
122 calibrate(values.cbegin(), values.cend(),
123 method, endCriteria, initialGuess);
126 template <
typename ForwardIterator>
127 void calibrate(ForwardIterator begin, ForwardIterator end) {
128 std::vector<Volatility> r2;
130 ext::shared_ptr<Problem> p =
138 template <
typename ForwardIterator>
139 void calibrate(ForwardIterator begin, ForwardIterator end,
142 std::vector<Volatility> r2;
144 ext::shared_ptr<Problem> p =
153 template <
typename ForwardIterator>
154 void calibrate(ForwardIterator begin, ForwardIterator end,
157 const Array& initialGuess) {
158 std::vector<Volatility> r2;
159 to_r2(begin, end, r2);
160 ext::shared_ptr<Problem> p =
174 template <
typename InputIterator>
175 static Real to_r2(InputIterator begin, InputIterator end,
176 std::vector<Volatility>& r2) {
177 Real u2(0.0), mean_r2(0.0), w(1.0);
178 for (; begin != end; ++begin) {
179 u2 = *begin; u2 *= u2;
180 mean_r2 = (1.0 - w) * mean_r2 + w * u2;
190 const std::vector<Volatility>& r2,
200 const std::vector<Volatility>& r2,
211 const std::vector<Volatility>& r2,
215 const Array& initialGuess,
223 const std::vector<Volatility> &r2,
226 const Array& initialGuess,
234 const std::vector<Volatility>& r2,
239 const Array& initialGuess,
245 const std::vector<Volatility> &r2,
249 const Array& initialGuess,
254 template<
class InputIterator>
258 Real u2(0.0), sigma2(0.0);
260 for (; begin != end; ++begin, ++N) {
262 u2 = *begin; u2 *= u2;
263 retval += std::log(sigma2) + u2 / sigma2;
265 return N > 0 ?
Real(retval / (2*N)) : 0.0;
273 template<
class InputIterator>
1-D array used in linear algebra.
Criteria to end optimization process:
Real costFunction(InputIterator begin, InputIterator end) const
Garch11(const time_series &qs, Mode mode=BestOfTwo)
time_series calculate(const time_series "eSeries) override
time_series::const_iterator const_iterator
static ext::shared_ptr< Problem > calibrate_r2(Mode mode, const std::vector< Volatility > &r2, Real mean_r2, Real &alpha, Real &beta, Real &omega)
Garch11(Real a, Real b, Real vl)
void calibrate(ForwardIterator begin, ForwardIterator end, OptimizationMethod &method, EndCriteria endCriteria)
void calibrate(const time_series "eSeries, OptimizationMethod &method, const EndCriteria &endCriteria, const Array &initialGuess)
Real forecast(Real r, Real sigma2) const
QL_DEPRECATED_DISABLE_WARNING typedef time_series::const_value_iterator const_value_iterator
static Real to_r2(InputIterator begin, InputIterator end, std::vector< Volatility > &r2)
void calibrate(const time_series "eSeries, OptimizationMethod &method, const EndCriteria &endCriteria)
static Real costFunction(InputIterator begin, InputIterator end, Real alpha, Real beta, Real omega)
Real logLikelihood() const
TimeSeries< Volatility > time_series
void calibrate(ForwardIterator begin, ForwardIterator end)
void calibrate(ForwardIterator begin, ForwardIterator end, OptimizationMethod &method, EndCriteria endCriteria, const Array &initialGuess)
void calibrate(const time_series "eSeries) override
Abstract class for constrained optimization method.
Container for historical data.
Container::const_iterator const_iterator
std::vector< T > values() const
returns the historical data
boost::transform_iterator< projection_value, const_iterator > const_value_iterator
Abstract constraint class.
ext::function< Real(Real)> b
std::size_t Size
size of a container
ext::shared_ptr< YieldTermStructure > r
Abstract optimization problem class.
#define QL_DEPRECATED_DISABLE_WARNING
#define QL_DEPRECATED_ENABLE_WARNING
Volatility term structures.