Table of Contents

Class ExchangeRates

Namespace
NanoQL.Currencies
Assembly
NanoQL.dll

The exchange-rate registry: QuantLib's ExchangeRateManager, as an immutable value that ExchangeRates holds.

public sealed class ExchangeRates : IEquatable<ExchangeRates>
Inheritance
ExchangeRates
Implements
Inherited Members

Remarks

Every change returns a new registry, as .NET's immutable collections do. Default holds QuantLib's known rates, the euro's legacy currencies and the redenominated Turkish, Romanian and Peruvian currencies, which QuantLib's manager holds at start and after clear(). Add(ExchangeRate, Date?, Date?) puts a rate first among its pair's entries, so the latest added takes precedence where date ranges overlap; Lookup(Currency?, Currency?, EvaluationContext, Date?, ExchangeRateType) finds a direct, triangulated or chained rate in QuantLib's order.

QuantLib keys its rates by the pair's numeric codes, min × 1000 + max (exchangeratemanager.cpp:89-98), which loses every rate of a currency coded 1,000 or more (QuantLib's crypto currencies, 10000 to 10007, or any currency of one's own: a lookup from it throws, and no chain passes through it), and can't tell apart two currencies sharing a code (CNY and CNH, 156: a USD/CNH rate answers for USD/CNY). Here the key is the pair of currencies, ordered as QuantLib's key orders pairs, the codes and names breaking a tie; a chained lookup tests which pairs involve a currency and which currencies it has passed by the same identity, where QuantLib uses the numeric code (:95-98, :159, :170), and chains as QuantLib's chain does. So QuantLib's order and answers stand wherever the numeric codes are distinct and below 1,000 and the currencies' names distinct, BGL and BGN apart: three documented divergences (Divergences/ExchangeRateKeyTests.cs, Divergences/SharedNumericCodeTests.cs, Divergences/CurrencyNameAndCodeTests.cs).

Two registries are equal when they hold the same pairs, each with equal entries (rate, start and end dates) in the same order. The hash combines one hash per pair, computed when the registry is built.

Properties

Default

Gets the registry holding QuantLib's known rates alone, its state at start and after clear().

public static ExchangeRates Default { get; }

Property Value

ExchangeRates

Methods

Add(ExchangeRate, Date?, Date?)

A registry with one more exchange rate, valid between two dates.

public ExchangeRates Add(ExchangeRate rate, Date? startDate = null, Date? endDate = null)

Parameters

rate ExchangeRate

The rate.

startDate Date?

The first date it is valid on; null for the earliest date, QuantLib's Date::minDate().

endDate Date?

The last date it is valid on; null for the latest date, QuantLib's Date::maxDate().

Returns

ExchangeRates

The new registry, the rate first among its pair's; this one is unchanged.

Exceptions

ArgumentNullException

rate is null.

ArgumentException

A date is default(Date).

NanoQLException

A currency of the rate is QuantLib's empty one.

Clear()

The registry without the added rates: Default, QuantLib's known rates alone.

public ExchangeRates Clear()

Returns

ExchangeRates

Default; this registry is unchanged.

Equals(ExchangeRates?)

public bool Equals(ExchangeRates? other)

Parameters

other ExchangeRates

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

GetHashCode()

public override int GetHashCode()

Returns

int

Lookup(Currency?, Currency?, EvaluationContext, Date?, ExchangeRateType)

The exchange rate between two currencies at a date. Direct rates are preferred; with Derived, a rate is triangulated through a currency's triangulation currency, or chained through other currencies, where no direct one is held.

public ExchangeRate Lookup(Currency? source, Currency? target, EvaluationContext context, Date? date = null, ExchangeRateType type = ExchangeRateType.Derived)

Parameters

source Currency

The source currency.

target Currency

The target currency.

context EvaluationContext

The evaluation context, whose evaluation date is the date when none is given.

date Date?

The date; null for the context's evaluation date.

type ExchangeRateType

Whether only a direct rate is returned, or derived ones too.

Returns

ExchangeRate

The rate; 1.0 between a currency and itself.

Remarks

Where two or more chains are possible, which one is returned is QuantLib's choice: the first by the pairs' order.

Exceptions

ArgumentNullException

context is null.

ArgumentOutOfRangeException

type isn't a member of its enum.

ArgumentException

date is default(Date).

NanoQLException

No rate is held for the date ("no direct conversion available", "no conversion available"), or a currency is QuantLib's empty one.