• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lballabio / QuantLib / 13667868683

05 Mar 2025 03:28AM UTC coverage: 73.314% (+0.04%) from 73.274%
13667868683

Pull #2163

github

web-flow
Merge 60581c90d into 2391bbf48
Pull Request #2163: Allow optimizing additional variables during global bootstrap

43 of 44 new or added lines in 2 files covered. (97.73%)

1 existing line in 1 file now uncovered.

56252 of 76727 relevant lines covered (73.31%)

8655972.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.15
/ql/termstructures/globalbootstrapvars.cpp
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2

3
#include <ql/termstructures/globalbootstrapvars.hpp>
4
#include <ql/utilities/null.hpp>
5
#include <ql/utilities/vectors.hpp>
6
#include <utility>
7

8
namespace QuantLib {
9

10
    SimpleQuoteVariables::SimpleQuoteVariables(std::vector<ext::shared_ptr<SimpleQuote>> quotes,
1✔
11
                                               std::vector<Real> initialGuesses,
12
                                               std::vector<Real> lowerBounds)
1✔
13
    : quotes_(std::move(quotes)), initialGuesses_(std::move(initialGuesses)),
1✔
14
      lowerBounds_(std::move(lowerBounds)) {
1✔
15
        QL_REQUIRE(initialGuesses_.size() <= quotes_.size(), "too many initialGuesses");
1✔
16
        QL_REQUIRE(lowerBounds_.size() <= quotes_.size(), "too many lowerBounds");
1✔
17
    }
1✔
18

19
    Array SimpleQuoteVariables::initialize(bool validData) {
1✔
20
        Array guesses(quotes_.size());
1✔
21
        for (Size i = 0, size = guesses.size(); i < size; ++i) {
2✔
22
            Real guess;
23
            if (validData) {
1✔
NEW
24
                guess = quotes_[i]->value();
×
25
            } else {
26
                guess = detail::get(initialGuesses_, i, 0.0);
1✔
27
                quotes_[i]->setValue(guess);
1✔
28
            }
29
            guesses[i] = transformInverse(guess, i);
1✔
30
        }
31
        return guesses;
1✔
32
    }
33

34
    void SimpleQuoteVariables::update(const Array& x) {
253✔
35
        for (Size i = 0, size = x.size(); i < size; ++i) {
506✔
36
            quotes_[i]->setValue(transformDirect(x[i], i));
253✔
37
        }
38
    }
253✔
39

40
    Real SimpleQuoteVariables::transformDirect(Real x, Size i) const {
253✔
41
        const Real lb = detail::get(lowerBounds_, i, Null<Real>());
253✔
42
        return lb == Null<Real>() ? x : std::exp(x) + lb;
253✔
43
    }
44

45
    Real SimpleQuoteVariables::transformInverse(Real x, Size i) const {
1✔
46
        const Real lb = detail::get(lowerBounds_, i, Null<Real>());
1✔
47
        return lb == Null<Real>() ? x : std::log(x - lb);
1✔
48
    }
49
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc