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

lballabio / QuantLib / 21247173144

22 Jan 2026 11:44AM UTC coverage: 74.184% (+0.01%) from 74.172%
21247173144

Pull #2414

github

web-flow
Merge d5c127c70 into 71e800be7
Pull Request #2414: Add FX Forward instrument, engine, and tests

102 of 111 new or added lines in 3 files covered. (91.89%)

345 existing lines in 25 files now uncovered.

57443 of 77433 relevant lines covered (74.18%)

8775180.22 hits per line

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

96.36
/ql/processes/mfstateprocess.cpp
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2

3
/*
4
 Copyright (C) 2013 Peter Caspers
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
#include <ql/processes/mfstateprocess.hpp>
21

22
namespace QuantLib {
23

24
    MfStateProcess::MfStateProcess(Real reversion, Array times, Array vols)
15✔
25
    : reversion_(reversion), times_(std::move(times)), vols_(std::move(vols)) {
15✔
26
        if (reversion_ < QL_EPSILON && -reversion_ < QL_EPSILON)
15✔
27
            reversionZero_ = true;
2✔
28
        checkTimesVols();
15✔
29
    }
15✔
30

31
    void MfStateProcess::setTimes(Array times) {
12✔
32
        times_ = std::move(times);
33
        checkTimesVols();
12✔
34
        notifyObservers();
12✔
35
    }
12✔
36

37
    void MfStateProcess::setVols(Array vols) {
142✔
38
        vols_ = std::move(vols);
39
        checkTimesVols();
142✔
40
        notifyObservers();
142✔
41
    }
142✔
42

43
    void MfStateProcess::checkTimesVols() const {
169✔
44
        QL_REQUIRE(times_.size() == vols_.size() - 1,
169✔
45
                   "number of volatilities ("
46
                       << vols_.size() << ") compared to number of times ("
47
                       << times_.size() << " must be bigger by one");
48
        for (int i = 0; i < ((int)times_.size()) - 1; i++)
1,040✔
49
            QL_REQUIRE(times_[i] < times_[i + 1], "times must be increasing ("
871✔
50
                                                    << times_[i] << "@" << i
51
                                                    << " , " << times_[i + 1]
52
                                                    << "@" << i + 1 << ")");
53
        for (Size i = 0; i < vols_.size(); i++)
1,359✔
54
            QL_REQUIRE(vols_[i] >= 0.0, "volatilities must be non negative ("
1,190✔
55
                                           << vols_[i] << "@" << i << ")");
56
    }
169✔
57

UNCOV
58
    Real MfStateProcess::x0() const { return 0.0; }
×
59

UNCOV
60
    Real MfStateProcess::drift(Time, Real) const { return 0.0; }
×
61

62
    Real MfStateProcess::diffusion(Time t, Real) const {
7✔
63
        Size i =
64
            std::upper_bound(times_.begin(), times_.end(), t) - times_.begin();
7✔
65
        return vols_[i];
7✔
66
    }
67

68
    Real MfStateProcess::expectation(Time, Real x0, Time dt) const {
13,666✔
69
        return x0;
13,666✔
70
    }
71

72
    Real MfStateProcess::stdDeviation(Time t, Real x0, Time dt) const {
19,855,825✔
73
        return std::sqrt(variance(t, x0, dt));
19,855,825✔
74
    }
75

76
    Real MfStateProcess::variance(Time t, Real, Time dt) const {
19,855,841✔
77

78
        if (dt < QL_EPSILON)
19,855,841✔
79
            return 0.0;
80
        if (times_.empty())
19,571,209✔
81
            return reversionZero_ ? dt
15,591,311✔
82
                                  : 1.0 / (2.0 * reversion_) *
15,591,309✔
83
                                        (std::exp(2.0 * reversion_ * (t + dt)) -
15,591,309✔
84
                                         std::exp(2.0 * reversion_ * t));
15,591,309✔
85

86
        Size i =
87
            std::upper_bound(times_.begin(), times_.end(), t) - times_.begin();
3,979,898✔
88
        Size j = std::upper_bound(times_.begin(), times_.end(), t + dt) -
3,979,898✔
89
                 times_.begin();
3,979,898✔
90

91
        Real v = 0.0;
92

93
        for (Size k = i; k < j; k++) {
17,104,631✔
94
            if (reversionZero_)
13,124,733✔
95
                v += vols_[k] * vols_[k] *
14✔
96
                     (times_[k] - std::max(k > 0 ? times_[k - 1] : 0.0, t));
8✔
97
            else
98
                v += 1.0 / (2.0 * reversion_) * vols_[k] * vols_[k] *
13,124,726✔
99
                     (std::exp(2.0 * reversion_ * times_[k]) -
26,249,452✔
100
                      std::exp(2.0 * reversion_ *
13,124,726✔
101
                               std::max(k > 0 ? times_[k - 1] : 0.0, t)));
13,127,103✔
102
        }
103

104
        if (reversionZero_)
3,979,898✔
105
            v += vols_[j] * vols_[j] *
12✔
106
                 (t + dt - std::max(j > 0 ? times_[j - 1] : 0.0, t));
11✔
107
        else
108
            v += 1.0 / (2.0 * reversion_) * vols_[j] * vols_[j] *
3,979,892✔
109
                 (std::exp(2.0 * reversion_ * (t + dt)) -
7,959,784✔
110
                  std::exp(2.0 * reversion_ *
3,979,892✔
111
                           (std::max(j > 0 ? times_[j - 1] : 0.0, t))));
7,962,054✔
112

113
        return v;
114
    }
115
}
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