QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
Loading...
Searching...
No Matches
globalbootstrapvars.cpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
6#include <utility>
7
8namespace QuantLib {
9
10 SimpleQuoteVariables::SimpleQuoteVariables(std::vector<ext::shared_ptr<SimpleQuote>> quotes,
11 std::vector<Real> initialGuesses,
12 std::vector<Real> lowerBounds)
13 : quotes_(std::move(quotes)), initialGuesses_(std::move(initialGuesses)),
14 lowerBounds_(std::move(lowerBounds)) {
15 QL_REQUIRE(initialGuesses_.size() <= quotes_.size(), "too many initialGuesses");
16 QL_REQUIRE(lowerBounds_.size() <= quotes_.size(), "too many lowerBounds");
17 }
18
20 Array guesses(quotes_.size());
21 for (Size i = 0, size = guesses.size(); i < size; ++i) {
22 Real guess;
23 if (validData) {
24 guess = quotes_[i]->value();
25 } else {
26 guess = detail::get(initialGuesses_, i, 0.0);
27 quotes_[i]->setValue(guess);
28 }
29 guesses[i] = transformInverse(guess, i);
30 }
31 return guesses;
32 }
33
35 for (Size i = 0, size = x.size(); i < size; ++i) {
36 quotes_[i]->setValue(transformDirect(x[i], i));
37 }
38 }
39
41 const Real lb = detail::get(lowerBounds_, i, Null<Real>());
42 return lb == Null<Real>() ? x : std::exp(x) + lb;
43 }
44
46 const Real lb = detail::get(lowerBounds_, i, Null<Real>());
47 return lb == Null<Real>() ? x : std::log(x - lb);
48 }
49}
1-D array used in linear algebra.
Definition: array.hpp:52
Size size() const
dimension of the array
Definition: array.hpp:483
template class providing a null value for a given type.
Definition: null.hpp:59
SimpleQuoteVariables(std::vector< ext::shared_ptr< SimpleQuote > > quotes, std::vector< Real > initialGuesses={}, std::vector< Real > lowerBounds={})
Array initialize(bool validData) override
std::vector< ext::shared_ptr< SimpleQuote > > quotes_
Real transformDirect(Real x, Size i) const
Real transformInverse(Real x, Size i) const
void update(const Array &x) override
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
T get(const std::vector< T > &v, Size i, U defaultValue)
Definition: vectors.hpp:33
Definition: any.hpp:37
STL namespace.
null values
Utilities for vector manipulation.