Coverage Report

Created: 2026-09-28 06:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/experimental/commodities/commoditypricinghelpers.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/commoditypricinghelpers.hpp>
21
22
namespace QuantLib {
23
24
    void CommodityPricingHelper::createPricingPeriods(
25
                          Date startDate, Date endDate,
26
                          const Quantity& quantity,
27
                          EnergyCommodity::DeliverySchedule deliverySchedule,
28
                          EnergyCommodity::QuantityPeriodicity qtyPeriodicity,
29
                          const PaymentTerm& paymentTerm,
30
0
                          PricingPeriods& pricingPeriods) {
31
0
        if (deliverySchedule == EnergyCommodity::Monthly) {
32
0
            Quantity periodQuantity;
33
0
            if (qtyPeriodicity == EnergyCommodity::PerMonth) {
34
0
                periodQuantity = quantity;
35
0
            } else {
36
0
                QL_FAIL("Invalid period quantity/pricing period combination.");
37
0
            }
38
39
0
            for (Date periodStartDate=startDate; periodStartDate<endDate; ) {
40
0
                Date periodEndDate = (periodStartDate + (1 * Months)) - 1;
41
0
                Date paymentDate = paymentTerm.getPaymentDate(periodEndDate);
42
0
                pricingPeriods.push_back(ext::make_shared<PricingPeriod>(
43
0
                             periodStartDate, periodEndDate,
44
0
                                               paymentDate, periodQuantity));
45
0
                periodStartDate = periodEndDate + 1;
46
0
            }
47
0
        } else if (deliverySchedule == EnergyCommodity::Daily) {
48
0
            QL_REQUIRE(qtyPeriodicity == EnergyCommodity::PerDay,
49
0
                       "Invalid period quantity/pricing period combination.");
50
51
0
            for (Date periodStartDate=startDate; periodStartDate<endDate; ) {
52
0
                Date periodEndDate = (periodStartDate + (1 * Months)) - 1;
53
54
0
                Quantity periodQuantity =
55
0
                    quantity * (periodEndDate - periodStartDate);
56
0
                Date paymentDate = paymentTerm.getPaymentDate(periodEndDate);
57
0
                pricingPeriods.push_back(ext::make_shared<PricingPeriod>(
58
0
                             periodStartDate, periodEndDate,
59
0
                                               paymentDate, periodQuantity));
60
0
                periodStartDate = periodEndDate + 1;
61
0
            }
62
0
        }
63
0
    }
64
65
}