• 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

0.0
/ql/experimental/commodities/commoditycurve.cpp
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2

3
/*
4
 Copyright (C) 2008 J. Erik Radmall
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/experimental/commodities/commoditycurve.hpp>
21
#include <ql/experimental/commodities/commoditypricinghelpers.hpp>
22
#include <utility>
23

24
namespace QuantLib {
25

26
    CommodityCurve::CommodityCurve(std::string name,
×
27
                                   CommodityType commodityType,
28
                                   Currency currency,
29
                                   UnitOfMeasure unitOfMeasure,
30
                                   const Calendar& calendar,
31
                                   const std::vector<Date>& dates,
32
                                   std::vector<Real> prices,
33
                                   const DayCounter& dayCounter)
×
34
    : TermStructure(dates[0], calendar, dayCounter), name_(std::move(name)),
×
35
      commodityType_(std::move(commodityType)), unitOfMeasure_(std::move(unitOfMeasure)),
36
      currency_(std::move(currency)), dates_(dates), data_(std::move(prices)),
×
37
      interpolator_(ForwardFlat()), basisOfCurveUomConversionFactor_(1) {
×
38

39
        QL_REQUIRE(dates_.size()>1, "too few dates");
×
40
        QL_REQUIRE(data_.size()==dates_.size(), "dates/prices count mismatch");
×
41

42
        times_.resize(dates_.size());
×
43
        times_[0]=0.0;
×
44
        for (Size i = 1; i < dates_.size(); i++) {
×
45
            QL_REQUIRE(dates_[i] > dates_[i-1],
×
46
                       "invalid date (" << dates_[i] << ", vs "
47
                       << dates_[i-1] << ")");
48
            times_[i] = dayCounter.yearFraction(dates_[0], dates_[i]);
×
49
        }
50

51
        interpolation_ =
52
            interpolator_.interpolate(times_.begin(), times_.end(),
×
53
                                      data_.begin());
×
54
        interpolation_.update();
×
55
    }
×
56

57
    CommodityCurve::CommodityCurve(std::string name,
×
58
                                   CommodityType commodityType,
59
                                   Currency currency,
60
                                   UnitOfMeasure unitOfMeasure,
61
                                   const Calendar& calendar,
62
                                   const DayCounter& dayCounter)
×
63
    : TermStructure(0, calendar, dayCounter), name_(std::move(name)),
64
      commodityType_(std::move(commodityType)), unitOfMeasure_(std::move(unitOfMeasure)),
65
      currency_(std::move(currency)), interpolator_(ForwardFlat()),
66
      basisOfCurveUomConversionFactor_(1) {}
×
67

68
    void CommodityCurve::setPrices(std::map<Date, Real>& prices) {
×
69
        QL_REQUIRE(prices.size()>1, "too few prices");
×
70

71
        dates_.clear();
×
72
        data_.clear();
×
NEW
73
        for (auto i = prices.begin(); i != prices.end(); ++i) {
×
74
            dates_.push_back(i->first);
×
75
            data_.push_back(i->second);
×
76
        }
77

78
        times_.resize(dates_.size());
×
79
        times_[0]=0.0;
×
80
        for (Size i = 1; i < dates_.size(); i++)
×
81
            times_[i] = dayCounter().yearFraction(dates_[0], dates_[i]);
×
82

83
        interpolation_ =
84
            interpolator_.interpolate(times_.begin(), times_.end(),
×
85
                                      data_.begin());
×
86
        interpolation_.update();
×
87
    }
×
88

89
    void CommodityCurve::setBasisOfCurve(
×
90
                      const ext::shared_ptr<CommodityCurve>& basisOfCurve) {
91
        basisOfCurve_ = basisOfCurve;
×
92
        basisOfCurveUomConversionFactor_ =
×
93
            CommodityPricingHelper::calculateUomConversionFactor(
×
94
                                                commodityType_,
×
95
                                                basisOfCurve_->unitOfMeasure_,
×
96
                                                unitOfMeasure_);
×
97
    }
×
98

99
    std::ostream& operator<<(std::ostream& out, const CommodityCurve& curve) {
×
100
        out << "[" << curve.name_ << "] (" << curve.currency_.code()
×
101
            << "/" << curve.unitOfMeasure_.code() << ")";
×
102
        if (curve.basisOfCurve_ != nullptr)
×
103
            out << "; basis to (" << (*curve.basisOfCurve_) << ")";
×
104
        return out;
×
105
    }
106

107
}
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