API Reference

Market Context

Market data container, fixing store, and evaluation date management for production pricing workflows.

See also: Market Context Guide for complete usage patterns and serialization workflows.

All types are available via flat import:

from vade import MarketContext, FixingStore, eval_date

Contents: FixingStore | MarketContext | eval_date


FixingStore

In-memory store for historical fixing rates keyed by index name (e.g. "SOFR", "EURIBOR"). Pure Python.

Constructor

FixingStore()

Methods

MethodReturnsDescription
.set(index, fixings)NoneStore or merge fixings for an index. fixings is dict[date, float]
.get(index)dict[date, float] | NoneGet all fixings for an index (returns a copy)
.get_rate(index, dt)float | NoneGet single fixing rate by index and date
.clear(index=None)NoneClear one index or all indices if None
.list_indices()list[str]Sorted list of stored index names
.from_polars(df, index=None)NoneBulk-load from Polars DataFrame with columns date, rate, and optionally index
.from_csv(path, index=None)NoneBulk-load from CSV file (same column format as from_polars)
len(store)intTotal count of all fixings across all indices

Example

import datetime
from vade import FixingStore

store = FixingStore()
store.set("SOFR", {
    datetime.date(2024, 1, 2): 0.053,
    datetime.date(2024, 1, 3): 0.0531,
    datetime.date(2024, 1, 4): 0.0529,
})

rate = store.get_rate("SOFR", datetime.date(2024, 1, 2))
assert rate == 0.053

assert store.list_indices() == ["SOFR"]
assert len(store) == 3

# Merge additional fixings
store.set("EURIBOR", {datetime.date(2024, 1, 2): 0.039})
assert store.list_indices() == ["EURIBOR", "SOFR"]
assert len(store) == 4

MarketContext

Immutable container bundling all pricing inputs: evaluation date, named curves, historical fixings, FX rates, and calendars. Pure Python.

Constructor

MarketContext(*, eval_date=None, curves=None, fixings=None, fx_rates=None, fx_pairs=None, calendars=None)

Parameters

NameTypeDefaultDescription
eval_datedatetime.date | NoneNoneEvaluation (pricing) date. Falls back to module-level eval_date context, then date.today()
curvesdict[str, Any] | NoneNoneNamed curves keyed by string ID (e.g. {"USD_SOFR": curve})
fixingsFixingStore | NoneNoneHistorical fixing rates
fx_ratesFXRates | NoneNoneFX rate object for cross-currency pricing
fx_pairsdict[str, float] | NoneNoneRaw FX pair dict for serialization (required if fx_rates provided)
calendarsdict[str, Any] | NoneNoneNamed business day calendars

Properties

PropertyTypeDescription
.eval_datedatetime.dateRead-only evaluation date
.curvesdict[str, Any]Read-only curves dict (empty dict if None)
.fixingsFixingStoreRead-only fixing store (empty FixingStore if None)
.fx_ratesFXRates | NoneRead-only FX rates object
.calendarsdict[str, Any]Read-only calendars dict (empty dict if None)

Methods: Construction

MethodReturnsDescription
.from_solver(solver, *, eval_date=None, fixings=None, fx_rates=None, fx_pairs=None, calendars=None)MarketContextCreate context from calibrated Solver, extracting all curves by ID

Methods: Copy-on-Modify

MethodReturnsDescription
.with_eval_date(eval_date)MarketContextNew context with different evaluation date
.with_curve(curve_id, curve)MarketContextNew context with added/replaced curve
.with_fixings(fixings)MarketContextNew context with replaced fixing store
.with_fx_rates(fx_rates, *, fx_pairs=None)MarketContextNew context with replaced FX rates
.with_calendar(name, calendar)MarketContextNew context with added/replaced calendar

Methods: Lookup

MethodReturnsDescription
.curve(curve_id)DiscountCurve | ForwardCurve | ...Retrieve curve by string ID (raises KeyError if not found)

Methods: Analytics

MethodReturnsDescription
.discount_factor(curve_id, dt)float | Dual | Dual2Discount factor from curve at date
.forward_rate(curve_id, start, end)float | Dual | Dual2Forward rate from curve between dates
.zero_rate(curve_id, start, end)float | Dual | Dual2Zero rate from curve between dates
.fx_rate(base, quote)floatFX spot rate for currency pair

Methods: Comparison

MethodReturnsDescription
.diff(other, *, as_dataframe=False)dict | DataFrameCompare two contexts: shows added/removed/changed curves and fixings

Methods: Serialization

MethodReturnsDescription
.to_json()strSerialize full context to JSON string
.from_json(json_str) (classmethod)MarketContextRestore context from JSON string with polymorphic curve handling

Example

import datetime
from vade import MarketContext, FixingStore, DiscountCurve

effective = datetime.date(2025, 6, 16)

curve = DiscountCurve(
    {
        effective: 1.0,
        datetime.date(2026, 6, 16): 0.9615,
        datetime.date(2027, 6, 16): 0.9246,
    },
    interpolation="log_linear",
    convention="act360",
    id="usd_sofr",
)

store = FixingStore()
store.set("SOFR", {datetime.date(2025, 6, 13): 0.043})

ctx = MarketContext(
    eval_date=effective,
    curves={"usd_sofr": curve},
    fixings=store,
)

# Lookup
assert ctx.curve("usd_sofr") is curve

# Analytics
df = ctx.discount_factor("usd_sofr", datetime.date(2026, 6, 16))
assert abs(df - 0.9615) < 0.001

# Copy-on-modify (original unchanged)
ctx2 = ctx.with_eval_date(datetime.date(2025, 7, 16))
assert ctx.eval_date == effective
assert ctx2.eval_date == datetime.date(2025, 7, 16)

eval_date

Context manager for temporarily setting the module-level default evaluation date. Pure Python.

Usage

from vade import eval_date

with eval_date(datetime.date(2025, 6, 16)):
    # All vade calls within this block use 2025-06-16 as default eval_date
    ...

Example

import datetime
from vade import eval_date

d = datetime.date(2025, 6, 16)
with eval_date(d):
    pass  # eval_date context active
# context restored after block exits

On this page