Coverage Report

Created: 2025-08-28 06:30

/src/quantlib/ql/experimental/commodities/commodity.hpp
Line
Count
Source (jump to first uncovered line)
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
/*! \file commodity.hpp
21
    \brief Commodity base class
22
*/
23
24
#ifndef quantlib_commodity_hpp
25
#define quantlib_commodity_hpp
26
27
#include <ql/any.hpp>
28
#include <ql/instrument.hpp>
29
#include <ql/money.hpp>
30
#include <iosfwd>
31
#include <utility>
32
#include <vector>
33
34
namespace QuantLib {
35
36
    typedef std::map<std::string, ext::any> SecondaryCosts;
37
    typedef std::map<std::string, Money> SecondaryCostAmounts;
38
39
    std::ostream& operator<<(std::ostream& out,
40
                             const SecondaryCostAmounts& secondaryCostAmounts);
41
42
43
    struct PricingError {
44
        enum Level { Info, Warning, Error, Fatal };
45
46
        Level errorLevel;
47
        std::string tradeId;
48
        std::string error;
49
        std::string detail;
50
51
        PricingError(Level errorLevel, std::string error, std::string detail)
52
0
        : errorLevel(errorLevel), error(std::move(error)), detail(std::move(detail)) {}
53
    };
54
55
    typedef std::vector<PricingError> PricingErrors;
56
57
    std::ostream& operator<<(std::ostream& out, const PricingError& error);
58
    std::ostream& operator<<(std::ostream& out, const PricingErrors& errors);
59
60
61
    //! Commodity base class
62
    /*! \ingroup instruments */
63
    class Commodity : public Instrument {
64
      public:
65
        explicit Commodity(ext::shared_ptr<SecondaryCosts> secondaryCosts);
66
        const ext::shared_ptr<SecondaryCosts>& secondaryCosts() const;
67
        const SecondaryCostAmounts& secondaryCostAmounts() const;
68
        const PricingErrors& pricingErrors() const;
69
        void addPricingError(PricingError::Level errorLevel,
70
                             const std::string& error,
71
                             const std::string& detail = "") const;
72
      protected:
73
        ext::shared_ptr<SecondaryCosts> secondaryCosts_;
74
        mutable PricingErrors pricingErrors_;
75
        mutable SecondaryCostAmounts secondaryCostAmounts_;
76
    };
77
78
}
79
80
#endif