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

lballabio / QuantLib / 10097394869

25 Jul 2024 03:42PM UTC coverage: 72.623% (-0.001%) from 72.624%
10097394869

push

github

lballabio
Automated fixes by clang-tidy

19 of 27 new or added lines in 18 files covered. (70.37%)

1 existing line in 1 file now uncovered.

55035 of 75782 relevant lines covered (72.62%)

8648991.77 hits per line

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

78.26
/ql/instruments/compositeinstrument.cpp
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2

3
/*
4
 Copyright (C) 2006 StatPro Italia srl
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
 <http://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/instruments/compositeinstrument.hpp>
21

22
namespace QuantLib {
23

24
    void CompositeInstrument::add(const ext::shared_ptr<Instrument>& instrument, Real multiplier) {
100✔
25
        QL_REQUIRE(instrument, "null instrument provided");
100✔
26
        components_.emplace_back(instrument, multiplier);
100✔
27
        registerWith(instrument);
100✔
28
        update();
100✔
29
        // When we ask for the NPV of an expired composite, the
30
        // components are not recalculated and thus wouldn't forward
31
        // later notifications according to the default behavior of
32
        // LazyObject instances.  This means that even if the
33
        // evaluation date changes so that the composite is no longer
34
        // expired, the instrument wouldn't be notified and thus it
35
        // wouldn't recalculate.  To avoid this, we override the
36
        // default behavior of the components.
37
        instrument->alwaysForwardNotifications();
100✔
38
    }
100✔
39

40
    void CompositeInstrument::subtract(
96✔
41
           const ext::shared_ptr<Instrument>& instrument, Real multiplier) {
42
        add(instrument, -multiplier);
96✔
43
    }
96✔
44

45
    bool CompositeInstrument::isExpired() const {
103✔
46
        for (const auto& component : components_) {
105✔
47
            if (!component.first->isExpired())
103✔
48
                return false;
49
        }
50
        return true;
51
    }
52

53
    void CompositeInstrument::performCalculations() const {
100✔
54
        NPV_ = 0.0;
100✔
55
        for (const auto& component : components_) {
2,385✔
56
            NPV_ += component.second * component.first->NPV();
2,285✔
57
        }
58
    }
100✔
59

60
    void CompositeInstrument::deepUpdate() {
×
NEW
61
        for (auto i=components_.begin(); i!=components_.end(); ++i) {
×
62
            i->first->deepUpdate();
×
63
        }
64
        update();
×
65
    }
×
66

67
}
68

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