24#ifndef quantlib_commodity_curve_hpp
25#define quantlib_commodity_curve_hpp
27#include <ql/termstructure.hpp>
28#include <ql/experimental/commodities/commoditytype.hpp>
29#include <ql/experimental/commodities/unitofmeasure.hpp>
30#include <ql/experimental/commodities/exchangecontract.hpp>
31#include <ql/currency.hpp>
32#include <ql/math/interpolations/forwardflatinterpolation.hpp>
33#include <ql/time/daycounters/actual365fixed.hpp>
47 const std::vector<Date>&
dates,
60 const std::string&
name()
const;
65 const std::vector<Time>&
times()
const;
66 const std::vector<Date>&
dates()
const;
67 const std::vector<Real>&
prices()
const;
68 std::vector<std::pair<Date,Real> >
nodes()
const;
77 const ext::shared_ptr<ExchangeContracts>& exchangeContracts,
82 const ext::shared_ptr<ExchangeContracts>& exchangeContracts,
85 const ext::shared_ptr<CommodityCurve>&
basisOfCurve()
const;
87 friend std::ostream&
operator<<(std::ostream& out,
98 mutable std::vector<Real>
data_;
138 inline const ext::shared_ptr<CommodityCurve>&
158 const ext::shared_ptr<ExchangeContracts>& exchangeContracts,
160 Date date = nearbyOffset > 0 ?
166 }
catch (
const std::exception& e) {
167 QL_FAIL(
"error retrieving price for curve [" <<
name() <<
"]: "
177 const ext::shared_ptr<ExchangeContracts>& exchangeContracts,
179 QL_REQUIRE(nearbyOffset > 0,
"nearby offset must be > 0");
180 ExchangeContracts::const_iterator ic =
181 exchangeContracts->lower_bound(date);
182 if (ic != exchangeContracts->end()) {
183 for (
int i = 0; i < nearbyOffset-1 && ic!=exchangeContracts->end(); ++i)
185 QL_REQUIRE(ic != exchangeContracts->end(),
186 "not enough nearby contracts available for curve ["
187 <<
name() <<
"] for date [" << date <<
"].");
188 return ic->second.underlyingStartDate();
195 Real basisCurvePriceValue = 0;
197 basisCurvePriceValue =
200 }
catch (
const std::exception& e) {
201 QL_FAIL(
"error retrieving price for curve [" <<
name() <<
204 return basisCurvePriceValue +
basisOfCurve_->basisOfPriceImpl(t);
Actual/365 (Fixed) day count convention.
Commodity term structure.
Real basisOfPrice(const Date &d) const
const ext::shared_ptr< CommodityCurve > & basisOfCurve() const
void setBasisOfCurve(const ext::shared_ptr< CommodityCurve > &basisOfCurve)
UnitOfMeasure unitOfMeasure_
Real basisOfCurveUomConversionFactor_
const std::string & name() const
const std::vector< Real > & prices() const
std::vector< Date > dates_
friend std::ostream & operator<<(std::ostream &out, const CommodityCurve &curve)
Date underlyingPriceDate(const Date &date, const ext::shared_ptr< ExchangeContracts > &exchangeContracts, Integer nearbyOffset) const
const std::vector< Date > & dates() const
const Currency & currency() const
std::vector< Time > times_
Interpolation interpolation_
CommodityType commodityType_
ForwardFlat interpolator_
std::vector< std::pair< Date, Real > > nodes() const
const std::vector< Time > & times() const
Real priceImpl(Time t) const
Date maxDate() const override
the latest date for which the curve can return values
void setPrices(std::map< Date, Real > &prices)
Real price(const Date &d, const ext::shared_ptr< ExchangeContracts > &exchangeContracts, Integer nearbyOffset) const
const CommodityType & commodityType() const
Real basisOfPriceImpl(Time t) const
std::vector< Real > data_
const UnitOfMeasure & unitOfMeasure() const
ext::shared_ptr< CommodityCurve > basisOfCurve_
base class for commodity indexes
Forward-flat interpolation factory and traits.
base class for 1-D interpolations.
Basic term-structure functionality.
virtual Calendar calendar() const
the calendar used for reference and/or option date calculation
Time timeFromReference(const Date &date) const
date/time conversion
virtual DayCounter dayCounter() const
the day counter used for date/time conversion
Unit of measure specification
Real Time
continuous quantity with 1-year units
QL_INTEGER Integer
integer number
std::size_t Size
size of a container
bool operator==(const Currency &c1, const Currency &c2)