QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
commoditypricinghelpers.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
22namespace QuantLib {
23
25 Date startDate, Date endDate,
26 const Quantity& quantity,
27 EnergyCommodity::DeliverySchedule deliverySchedule,
29 const PaymentTerm& paymentTerm,
30 PricingPeriods& pricingPeriods) {
31 if (deliverySchedule == EnergyCommodity::Monthly) {
32 Quantity periodQuantity;
33 if (qtyPeriodicity == EnergyCommodity::PerMonth) {
34 periodQuantity = quantity;
35 } else {
36 QL_FAIL("Invalid period quantity/pricing period combination.");
37 }
38
39 for (Date periodStartDate=startDate; periodStartDate<endDate; ) {
40 Date periodEndDate = (periodStartDate + (1 * Months)) - 1;
41 Date paymentDate = paymentTerm.getPaymentDate(periodEndDate);
42 pricingPeriods.push_back(ext::make_shared<PricingPeriod>(
43 periodStartDate, periodEndDate,
44 paymentDate, periodQuantity));
45 periodStartDate = periodEndDate + 1;
46 }
47 } else if (deliverySchedule == EnergyCommodity::Daily) {
48 QL_REQUIRE(qtyPeriodicity == EnergyCommodity::PerDay,
49 "Invalid period quantity/pricing period combination.");
50
51 for (Date periodStartDate=startDate; periodStartDate<endDate; ) {
52 Date periodEndDate = (periodStartDate + (1 * Months)) - 1;
53
54 Quantity periodQuantity =
55 quantity * (periodEndDate - periodStartDate);
56 Date paymentDate = paymentTerm.getPaymentDate(periodEndDate);
57 pricingPeriods.push_back(ext::make_shared<PricingPeriod>(
58 periodStartDate, periodEndDate,
59 paymentDate, periodQuantity));
60 periodStartDate = periodEndDate + 1;
61 }
62 }
63 }
64
65}
static void createPricingPeriods(Date startDate, Date endDate, const Quantity &quantity, EnergyCommodity::DeliverySchedule deliverySchedule, EnergyCommodity::QuantityPeriodicity qtyPeriodicity, const PaymentTerm &paymentTerm, PricingPeriods &pricingPeriods)
Concrete date class.
Definition: date.hpp:125
Date getPaymentDate(const Date &date) const
Amount of a commodity.
Definition: quantity.hpp:34
Commodity pricing helpers.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Definition: errors.hpp:92
Definition: any.hpp:35
std::vector< ext::shared_ptr< PricingPeriod > > PricingPeriods