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/energyswap.hpp>
21#include <ql/settings.hpp>
22#include <utility>
23
24namespace QuantLib {
25
26 EnergySwap::EnergySwap(Calendar calendar,
27 Currency payCurrency,
28 Currency receiveCurrency,
29 PricingPeriods pricingPeriods,
30 const CommodityType& commodityType,
31 const ext::shared_ptr<SecondaryCosts>& secondaryCosts)
32 : EnergyCommodity(commodityType, secondaryCosts), calendar_(std::move(calendar)),
33 payCurrency_(std::move(payCurrency)), receiveCurrency_(std::move(receiveCurrency)),
34 pricingPeriods_(std::move(pricingPeriods)) {}
35
36 const CommodityType& EnergySwap::commodityType() const {
37 QL_REQUIRE(!pricingPeriods_.empty(), "no pricing periods");
38 return pricingPeriods_[0]->quantity().commodityType();
39 }
40
41 Quantity EnergySwap::quantity() const {
42 Real totalQuantityAmount = 0;
43 for (const auto& pricingPeriod : pricingPeriods_) {
44 totalQuantityAmount += pricingPeriod->quantity().amount();
45 }
46 return Quantity(pricingPeriods_[0]->quantity().commodityType(),
47 pricingPeriods_[0]->quantity().unitOfMeasure(),
48 totalQuantityAmount);
49 }
50
51 bool EnergySwap::isExpired() const {
52 return pricingPeriods_.empty()
53 || detail::simple_event(pricingPeriods_.back()->paymentDate())
54 .hasOccurred();
55 }
56
57}
58
59

source code of quantlib/ql/experimental/commodities/energyswap.cpp