QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
commoditypricinghelpers.hpp
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
24#ifndef quantlib_commodity_pricing_helpers_hpp
25#define quantlib_commodity_pricing_helpers_hpp
26
27#include <ql/experimental/commodities/energycommodity.hpp>
28#include <ql/experimental/commodities/paymentterm.hpp>
29#include <ql/experimental/commodities/pricingperiod.hpp>
30#include <ql/experimental/commodities/unitofmeasureconversionmanager.hpp>
31#include <ql/currencies/exchangeratemanager.hpp>
32
33namespace QuantLib {
34
37 public:
39
40 static Real calculateFxConversionFactor(const Currency& fromCurrency,
41 const Currency& toCurrency,
42 const Date& evaluationDate);
43
45 const CommodityType& commodityType,
46 const UnitOfMeasure& fromUnitOfMeasure,
47 const UnitOfMeasure& toUnitOfMeasure);
48
49 static Real calculateUnitCost(const CommodityType& commodityType,
50 const CommodityUnitCost& unitCost,
51 const Currency& baseCurrency,
52 const UnitOfMeasure& baseUnitOfMeasure,
53 const Date& evaluationDate);
54
55 static void createPricingPeriods(
56 Date startDate, Date endDate,
57 const Quantity& quantity,
58 EnergyCommodity::DeliverySchedule deliverySchedule,
60 const PaymentTerm& paymentTerm,
61 PricingPeriods& pricingPeriods);
62 };
63
64
66 const CommodityType& commodityType,
67 const UnitOfMeasure& fromUnitOfMeasure,
68 const UnitOfMeasure& toUnitOfMeasure) {
69 if (toUnitOfMeasure != fromUnitOfMeasure) {
72 commodityType, fromUnitOfMeasure, toUnitOfMeasure);
73 return uomConv.conversionFactor();
74 }
75
76 return 1;
77 }
78
80 const Currency& fromCurrency,
81 const Currency& toCurrency,
82 const Date& evaluationDate) {
83 if (fromCurrency != toCurrency) {
84 ExchangeRate exchRate =
86 toCurrency,
87 evaluationDate,
89 if (fromCurrency != exchRate.source())
90 return (Real)1 / exchRate.rate();
91 return exchRate.rate();
92 }
93 return 1;
94 }
95
97 const CommodityType& commodityType,
98 const CommodityUnitCost& unitCost,
99 const Currency& baseCurrency,
100 const UnitOfMeasure& baseUnitOfMeasure,
101 const Date& evaluationDate) {
102 if (unitCost.amount().value() != 0) {
103 Real unitCostUomConversionFactor =
104 calculateUomConversionFactor(commodityType,
105 unitCost.unitOfMeasure(),
106 baseUnitOfMeasure);
107 Real unitCostFxConversionFactor =
109 baseCurrency, evaluationDate);
110 return unitCost.amount().value() * unitCostUomConversionFactor
111 * unitCostFxConversionFactor;
112 }
113 return 0;
114 }
115
116}
117
118#endif
static Real calculateUomConversionFactor(const CommodityType &commodityType, const UnitOfMeasure &fromUnitOfMeasure, const UnitOfMeasure &toUnitOfMeasure)
static void createPricingPeriods(Date startDate, Date endDate, const Quantity &quantity, EnergyCommodity::DeliverySchedule deliverySchedule, EnergyCommodity::QuantityPeriodicity qtyPeriodicity, const PaymentTerm &paymentTerm, PricingPeriods &pricingPeriods)
static Real calculateUnitCost(const CommodityType &commodityType, const CommodityUnitCost &unitCost, const Currency &baseCurrency, const UnitOfMeasure &baseUnitOfMeasure, const Date &evaluationDate)
static Real calculateFxConversionFactor(const Currency &fromCurrency, const Currency &toCurrency, const Date &evaluationDate)
const Money & amount() const
const UnitOfMeasure & unitOfMeasure() const
Currency specification
Definition: currency.hpp:36
Concrete date class.
Definition: date.hpp:125
exchange rate between two currencies
Decimal rate() const
the exchange rate (when available)
const Currency & source() const
the source currency.
ExchangeRate lookup(const Currency &source, const Currency &target, Date date=Date(), ExchangeRate::Type type=ExchangeRate::Derived) const
const Currency & currency() const
Definition: money.hpp:173
Decimal value() const
Definition: money.hpp:177
Amount of a commodity.
Definition: quantity.hpp:34
static UnitOfMeasureConversionManager & instance()
access to the unique instance
Definition: singleton.hpp:104
Real conversionFactor() const
the conversion factor
UnitOfMeasureConversion lookup(const CommodityType &commodityType, const UnitOfMeasure &, const UnitOfMeasure &, UnitOfMeasureConversion::Type type=UnitOfMeasureConversion::Derived) const
Unit of measure specification
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
std::vector< ext::shared_ptr< PricingPeriod > > PricingPeriods