33 explicit valid_at(
const Date& d) :
d(
d) {}
34 bool operator()(
const ExchangeRateManager::Entry& e)
const {
35 return d >= e.startDate &&
d <= e.endDate;
46 const Date& startDate,
47 const Date& endDate) {
48 Key k =
hash(rate.source(), rate.target());
49 data_[k].emplace_front(rate,startDate,endDate);
139 const Date& date)
const {
143 QL_FAIL(
"no direct conversion available from "
144 << source.
code() <<
" to " << target.
code()
152 std::list<Integer> forbidden)
const {
160 std::map<Key, std::list<Entry> >::const_iterator i;
161 for (i =
data_.begin(); i !=
data_.end(); ++i) {
164 if (
hashes(i->first, source) && !(i->second.empty())) {
166 const Entry& e = i->second.front();
170 if (std::find(forbidden.begin(),forbidden.end(),
189 QL_FAIL(
"no conversion available from "
190 << source.
code() <<
" to " << target.
code()
196 const Date& date)
const {
197 const std::list<Entry>& rates =
data_[
hash(source,target)];
198 auto i = std::find_if(rates.begin(), rates.end(), valid_at(date));
199 return i == rates.end() ? (
const ExchangeRate*)
nullptr : &(i->rate);
const std::string & code() const
ISO 4217 three-letter code, e.g, "USD".
bool empty() const
is this a usable instance?
Integer numericCode() const
ISO 4217 numeric code, e.g, "840".
const Currency & triangulationCurrency() const
currency used for triangulated exchange when required
static Date maxDate()
latest allowed date
exchange rate between two currencies
const Currency & target() const
the target currency.
static ExchangeRate chain(const ExchangeRate &r1, const ExchangeRate &r2)
chain two exchange rates
const Currency & source() const
the source currency.
void add(const ExchangeRate &, const Date &startDate=Date::minDate(), const Date &endDate=Date::maxDate())
Add an exchange rate.
ExchangeRate lookup(const Currency &source, const Currency &target, Date date=Date(), ExchangeRate::Type type=ExchangeRate::Derived) const
ExchangeRate smartLookup(const Currency &source, const Currency &target, const Date &date, std::list< Integer > forbiddenCodes=std::list< Integer >()) const
std::map< Key, std::list< Entry > > data_
ExchangeRate directLookup(const Currency &source, const Currency &target, const Date &date) const
bool hashes(Key, const Currency &) const
Key hash(const Currency &, const Currency &) const
void clear()
remove the added exchange rates
const ExchangeRate * fetch(const Currency &source, const Currency &target, const Date &date) const
DateProxy & evaluationDate()
the date at which pricing is to be performed.
static Settings & instance()
access to the unique instance
#define QL_FAIL(message)
throw an error (possibly with file and line information)
global repository for run-time library settings