QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
energyswap.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 <ql/settings.hpp>
22#include <utility>
23
24namespace QuantLib {
25
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
37 QL_REQUIRE(!pricingPeriods_.empty(), "no pricing periods");
38 return pricingPeriods_[0]->quantity().commodityType();
39 }
40
42 Real totalQuantityAmount = 0;
43 for (const auto& pricingPeriod : pricingPeriods_) {
44 totalQuantityAmount += pricingPeriod->quantity().amount();
45 }
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
calendar class
Definition: calendar.hpp:61
Currency specification
Definition: currency.hpp:36
Energy commodity class.
PricingPeriods pricingPeriods_
Definition: energyswap.hpp:62
EnergySwap(Calendar calendar, Currency payCurrency, Currency receiveCurrency, PricingPeriods pricingPeriods, const CommodityType &commodityType, const ext::shared_ptr< SecondaryCosts > &secondaryCosts)
Definition: energyswap.cpp:26
bool isExpired() const override
returns whether the instrument might have value greater than zero.
Definition: energyswap.cpp:51
Quantity quantity() const override
Definition: energyswap.cpp:41
const CommodityType & commodityType() const
Definition: energyswap.cpp:36
virtual bool hasOccurred(const Date &refDate=Date(), ext::optional< bool > includeRefDate=ext::nullopt) const
returns true if an event has already occurred before a date
Definition: event.cpp:28
Amount of a commodity.
Definition: quantity.hpp:34
Real amount() const
Definition: quantity.hpp:136
Energy swap.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
std::vector< ext::shared_ptr< PricingPeriod > > PricingPeriods
STL namespace.
global repository for run-time library settings