35 class CalibratedModel::CalibrationFunction :
public CostFunction {
38 const vector<ext::shared_ptr<CalibrationHelper> >& h,
41 : model_(model,
null_deleter()), instruments_(h), weights_(
std::move(weights)),
42 projection_(projection) {}
44 ~CalibrationFunction()
override =
default;
46 Real value(
const Array&
params)
const override {
47 model_->setParams(projection_.include(
params));
49 for (
Size i=0; i<instruments_.size(); i++) {
50 Real diff = instruments_[i]->calibrationError();
51 value += diff*diff*weights_[i];
53 return std::sqrt(value);
56 Array values(
const Array&
params)
const override {
57 model_->setParams(projection_.include(
params));
58 Array values(instruments_.size());
59 for (
Size i=0; i<instruments_.size(); i++) {
60 values[i] = instruments_[i]->calibrationError()
61 *std::sqrt(weights_[i]);
66 Real finiteDifferenceEpsilon()
const override {
return 1e-6; }
69 ext::shared_ptr<CalibratedModel> model_;
70 const vector<ext::shared_ptr<CalibrationHelper> >& instruments_;
71 vector<Real> weights_;
72 const Projection projection_;
76 const vector<ext::shared_ptr<CalibrationHelper> >& instruments,
80 const vector<Real>& weights,
81 const vector<bool>& fixParameters) {
83 QL_REQUIRE(!instruments.empty(),
"no instruments provided");
86 if (additionalConstraint.
empty())
91 QL_REQUIRE(weights.empty() || weights.size() == instruments.size(),
92 "mismatch between number of instruments (" <<
93 instruments.size() <<
") and weights (" <<
94 weights.size() <<
")");
96 weights.empty() ? vector<Real>(instruments.size(), 1.0): weights;
99 QL_REQUIRE(fixParameters.empty() || fixParameters.size() == prms.
size(),
100 "mismatch between number of parameters (" <<
101 prms.
size() <<
") and fixed-parameter specs (" <<
102 fixParameters.size() <<
")");
103 vector<bool> all(prms.
size(),
false);
105 CalibrationFunction
f(
this,instruments,w,proj);
119 const vector<ext::shared_ptr<CalibrationHelper> >& instruments) {
120 vector<Real> w = vector<Real>(instruments.size(), 1.0);
122 CalibrationFunction
f(
this, instruments, w, p);
129 size += argument.
size();
141 for (
Size j = 0; j < argument.size(); ++j, ++p) {
143 argument.setParam(j, *p);
1-D array used in linear algebra.
const Real * const_iterator
bool empty() const
whether the array is empty
const_iterator end() const
Size size() const
dimension of the array
const_iterator begin() const
virtual void generateArguments()
Array params() const
Returns array of arguments on which calibration is done.
EndCriteria::Type endCriteria() const
Returns end criteria result.
Real value(const Array ¶ms, const std::vector< ext::shared_ptr< CalibrationHelper > > &)
Integer functionEvaluation_
EndCriteria::Type shortRateEndCriteria_
ext::shared_ptr< Constraint > constraint_
std::vector< Parameter > arguments_
CalibratedModel(Size nArguments)
virtual void calibrate(const std::vector< ext::shared_ptr< CalibrationHelper > > &, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >(), const std::vector< bool > &fixParameters=std::vector< bool >())
Calibrate to a set of market instruments (usually caps/swaptions)
virtual void setParams(const Array ¶ms)
Constraint enforcing both given sub-constraints
Cost function abstract class for optimization problem.
Criteria to end optimization process:
Abstract class for constrained optimization method.
virtual EndCriteria::Type minimize(Problem &P, const EndCriteria &endCriteria)=0
minimize the optimization problem P
Constrained optimization problem.
const Array & currentValue() const
current value of the local minimum
Integer functionEvaluation() const
number of evaluation of cost function
Array values(const Array &x)
call cost values computation and increment evaluation counter
virtual Array include(const Array &projectedParameters) const
returns whole set of parameters corresponding to the set
virtual Array project(const Array ¶meters) const
returns the subset of free parameters corresponding
ShortRateModel(Size nArguments)
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
std::size_t Size
size of a container
Abstract interest rate model class.
empty deleter for shared_ptr
Abstract optimization problem class.