Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
commoditycashflow.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file qle/cashflows/commoditycashflow.hpp
20 \brief Some data and logic shared among commodity cashflows
21 */
22
23#ifndef quantext_commodity_cash_flow_hpp
24#define quantext_commodity_cash_flow_hpp
25
26#include <ql/cashflow.hpp>
27#include <ql/patterns/visitor.hpp>
28#include <ql/patterns/lazyobject.hpp>
29#include <ql/time/calendar.hpp>
30#include <ql/time/date.hpp>
33
34#include <set>
35
36namespace QuantExt {
37
38/*! \brief Enumeration indicating the frequency associated with a commodity quantity. */
43 PerHour,
45};
46
47/*! \brief Get the set of valid pricing dates in a period.
48
49 \param start The start date of the period.
50 \param end The end date of the period.
51 \param pricingCalendar The pricing calendar used to determine valid dates
52 \param excludeStart Set to \c true if the start date should be excluded from the set of pricing dates and to
53 \c false if the start date should be included.
54 \param includeEnd set to \c true if the end date should be included in the set of pricing dates and to
55 \c false if the end date should be excluded.
56 \param useBusinessDays Set to \c true if \p pricingCalendar business dates are to be considered valid pricing
57 dates and \p false if \p pricingCalendar holidays are to be considered valid pricing
58 dates. The latter case is unusual but is useful for some electricity futures e.g. ICE PW2
59 contract which averages over weekends and non-NERC business days.
60
61 \return The set of valid pricing dates in the period.
62*/
63std::set<QuantLib::Date> pricingDates(const QuantLib::Date& start, const QuantLib::Date& end,
64 const QuantLib::Calendar& pricingCalendar, bool excludeStart, bool includeEnd,
65 bool useBusinessDays = true);
66
67/*! \brief Check if a date is a pricing date.
68
69 \param d The date that we wish to check.
70 \param pricingCalendar The pricing calendar used to determine valid dates
71 \param useBusinessDays Set to \c true if \p pricingCalendar business dates are to be considered valid pricing
72 dates and \p false if \p pricingCalendar holidays are to be considered valid pricing
73 dates. The latter case is unusual but is useful for some electricity futures e.g. ICE PW2
74 contract which averages over weekends and non-NERC business days.
75
76 \return Returns \c true if \p d is a pricing date and \c false otherwise.
77*/
78bool isPricingDate(const QuantLib::Date& d, const QuantLib::Calendar& pricingCalendar, bool useBusinessDays = true);
79
80class CommodityCashFlow : public QuantLib::LazyObject, public QuantLib::CashFlow {
81public:
82 CommodityCashFlow(QuantLib::Real quantity, QuantLib::Real spread, QuantLib::Real gearing, bool useFuturePrice,
83 const ext::shared_ptr<CommodityIndex>& index, const ext::shared_ptr<FxIndex>& fxIndex);
84 QuantLib::Real quantity() const { return quantity_; }
85 QuantLib::Real spread() const { return spread_; }
86 QuantLib::Real gearing() const { return gearing_; }
87 bool useFuturePrice() const { return useFuturePrice_; }
88
89 ext::shared_ptr<CommodityIndex> index() const { return index_; };
90 ext::shared_ptr<FxIndex> fxIndex() const { return fxIndex_; }
91 //! Return a map of pricing date and corresponding commodity index
92 virtual const std::vector<std::pair<QuantLib::Date, ext::shared_ptr<CommodityIndex>>>& indices() const = 0;
93 virtual QuantLib::Date lastPricingDate() const = 0;
94 virtual QuantLib::Real periodQuantity() const = 0;
95 // Return the price fixing
96 virtual QuantLib::Real fixing() const = 0;
97
98 //! \name Visitability
99 //@{
100 void accept(QuantLib::AcyclicVisitor& v) override;
101 //@}
102
103protected:
104 QuantLib::Real quantity_;
105 QuantLib::Real spread_;
106 QuantLib::Real gearing_;
108 ext::shared_ptr<CommodityIndex> index_;
109 ext::shared_ptr<FxIndex> fxIndex_;
110 mutable QuantLib::Real amount_;
111};
112} // namespace QuantExt
113
114#endif
virtual const std::vector< std::pair< QuantLib::Date, ext::shared_ptr< CommodityIndex > > > & indices() const =0
Return a map of pricing date and corresponding commodity index.
QuantLib::Real spread() const
void accept(QuantLib::AcyclicVisitor &v) override
ext::shared_ptr< FxIndex > fxIndex() const
virtual QuantLib::Real periodQuantity() const =0
ext::shared_ptr< FxIndex > fxIndex_
QuantLib::Real gearing() const
virtual QuantLib::Date lastPricingDate() const =0
ext::shared_ptr< CommodityIndex > index_
ext::shared_ptr< CommodityIndex > index() const
QuantLib::Real quantity() const
virtual QuantLib::Real fixing() const =0
commodity index class for holding commodity spot and futures price histories and forwarding.
FX index class.
CommodityQuantityFrequency
Enumeration indicating the frequency associated with a commodity quantity.
bool isPricingDate(const Date &d, const Calendar &pricingCalendar, bool useBusinessDays)
set< Date > pricingDates(const Date &s, const Date &e, const Calendar &pricingCalendar, bool excludeStart, bool includeEnd, bool useBusinessDays)