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 energycommodity.hpp
21 \brief Energy commodity
22*/
23
24#ifndef quantlib_energy_commodity_hpp
25#define quantlib_energy_commodity_hpp
26
27#include <ql/experimental/commodities/commodity.hpp>
28#include <ql/experimental/commodities/commoditytype.hpp>
29#include <ql/experimental/commodities/commodityunitcost.hpp>
30#include <ql/experimental/commodities/unitofmeasure.hpp>
31#include <ql/experimental/commodities/quantity.hpp>
32#include <ql/time/date.hpp>
33#include <ql/money.hpp>
34
35namespace QuantLib {
36
37 struct EnergyDailyPosition {
38 Date date;
39 Real quantityAmount;
40 Real payLegPrice = 0;
41 Real receiveLegPrice = 0;
42 Real riskDelta;
43 bool unrealized = false;
44
45 EnergyDailyPosition() = default;
46 EnergyDailyPosition(const Date& date,
47 Real payLegPrice,
48 Real receiveLegPrice,
49 bool unrealized);
50 };
51
52 typedef std::map<Date, EnergyDailyPosition> EnergyDailyPositions;
53
54 #ifndef __DOXYGEN__
55 std::ostream& operator<<(std::ostream& out,
56 const EnergyDailyPositions& dailyPositions);
57 #endif
58
59
60
61 //! Energy commodity class
62 /*! \ingroup instruments */
63 class EnergyCommodity : public Commodity {
64 public:
65 class arguments;
66 class results;
67 class engine;
68
69 enum DeliverySchedule { Constant,
70 Window,
71 Hourly,
72 Daily,
73 Weekly,
74 Monthly,
75 Quarterly,
76 Yearly };
77 enum QuantityPeriodicity { Absolute,
78 PerHour,
79 PerDay,
80 PerWeek,
81 PerMonth,
82 PerQuarter,
83 PerYear };
84 enum PaymentSchedule { WindowSettlement,
85 MonthlySettlement,
86 QuarterlySettlement,
87 YearlySettlement };
88
89 EnergyCommodity(CommodityType commodityType,
90 const ext::shared_ptr<SecondaryCosts>& secondaryCosts);
91
92 virtual Quantity quantity() const = 0;
93 const CommodityType& commodityType() const;
94
95 void setupArguments(PricingEngine::arguments*) const override;
96 void fetchResults(const PricingEngine::results*) const override;
97
98 protected:
99 static Real calculateFxConversionFactor(const Currency& fromCurrency,
100 const Currency& toCurrency,
101 const Date& evaluationDate);
102 static Real calculateUomConversionFactor(
103 const CommodityType& commodityType,
104 const UnitOfMeasure& fromUnitOfMeasure,
105 const UnitOfMeasure& toUnitOfMeasure);
106 Real calculateUnitCost(const CommodityType& commodityType,
107 const CommodityUnitCost& unitCost,
108 const Date& evaluationDate) const;
109 void calculateSecondaryCostAmounts(const CommodityType& commodityType,
110 Real totalQuantityValue,
111 const Date& evaluationDate) const;
112
113 CommodityType commodityType_;
114 };
115
116
117 class EnergyCommodity::arguments : public virtual PricingEngine::arguments {
118 public:
119 Currency currency;
120 UnitOfMeasure unitOfMeasure;
121 void validate() const override {}
122 };
123
124 class EnergyCommodity::results : public Instrument::results {
125 public:
126 Real NPV;
127 Currency currency;
128 UnitOfMeasure unitOfMeasure;
129 void reset() override { Instrument::results::reset(); }
130 };
131
132 class EnergyCommodity::engine
133 : public GenericEngine<EnergyCommodity::arguments,
134 EnergyCommodity::results> {};
135
136}
137
138#endif
139

source code of quantlib/ql/experimental/commodities/energycommodity.hpp