QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
commodity.cpp
Go to the documentation of this file.
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
21#include <iomanip>
22#include <utility>
23
24namespace QuantLib {
25
26 Commodity::Commodity(ext::shared_ptr<SecondaryCosts> secondaryCosts)
27 : secondaryCosts_(std::move(secondaryCosts)) {}
28
31 }
32
34 return pricingErrors_;
35 }
36
38 const std::string& error,
39 const std::string& detail) const {
40 pricingErrors_.emplace_back(errorLevel, error, detail);
41 }
42
43
44 std::ostream& operator<<(std::ostream& out,
45 const SecondaryCostAmounts& secondaryCostAmounts) {
46 std::string currencyCode;
47 Real totalAmount = 0;
48
49 out << "secondary costs" << std::endl;
50 for (const auto& secondaryCostAmount : secondaryCostAmounts) {
51 Real amount = secondaryCostAmount.second.value();
52 if (currencyCode.empty())
53 currencyCode = secondaryCostAmount.second.currency().code();
54 totalAmount += amount;
55 out << std::setw(28) << std::left << secondaryCostAmount.first << std::setw(12)
56 << std::right << std::fixed << std::setprecision(2) << amount << " " << currencyCode
57 << std::endl;
58 }
59 out << std::setw(28) << std::left << "total"
60 << std::setw(12) << std::right << std::fixed
61 << std::setprecision(2) << totalAmount << " " << currencyCode
62 << std::endl;
63 return out;
64 }
65
66
67 std::ostream& operator<<(std::ostream& out, const PricingError& error) {
68 switch (error.errorLevel) {
70 out << "info: ";
71 break;
73 out << "warning: ";
74 break;
76 out << "*** error: ";
77 break;
79 out << "*** fatal: ";
80 break;
81 }
82 out << error.error;
83 if (!error.detail.empty())
84 out << ": " << error.detail;
85 return out;
86 }
87
88 std::ostream& operator<<(std::ostream& out, const PricingErrors& errors) {
89 if (!errors.empty()) {
90 out << "*** pricing errors" << std::endl;
91 for (const auto& error : errors)
92 out << error << std::endl;
93 }
94 return out;
95 }
96
97}
98
const PricingErrors & pricingErrors() const
Definition: commodity.cpp:33
const SecondaryCostAmounts & secondaryCostAmounts() const
Definition: commodity.cpp:29
Commodity(ext::shared_ptr< SecondaryCosts > secondaryCosts)
Definition: commodity.cpp:26
void addPricingError(PricingError::Level errorLevel, const std::string &error, const std::string &detail="") const
Definition: commodity.cpp:37
SecondaryCostAmounts secondaryCostAmounts_
Definition: commodity.hpp:75
PricingErrors pricingErrors_
Definition: commodity.hpp:74
Commodity base class.
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
std::vector< PricingError > PricingErrors
Definition: commodity.hpp:55
std::ostream & operator<<(std::ostream &out, GFunctionFactory::YieldCurveModel type)
std::map< std::string, Money > SecondaryCostAmounts
Definition: commodity.hpp:37
STL namespace.