Table of Contents

Class ExchangeRate

Namespace
NanoQL
Assembly
NanoQL.dll

The exchange rate between two currencies, given directly or derived by chaining two others.

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

Remarks

Immutable. The rate r is given with the convention that a unit of the source is worth r units of the target. QuantLib's default constructor, an empty rate whose value is Null<Real>(), isn't ported: no member builds one.

Equality is nanoql's, where QuantLib has none: two rates are equal when they have the same source, target, rate (by Equals(double)) and type, and, for derived rates, equal chains. The exchange-rate registry's equality reads it.

Chain(ExchangeRate, ExchangeRate) refuses two rates over one pair of currencies, which QuantLib chains into a rate from a currency to itself (EUR→USD at 1.1 with EUR→USD at 1.2 gives USD→USD at 1.0909, which exchanges 100 USD into 109.09 USD): a documented divergence (Divergences/ExchangeRateChainRefusalTests.cs). The exchange-rate registry's chained lookups chain as QuantLib's, since their steps are never over one pair in its key.

Constructors

ExchangeRate(Currency?, Currency?, double)

Initializes a new instance of the ExchangeRate class: a direct rate.

public ExchangeRate(Currency? source, Currency? target, double rate)

Parameters

source Currency

The source currency; null for QuantLib's empty currency.

target Currency

The target currency; null for QuantLib's empty currency.

rate double

The units of the target a unit of the source is worth.

Properties

Rate

Gets the rate: the units of the target a unit of the source is worth.

public double Rate { get; }

Property Value

double

Source

Gets the source currency.

public Currency? Source { get; }

Property Value

Currency

Target

Gets the target currency.

public Currency? Target { get; }

Property Value

Currency

Type

Gets the type: given directly, or derived by chaining.

public ExchangeRateType Type { get; }

Property Value

ExchangeRateType

Methods

Chain(ExchangeRate, ExchangeRate)

Chains two exchange rates that share a currency into a derived rate between the other two.

public static ExchangeRate Chain(ExchangeRate r1, ExchangeRate r2)

Parameters

r1 ExchangeRate

The first rate.

r2 ExchangeRate

The second rate.

Returns

ExchangeRate

The derived rate.

Exceptions

ArgumentNullException

A rate is null.

ArgumentException

The rates share no currency, or are over one pair of currencies, QuantLib's "exchange rates not chainable".

Equals(ExchangeRate?)

Whether this rate has another's source, target, rate and type, and, if derived, an equal chain.

public bool Equals(ExchangeRate? other)

Parameters

other ExchangeRate

The other rate.

Returns

bool

true when they are equal.

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

Exchange(Money)

Applies the exchange rate to an amount in either of its currencies.

public Money Exchange(Money amount)

Parameters

amount Money

The amount.

Returns

Money

The amount in the other currency.

Exceptions

ArgumentException

The amount isn't in either of the rate's currencies.

GetHashCode()

public override int GetHashCode()

Returns

int