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 
23 namespace QuantLib {
24 
EnergySwap(const Calendar & calendar,const Currency & payCurrency,const Currency & receiveCurrency,const PricingPeriods & pricingPeriods,const CommodityType & commodityType,const ext::shared_ptr<SecondaryCosts> & secondaryCosts)25     EnergySwap::EnergySwap(
26                       const Calendar& calendar,
27                       const Currency& payCurrency,
28                       const Currency& receiveCurrency,
29                       const PricingPeriods& pricingPeriods,
30                       const CommodityType& commodityType,
31                       const ext::shared_ptr<SecondaryCosts>& secondaryCosts)
32     : EnergyCommodity(commodityType, secondaryCosts),
33       calendar_(calendar), payCurrency_(payCurrency),
34       receiveCurrency_(receiveCurrency), pricingPeriods_(pricingPeriods) {}
35 
commodityType() const36     const CommodityType& EnergySwap::commodityType() const {
37         QL_REQUIRE(!pricingPeriods_.empty(), "no pricing periods");
38         return pricingPeriods_[0]->quantity().commodityType();
39     }
40 
quantity() const41     Quantity EnergySwap::quantity() const {
42         Real totalQuantityAmount = 0;
43         for (PricingPeriods::const_iterator pi = pricingPeriods_.begin();
44              pi != pricingPeriods_.end(); ++pi) {
45             totalQuantityAmount += (*pi)->quantity().amount();
46         }
47         return Quantity(pricingPeriods_[0]->quantity().commodityType(),
48                         pricingPeriods_[0]->quantity().unitOfMeasure(),
49                         totalQuantityAmount);
50     }
51 
isExpired() const52     bool EnergySwap::isExpired() const {
53         return pricingPeriods_.empty()
54             || detail::simple_event(pricingPeriods_.back()->paymentDate())
55                .hasOccurred();
56     }
57 
58 }
59 
60