QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
commodityindex.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
22#include <utility>
23
24namespace QuantLib {
25
26 CommodityIndex::CommodityIndex(const std::string& indexName,
27 CommodityType commodityType,
28 Currency currency,
29 UnitOfMeasure unitOfMeasure,
30 Calendar calendar,
31 Real lotQuantity,
32 ext::shared_ptr<CommodityCurve> forwardCurve,
33 ext::shared_ptr<ExchangeContracts> exchangeContracts,
34 int nearbyOffset)
35 : name_(indexName), commodityType_(std::move(commodityType)),
36 unitOfMeasure_(std::move(unitOfMeasure)), currency_(std::move(currency)),
37 calendar_(std::move(calendar)), lotQuantity_(lotQuantity),
38 forwardCurve_(std::move(forwardCurve)), exchangeContracts_(std::move(exchangeContracts)),
39 nearbyOffset_(nearbyOffset) {
42 registerWith(Settings::instance().evaluationDate());
44
45 if (forwardCurve_ != nullptr)
46 // registerWith(forwardCurve_);
50 forwardCurve_->unitOfMeasure_,
52 }
53
54 std::ostream& operator<<(std::ostream& out, const CommodityIndex& index) {
55 out << "[" << index.name_ << "] ("
56 << index.currency_.code() << "/"
57 << index.unitOfMeasure_.code() << ")";
58 if (index.forwardCurve_ != nullptr)
59 out << "; forward (" << (*index.forwardCurve_) << ")";
60 return out;
61 }
62
63}
calendar class
Definition: calendar.hpp:61
base class for commodity indexes
std::string name() const
CommodityIndex(const std::string &name, CommodityType commodityType, Currency currency, UnitOfMeasure unitOfMeasure, Calendar calendar, Real lotQuantity, ext::shared_ptr< CommodityCurve > forwardCurve, ext::shared_ptr< ExchangeContracts > exchangeContracts, int nearbyOffset)
TimeSeries< Real > quotes_
ext::shared_ptr< CommodityCurve > forwardCurve_
static Real calculateUomConversionFactor(const CommodityType &commodityType, const UnitOfMeasure &fromUnitOfMeasure, const UnitOfMeasure &toUnitOfMeasure)
Currency specification
Definition: currency.hpp:36
const std::string & code() const
ISO 4217 three-letter code, e.g, "USD".
Definition: currency.hpp:178
const TimeSeries< Real > & getHistory(const std::string &name) const
returns the (possibly empty) history of the index fixings
void setHistory(const std::string &name, TimeSeries< Real > history)
stores the historical fixings of the index
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
static IndexManager & instance()
access to the unique instance
Definition: singleton.hpp:104
Unit of measure specification
const std::string & code() const
code, e.g, "BBL", "MT"
Commodity index.
Commodity pricing helpers.
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
std::ostream & operator<<(std::ostream &out, GFunctionFactory::YieldCurveModel type)
STL namespace.