Table of Contents

RateLookupOptions Class

Definition

Namespace
Bodu.Financial.ExchangeRates
Assembly
Bodu.Financial.dll
Package
Bodu.Financial 1.0.0
Source
RateLookupOptions.cs

Encapsulates the rules an exchange-rate lookup must apply when an exact-date match is unavailable.

public sealed class RateLookupOptions
Inheritance
RateLookupOptions
Inherited Members
Extension Methods

Remarks

The type is a reference type so that default(RateLookupOptions) evaluates to null rather than a partially populated value. All public surfaces that accept lookup options allow null and substitute Exact when no options are supplied, ensuring the out-of-the-box behaviour matches the documented safe default.

Use the static factory members (Exact, PreviousWithin(int), NextWithin(int), NearestWithin(int)) for the common configurations; construct an options instance directly only when a less common combination is required.

using Bodu.Financial;

// Require an exact-date hit (the default safe behaviour).
var exact = RateLookupOptions.Exact;

// Fall back to the most recent rate on or before the requested date, up to five days back.
var previous = RateLookupOptions.PreviousWithin(5);

// Pick the closest available date either side, within a week, preferring the earlier on ties.
var nearest = RateLookupOptions.NearestWithin(7);

Constructors

RateLookupOptions(RateDateResolution, int, bool, bool)

Initializes a new instance of the RateLookupOptions class.

public RateLookupOptions(RateDateResolution dateResolution, int toleranceDays = 0, bool allowInverse = true, bool allowSameCurrencyIdentityRate = true)

Parameters

dateResolution RateDateResolution

The fallback policy when no rate exists on the requested date.

toleranceDays int

The maximum permitted absolute distance, in days, between the requested date and the resolved date. Must be zero when dateResolution is Exact.

allowInverse bool

When true, the lookup may fall back to the reverse-direction pair (returning the reciprocal rate) when the direct pair has no rate. When false, only the direct pair is consulted.

allowSameCurrencyIdentityRate bool

When true, a lookup whose source and destination ISO codes are equal returns a synthetic identity rate of 1. When false, the lookup falls through to the underlying table.

Properties

AllowInverse

Gets a value indicating whether the lookup may fall back to the reverse-direction pair.

public bool AllowInverse { get; }

Property Value

bool

true when the reverse-direction pair may be consulted and its rate inverted; otherwise false.

AllowSameCurrencyIdentityRate

Gets a value indicating whether a same-currency lookup returns a synthetic identity rate of 1.

public bool AllowSameCurrencyIdentityRate { get; }

Property Value

bool

true when same-currency lookups return the identity rate; otherwise false.

DateResolution

Gets the fallback policy applied when no rate exists on the requested date.

public RateDateResolution DateResolution { get; }

Property Value

RateDateResolution

The configured RateDateResolution.

Exact

Gets a configuration that requires an exact-date match, allowing inverse and same-currency identity fallbacks.

public static RateLookupOptions Exact { get; }

Property Value

RateLookupOptions

An RateLookupOptions with Exact.

ToleranceDays

Gets the maximum permitted absolute distance, in days, between the requested date and the resolved date.

public int ToleranceDays { get; }

Property Value

int

A non-negative tolerance in days.

Methods

NearestWithin(int)

Returns a configuration that resolves to the closest available date within toleranceDays, preferring the previous date on ties.

public static RateLookupOptions NearestWithin(int toleranceDays)

Parameters

toleranceDays int

The maximum permitted distance, in days, between requested and resolved dates.

Returns

RateLookupOptions

An RateLookupOptions with NearestPreferPrevious .

Exceptions

ArgumentOutOfRangeException

Thrown if toleranceDays is negative.

NextWithin(int)

Returns a configuration that resolves to the earliest rate on or after the requested date, within toleranceDays.

public static RateLookupOptions NextWithin(int toleranceDays)

Parameters

toleranceDays int

The maximum permitted distance, in days, between requested and resolved dates.

Returns

RateLookupOptions

An RateLookupOptions with NextOnOrAfter.

Exceptions

ArgumentOutOfRangeException

Thrown if toleranceDays is negative.

PreviousWithin(int)

Returns a configuration that resolves to the most recent rate on or before the requested date, within toleranceDays.

public static RateLookupOptions PreviousWithin(int toleranceDays)

Parameters

toleranceDays int

The maximum permitted distance, in days, between requested and resolved dates.

Returns

RateLookupOptions

An RateLookupOptions with PreviousOnOrBefore.

Exceptions

ArgumentOutOfRangeException

Thrown if toleranceDays is negative.

Validate()

Validates the option values, throwing if any rule is violated.

public void Validate()

Exceptions

ArgumentOutOfRangeException

Thrown if DateResolution is not a defined RateDateResolution member, or if ToleranceDays is negative.

ArgumentException

Thrown if DateResolution is Exact and ToleranceDays is non-zero.

Applies to

ProductVersions
.NET8, 10