QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
abcdcalibration.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2006, 2007, 2015 Ferdinando Ametrano
5 Copyright (C) 2006 Cristina Duminuco
6 Copyright (C) 2007 Giorgio Facchinetti
7 Copyright (C) 2015 Paolo Mazzocchi
8
9 This file is part of QuantLib, a free-software/open-source library
10 for financial quantitative analysts and developers - http://quantlib.org/
11
12 QuantLib is free software: you can redistribute it and/or modify it
13 under the terms of the QuantLib license. You should have received a
14 copy of the license along with this program; if not, please email
15 <quantlib-dev@lists.sf.net>. The license is also available online at
16 <http://quantlib.org/license.shtml>.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the license for more details.
21*/
22
23#ifndef quantlib_abcdcalibration_hpp
24#define quantlib_abcdcalibration_hpp
25
26
27#include <ql/math/optimization/endcriteria.hpp>
28#include <ql/math/optimization/projectedcostfunction.hpp>
29#include <ql/math/array.hpp>
30
31#include <ql/shared_ptr.hpp>
32
33#include <vector>
34
35
36namespace QuantLib {
37
38 class Quote;
39 class OptimizationMethod;
40 class ParametersTransformation;
41
43 private:
44 class AbcdError : public CostFunction {
45 public:
47
48 Real value(const Array& x) const override {
49 const Array y = abcd_->transformation_->direct(x);
50 abcd_->a_ = y[0];
51 abcd_->b_ = y[1];
52 abcd_->c_ = y[2];
53 abcd_->d_ = y[3];
54 return abcd_->error();
55 }
56 Array values(const Array& x) const override {
57 const Array y = abcd_->transformation_->direct(x);
58 abcd_->a_ = y[0];
59 abcd_->b_ = y[1];
60 abcd_->c_ = y[2];
61 abcd_->d_ = y[3];
62 return abcd_->errors();
63 }
64
65 private:
67 };
68
70 public:
72 // to constrained <- from unconstrained
73 Array direct(const Array& x) const override;
74 // to unconstrained <- from constrained
75 Array inverse(const Array& x) const override;
76
77 private:
78 mutable Array y_;
79 };
80
81 public:
82 AbcdCalibration() = default;
83 ;
85 const std::vector<Real>& t,
86 const std::vector<Real>& blackVols,
87 Real aGuess = -0.06,
88 Real bGuess = 0.17,
89 Real cGuess = 0.54,
90 Real dGuess = 0.17,
91 bool aIsFixed = false,
92 bool bIsFixed = false,
93 bool cIsFixed = false,
94 bool dIsFixed = false,
95 bool vegaWeighted = false,
96 ext::shared_ptr<EndCriteria> endCriteria = ext::shared_ptr<EndCriteria>(),
97 ext::shared_ptr<OptimizationMethod> method = ext::shared_ptr<OptimizationMethod>());
99 std::vector<Real> k(const std::vector<Real>& t,
100 const std::vector<Real>& blackVols) const;
101 void compute();
102 //calibration results
103 Real value(Real x) const;
104 Real error() const;
105 Real maxError() const;
106 Array errors() const;
108 Real a() const { return a_; }
109 Real b() const { return b_; }
110 Real c() const { return c_; }
111 Real d() const { return d_; }
114 ext::shared_ptr<ParametersTransformation> transformation_;
115 private:
116 // optimization method used for fitting
118 ext::shared_ptr<EndCriteria> endCriteria_;
119 ext::shared_ptr<OptimizationMethod> optMethod_;
120 mutable std::vector<Real> weights_;
123 std::vector<Real> times_, blackVols_;
124 };
125
126}
127
128#endif
Real value(const Array &x) const override
method to overload to compute the cost function value in x
Array values(const Array &x) const override
method to overload to compute the cost function values in x
ext::shared_ptr< EndCriteria > endCriteria_
std::vector< Real > blackVols_
EndCriteria::Type endCriteria() const
ext::shared_ptr< ParametersTransformation > transformation_
std::vector< Real > k(const std::vector< Real > &t, const std::vector< Real > &blackVols) const
adjustment factors needed to match Black vols
std::vector< Real > weights_
std::vector< Real > times_
Parameters.
EndCriteria::Type abcdEndCriteria_
ext::shared_ptr< OptimizationMethod > optMethod_
1-D array used in linear algebra.
Definition: array.hpp:52
Cost function abstract class for optimization problem.
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35