QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
nonlinearfittingmethods.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2007 Allen Kuo
5 Copyright (C) 2010 Alessandro Roveda
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
25#ifndef quantlib_nonlinear_fitting_methods_hpp
26#define quantlib_nonlinear_fitting_methods_hpp
27
28#include <ql/termstructures/yield/fittedbonddiscountcurve.hpp>
29#include <ql/math/bspline.hpp>
30#include <ql/shared_ptr.hpp>
31
32namespace QuantLib {
33
35
51 public:
53 const Array& weights = Array(),
54 const ext::shared_ptr<OptimizationMethod>& optimizationMethod =
55 ext::shared_ptr<OptimizationMethod>(),
56 const Array& l2 = Array(),
57 Real minCutoffTime = 0.0,
58 Real maxCutoffTime = QL_MAX_REAL,
59 Size numCoeffs = 9,
60 Real fixedKappa = Null<Real>());
62 const Array& weights,
63 const Array& l2,
64 Real minCutoffTime = 0.0,
65 Real maxCutoffTime = QL_MAX_REAL,
66 Size numCoeffs = 9,
67 Real fixedKappa = Null<Real>());
69 Size numCoeffs,
70 Real fixedKappa,
71 const Array& weights = Array() );
72
73
74 std::unique_ptr<FittedBondDiscountCurve::FittingMethod> clone() const override;
75 private:
78 Size size() const override;
79 DiscountFactor discountFunction(const Array& x, Time t) const override;
80 };
81
82
84
95 public:
97 const ext::shared_ptr<OptimizationMethod>& optimizationMethod =
98 ext::shared_ptr<OptimizationMethod>(),
99 const Array& l2 = Array(),
100 Real minCutoffTime = 0.0,
101 Real maxCutoffTime = QL_MAX_REAL);
103 const Array& l2,
104 Real minCutoffTime = 0.0,
105 Real maxCutoffTime = QL_MAX_REAL);
106 std::unique_ptr<FittedBondDiscountCurve::FittingMethod> clone() const override;
107 private:
108 Size size() const override;
109 DiscountFactor discountFunction(const Array& x, Time t) const override;
110 };
111
112
114
127 public:
129 const ext::shared_ptr<OptimizationMethod>& optimizationMethod =
130 ext::shared_ptr<OptimizationMethod>(),
131 const Array& l2 = Array(),
132 Real minCutoffTime = 0.0,
133 Real maxCutoffTime = QL_MAX_REAL);
135 const Array& l2,
136 Real minCutoffTime = 0.0,
137 Real maxCutoffTime = QL_MAX_REAL);
138 std::unique_ptr<FittedBondDiscountCurve::FittingMethod> clone() const override;
139 private:
140 Size size() const override;
141 DiscountFactor discountFunction(const Array& x, Time t) const override;
142 };
143
144
146
166 public:
167 CubicBSplinesFitting(const std::vector<Time>& knotVector,
168 bool constrainAtZero = true,
169 const Array& weights = Array(),
170 const ext::shared_ptr<OptimizationMethod>& optimizationMethod =
171 ext::shared_ptr<OptimizationMethod>(),
172 const Array& l2 = Array(),
173 Real minCutoffTime = 0.0,
174 Real maxCutoffTime = QL_MAX_REAL);
175 CubicBSplinesFitting(const std::vector<Time>& knotVector,
176 bool constrainAtZero,
177 const Array& weights,
178 const Array& l2,
179 Real minCutoffTime = 0.0,
180 Real maxCutoffTime = QL_MAX_REAL);
182 Real basisFunction(Integer i, Time t) const;
183 std::unique_ptr<FittedBondDiscountCurve::FittingMethod> clone() const override;
184 private:
185 Size size() const override;
186 DiscountFactor discountFunction(const Array& x, Time t) const override;
191 };
192
193
195 /* Fits a discount function to the simple polynomial form:
196 \f[
197 d(t) = \sum_{i=0}^{degree} c_i * t^{i}
198 \f]
199 where the constants \f$ c_i \f$ are to be determined.
200
201 This is a simple/crude, but fast and robust, means of fitting
202 a yield curve.
203 */
206 public:
208 bool constrainAtZero = true,
209 const Array& weights = Array(),
210 const ext::shared_ptr<OptimizationMethod>& optimizationMethod =
211 ext::shared_ptr<OptimizationMethod>(),
212 const Array& l2 = Array(),
213 Real minCutoffTime = 0.0,
214 Real maxCutoffTime = QL_MAX_REAL);
216 bool constrainAtZero,
217 const Array& weights,
218 const Array& l2,
219 Real minCutoffTime = 0.0,
220 Real maxCutoffTime = QL_MAX_REAL);
221 std::unique_ptr<FittedBondDiscountCurve::FittingMethod> clone() const override;
222 private:
223 Size size() const override;
224 DiscountFactor discountFunction(const Array& x, Time t) const override;
226 };
227
228
230 /* Fits a spread curve on top of a discount function according to given parametric method
231 */
234 public:
235 SpreadFittingMethod(const ext::shared_ptr<FittingMethod>& method,
236 Handle<YieldTermStructure> discountCurve,
237 Real minCutoffTime = 0.0,
238 Real maxCutoffTime = QL_MAX_REAL);
239 std::unique_ptr<FittedBondDiscountCurve::FittingMethod> clone() const override;
240 protected:
241 void init() override;
242
243 private:
244 Size size() const override;
245 DiscountFactor discountFunction(const Array& x, Time t) const override;
246 // underlying parametric method
247 ext::shared_ptr<FittingMethod> method_;
248 // adjustment in case underlying discount curve has different reference date
250 // discount curve from on top of which the spread will be calculated
252 };
253}
254
255
256#endif
1-D array used in linear algebra.
Definition: array.hpp:52
B-spline basis functions.
Definition: bspline.hpp:58
CubicSpline B-splines fitting method.
std::unique_ptr< FittedBondDiscountCurve::FittingMethod > clone() const override
clone of the current object
Size size() const override
total number of coefficients to fit/solve for
Real basisFunction(Integer i, Time t) const
cubic B-spline basis functions
Natural N_
N_th basis function coefficient to solve for when d(0)=1.
DiscountFactor discountFunction(const Array &x, Time t) const override
discount function called by FittedBondDiscountCurve
Exponential-splines fitting method.
std::unique_ptr< FittedBondDiscountCurve::FittingMethod > clone() const override
clone of the current object
Size size() const override
total number of coefficients to fit/solve for
DiscountFactor discountFunction(const Array &x, Time t) const override
discount function called by FittedBondDiscountCurve
Base fitting method used to construct a fitted bond discount curve.
bool constrainAtZero() const
return whether there is a constraint at zero
Array l2() const
return l2 penalties being used
ext::shared_ptr< OptimizationMethod > optimizationMethod() const
return optimization method being used
Shared handle to an observable.
Definition: handle.hpp:41
Nelson-Siegel fitting method.
std::unique_ptr< FittedBondDiscountCurve::FittingMethod > clone() const override
clone of the current object
Size size() const override
total number of coefficients to fit/solve for
DiscountFactor discountFunction(const Array &x, Time t) const override
discount function called by FittedBondDiscountCurve
template class providing a null value for a given type.
Definition: null.hpp:76
Simple polynomial fitting method.
std::unique_ptr< FittedBondDiscountCurve::FittingMethod > clone() const override
clone of the current object
Size size() const override
total number of coefficients to fit/solve for
DiscountFactor discountFunction(const Array &x, Time t) const override
discount function called by FittedBondDiscountCurve
Spread fitting method helper.
std::unique_ptr< FittedBondDiscountCurve::FittingMethod > clone() const override
clone of the current object
Size size() const override
total number of coefficients to fit/solve for
Handle< YieldTermStructure > discountingCurve_
ext::shared_ptr< FittingMethod > method_
void init() override
rerun every time instruments/referenceDate changes
DiscountFactor discountFunction(const Array &x, Time t) const override
discount function called by FittedBondDiscountCurve
std::unique_ptr< FittedBondDiscountCurve::FittingMethod > clone() const override
clone of the current object
Size size() const override
total number of coefficients to fit/solve for
DiscountFactor discountFunction(const Array &x, Time t) const override
discount function called by FittedBondDiscountCurve
#define QL_MAX_REAL
Definition: qldefines.hpp:176
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real DiscountFactor
discount factor between dates
Definition: types.hpp:66
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
QL_INTEGER Integer
integer number
Definition: types.hpp:35
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35