Coverage Report

Created: 2026-03-11 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/experimental/commodities/commodityindex.cpp
Line
Count
Source
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
 <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/experimental/commodities/commodityindex.hpp>
21
#include <ql/experimental/commodities/commoditypricinghelpers.hpp>
22
#include <utility>
23
24
namespace QuantLib {
25
26
    CommodityIndex::CommodityIndex(std::string  indexName,
27
                                   CommodityType commodityType,
28
                                   Currency currency,
29
                                   UnitOfMeasure unitOfMeasure,
30
                                   Calendar calendar,
31
                                   Real lotQuantity,
32
                                   ext::shared_ptr<CommodityCurve> forwardCurve,
33
                                   ext::shared_ptr<ExchangeContracts> exchangeContracts,
34
                                   int nearbyOffset)
35
0
    : name_(std::move(indexName)), commodityType_(std::move(commodityType)),
36
0
      unitOfMeasure_(std::move(unitOfMeasure)), currency_(std::move(currency)),
37
0
      calendar_(std::move(calendar)), lotQuantity_(lotQuantity),
38
0
      forwardCurve_(std::move(forwardCurve)), exchangeContracts_(std::move(exchangeContracts)),
39
0
      nearbyOffset_(nearbyOffset) {
40
0
        registerWith(Settings::instance().evaluationDate());
41
0
        registerWith(notifier());
42
43
0
        if (forwardCurve_ != nullptr)
44
            // registerWith(forwardCurve_);
45
0
            forwardCurveUomConversionFactor_ =
46
0
                CommodityPricingHelper::calculateUomConversionFactor(
47
0
                                                commodityType_,
48
0
                                                forwardCurve_->unitOfMeasure_,
49
0
                                                unitOfMeasure_);
50
0
    }
51
52
0
    std::ostream& operator<<(std::ostream& out, const CommodityIndex& index) {
53
0
        out << "[" << index.name_ << "] ("
54
0
            << index.currency_.code() << "/"
55
0
            << index.unitOfMeasure_.code() << ")";
56
0
        if (index.forwardCurve_ != nullptr)
57
0
            out << "; forward (" << (*index.forwardCurve_) << ")";
58
0
        return out;
59
0
    }
60
61
}