Table of Contents

RateBook Class

Definition

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

Provides an immutable, read-heavy collection of RateSeries instances keyed by RateSeriesKey (pair + provider), forming the immutable bridge between mutable build-side types (RateTableBuilder) and dated lookup providers ( FixedDatedRateProvider and friends).

public sealed class RateBook
Inheritance
RateBook
Inherited Members
Extension Methods

Remarks

The book stores at most one series per (pair, provider) combination, allowing the same currency pair to be represented by multiple providers within a single immutable store. Providers built on top of the book apply an explicit provider-selection policy at lookup time.

Instances are safe to share across threads after construction because all read paths only touch the underlying frozen dictionary.

using Bodu.Financial;

var series = new RateSeries(
    new CurrencyPair(CurrencyCode.USD, CurrencyCode.EUR),
    "ECB",
    new[] { (new DateOnly(2024, 3, 1), 0.92m), (new DateOnly(2024, 3, 4), 0.93m) });

var book = new RateBook(new[] { series });

// Look the series back up by pair and provider.
if (book.TryGetSeries(series.Pair, "ECB", out RateSeries? found))
{
    int count = found!.Count;   // 2
}

Constructors

RateBook(IEnumerable<RateSeries>)

Initializes a new instance of the RateBook class from the supplied series.

public RateBook(IEnumerable<RateSeries> series)

Parameters

series IEnumerable<RateSeries>

The series to include in the book.

Exceptions

ArgumentNullException

Thrown if series is null, or if any element of series is null.

ArgumentException

Thrown if two series share the same pair and provider.

Properties

Count

Gets the number of (pair, provider) series held by the book.

public int Count { get; }

Property Value

int

A non-negative series count.

Keys

Gets the set of keys currently held.

public IReadOnlyCollection<RateSeriesKey> Keys { get; }

Property Value

IReadOnlyCollection<RateSeriesKey>

The keys exposed by the underlying frozen dictionary.

Methods

EnumerateSeries()

Enumerates every series in the book.

public IEnumerable<RateSeries> EnumerateSeries()

Returns

IEnumerable<RateSeries>

A lazy sequence of RateSeries instances.

GetSeries(CurrencyPair)

Enumerates every series whose currency pair equals pair, regardless of provider.

public IEnumerable<RateSeries> GetSeries(CurrencyPair pair)

Parameters

pair CurrencyPair

The currency pair to filter by.

Returns

IEnumerable<RateSeries>

A lazy sequence of RateSeries instances ordered by their hash slot.

Exceptions

ArgumentException

Thrown if pair is invalid.

ToBuilder()

Creates a mutable RateTableBuilder seeded with a copy of every series in this book, including each series' fetch instant.

public RateTableBuilder ToBuilder()

Returns

RateTableBuilder

A new builder whose contents start equal to this book.

Remarks

This is the editing counterpart of ToBook(): edits to the returned builder never affect this book, and calling ToBook() on the builder completes the round trip. It mirrors the per-series ToBuilder().

TryGetSeries(CurrencyPair, string, out RateSeries?)

Attempts to retrieve the series for the supplied pair and provider.

public bool TryGetSeries(CurrencyPair pair, string provider, out RateSeries? series)

Parameters

pair CurrencyPair

The currency pair.

provider string

The non-empty identifier of the publishing source.

series RateSeries

When this method returns true, the matching series; otherwise null.

Returns

bool

true if a matching series exists; otherwise false.

Exceptions

ArgumentException

Thrown if pair is invalid or provider is empty / white-space.

ArgumentNullException

Thrown if provider is null.

Applies to

ProductVersions
.NET8, 10