Coverage Report

Created: 2026-06-23 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/models/marketmodels/discounter.cpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2006 Mark Joshi
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/models/marketmodels/discounter.hpp>
21
#include <ql/models/marketmodels/curvestate.hpp>
22
#include <ql/models/marketmodels/utilities.hpp>
23
#include <algorithm>
24
25
namespace QuantLib {
26
27
    MarketModelDiscounter::MarketModelDiscounter(
28
                                        Time paymentTime,
29
0
                                        const std::vector<Time>& rateTimes) {
30
0
        checkIncreasingTimes(rateTimes);
31
0
        before_ = std::lower_bound(rateTimes.begin(), rateTimes.end(),
32
0
                                   paymentTime) - rateTimes.begin();
33
34
        // handle the case where the payment is in the last
35
        // period or after the last period
36
0
        if (before_ > rateTimes.size()-2)
37
0
            before_ =  rateTimes.size()-2;
38
39
0
        beforeWeight_=1.0-(paymentTime-rateTimes[before_])/
40
0
            (rateTimes[before_+1]-rateTimes[before_]);
41
0
    }
42
43
    Real MarketModelDiscounter::numeraireBonds(const CurveState& curveState,
44
0
                                               Size numeraire) const {
45
0
        Real preDF = curveState.discountRatio(before_,numeraire);
46
0
        if (beforeWeight_==1.0)
47
0
            return preDF;
48
49
0
        Real postDF = curveState.discountRatio(before_+1,numeraire);
50
0
        if (beforeWeight_==0.0)
51
0
            return postDF;
52
53
0
        return std::pow(preDF,beforeWeight_)*std::pow(postDF,1.-beforeWeight_);
54
0
    }
55
56
}