24#ifndef quantlib_commodity_curve_hpp
25#define quantlib_commodity_curve_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_;
150 inline const ext::shared_ptr<CommodityCurve>&
170 const ext::shared_ptr<ExchangeContracts>& exchangeContracts,
172 Date date = nearbyOffset > 0 ?
178 }
catch (
const std::exception& e) {
179 QL_FAIL(
"error retrieving price for curve [" <<
name() <<
"]: "
189 const ext::shared_ptr<ExchangeContracts>& exchangeContracts,
191 QL_REQUIRE(nearbyOffset > 0,
"nearby offset must be > 0");
192 ExchangeContracts::const_iterator ic =
193 exchangeContracts->lower_bound(date);
194 if (ic != exchangeContracts->end()) {
195 for (
int i = 0; i < nearbyOffset-1 && ic!=exchangeContracts->end(); ++i)
198 "not enough nearby contracts available for curve ["
199 <<
name() <<
"] for date [" << date <<
"].");
200 return ic->second.underlyingStartDate();
207 Real basisCurvePriceValue = 0;
209 basisCurvePriceValue =
212 }
catch (
const std::exception& e) {
213 QL_FAIL(
"error retrieving price for curve [" <<
name() <<
Actual/365 (Fixed) day counter.
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
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
forward-flat interpolation between discrete points
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)
base class for term structures