Coverage Report

Created: 2026-06-08 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/math/optimization/bfgs.hpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2009 Frédéric Degraeve
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
/*! \file bfgs.hpp
21
    \brief Broyden-Fletcher-Goldfarb-Shanno optimization method
22
*/
23
24
#ifndef quantlib_optimization_bfgs_hpp
25
#define quantlib_optimization_bfgs_hpp
26
27
#include <ql/math/optimization/linesearchbasedmethod.hpp>
28
#include <ql/math/matrix.hpp>
29
30
namespace QuantLib {
31
32
    //! Broyden-Fletcher-Goldfarb-Shanno algorithm
33
    /*! See <http://en.wikipedia.org/wiki/BFGS_method>.
34
35
        Adapted from Numerical Recipes in C, 2nd edition.
36
37
        User has to provide line-search method and optimization end criteria.
38
    */
39
    class BFGS: public LineSearchBasedMethod {
40
      public:
41
        BFGS(const ext::shared_ptr<LineSearch>& lineSearch =
42
                                              ext::shared_ptr<LineSearch>())
43
0
        : LineSearchBasedMethod(lineSearch) {}
44
      private:
45
        //! \name LineSearchBasedMethod interface
46
        //@{
47
        Array getUpdatedDirection(const Problem& P, Real gold2, const Array& oldGradient) override;
48
        //@}
49
        //! inverse of hessian matrix
50
        Matrix inverseHessian_;
51
    };
52
53
}
54
55
#endif