Coverage Report

Created: 2025-12-08 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/experimental/commodities/energyswap.cpp
Line
Count
Source
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
 <https://www.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
24
namespace 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
0
    : EnergyCommodity(commodityType, secondaryCosts), calendar_(std::move(calendar)),
33
0
      payCurrency_(std::move(payCurrency)), receiveCurrency_(std::move(receiveCurrency)),
34
0
      pricingPeriods_(std::move(pricingPeriods)) {}
Unexecuted instantiation: QuantLib::EnergySwap::EnergySwap(QuantLib::Calendar, QuantLib::Currency, QuantLib::Currency, std::__1::vector<boost::shared_ptr<QuantLib::PricingPeriod>, std::__1::allocator<boost::shared_ptr<QuantLib::PricingPeriod> > >, QuantLib::CommodityType const&, boost::shared_ptr<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::any, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::any> > > > const&)
Unexecuted instantiation: QuantLib::EnergySwap::EnergySwap(QuantLib::Calendar, QuantLib::Currency, QuantLib::Currency, std::__1::vector<boost::shared_ptr<QuantLib::PricingPeriod>, std::__1::allocator<boost::shared_ptr<QuantLib::PricingPeriod> > >, QuantLib::CommodityType const&, boost::shared_ptr<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::any, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::any> > > > const&)
35
36
0
    const CommodityType& EnergySwap::commodityType() const {
37
0
        QL_REQUIRE(!pricingPeriods_.empty(), "no pricing periods");
38
0
        return pricingPeriods_[0]->quantity().commodityType();
39
0
    }
40
41
0
    Quantity EnergySwap::quantity() const {
42
0
        Real totalQuantityAmount = 0;
43
0
        for (const auto& pricingPeriod : pricingPeriods_) {
44
0
            totalQuantityAmount += pricingPeriod->quantity().amount();
45
0
        }
46
0
        return Quantity(pricingPeriods_[0]->quantity().commodityType(),
47
0
                        pricingPeriods_[0]->quantity().unitOfMeasure(),
48
0
                        totalQuantityAmount);
49
0
    }
50
51
0
    bool EnergySwap::isExpired() const {
52
0
        return pricingPeriods_.empty()
53
0
            || detail::simple_event(pricingPeriods_.back()->paymentDate())
54
0
               .hasOccurred();
55
0
    }
56
57
}
58