跳转到正文

kiyosi.market ​

Market snapshots, rate curves, calendars, and observation schedules.

Notes ​

Rates use annual decimal units and continuous compounding; volatility is annualized in decimal units under the variance time convention. Models default to variance_time_convention="actual_365_fixed"; BSM and local-volatility PDE models also accept variance_time_convention="business", calendar=.... Business time uses the calendar's fixed basis and advances uniformly over trading dates, stopping on closed dates. Rates and continuous dividend yields use Actual/365 Fixed by default. Pass reference_time, max_time and calendar to RateTermStructure.flat for calendar-based accrual independent of the model's variance clock. Changing the model clock does not convert volatility values.

BlackScholesMertonParameters accepts nonnegative volatility; zero selects deterministic pricing. LocalVolatilityParameters uses an absolute time/spot surface. HestonParameters uses risk-neutral variance parameters on an Actual/365 Fixed variance clock. Each engine documents its support and controls.

Read model rates through risk_free_curve and dividend_curve for term structure queries and to preserve coverage when reusing model rates. Scalar rate queries discard coverage bounds. Use RateTermStructure.flat with coverage bounds and the default day count when you need an exact constant forward rate. Rounded node factors may imply slightly different forward rates.

Calendars classify dates without moving contract boundaries. Automatic schedules require an explicit observation clock. ObservationSchedule supports integer indexing, slicing, and reversed(schedule). Forward and reverse iteration yield timestamps lazily and retain the schedule owner. Slices return independent schedules with the same calendar and reject decreasing selections. The calendar property preserves the validation calendar; plain lists and tuples contain no calendar. Schedule-taking constructors inherit this calendar unless explicitly overridden.

Examples ​

Validate an irregular schedule with exact observation times:

python
>>> from datetime import datetime
>>> times = [datetime(2025, 1, 3, 15), datetime(2025, 1, 8, 14, 30)]
>>> schedule = ObservationSchedule(
...     times=times, start_time=datetime(2025, 1, 1),
...     end_time=datetime(2025, 1, 10),
... )
>>> list(schedule) == times
True

Build monthly observations from a month-end anchor. February is clamped without moving the March anchor:

python
>>> from datetime import datetime, time
>>> schedule = ObservationSchedule.monthly(
...     start_time=datetime(2025, 1, 31), end_time=datetime(2025, 3, 31),
...     first_observation_month=1, observation_clock_time=time(0),
...     calendar=TradingCalendar.all_days(),
... )
>>> [stamp.isoformat() for stamp in schedule]
['2025-02-28T00:00:00', '2025-03-31T00:00:00']

BlackScholesMertonParameters ​

python
BlackScholesMertonParameters(*, risk_free_rate, dividend_yield, volatility, variance_time_convention='actual_365_fixed', calendar=None)

Black-Scholes-Merton (BSM) model parameters.

Parameters ​

  • risk_free_rate (float or RateTermStructure) — Continuously compounded risk-free rate or owned rate curve.
  • dividend_yield (float or RateTermStructure) — Continuously compounded dividend yield or owned rate curve.
  • volatility (float) — Nonnegative finite annualized log-return volatility in decimal units. Zero selects the exact deterministic path implied by the rate curves.
  • variance_time_convention ({"actual_365_fixed", "business"}, optional) — Volatility annualization and variance clock. The Rust default is actual_365_fixed. The rate curves define rate and dividend accrual.
  • calendar (TradingCalendar or None, optional) — Required for business time and rejected for actual_365_fixed. Business time accumulates uniformly over each trading date's 24 hours, divided by the calendar's fixed annualization basis; closed dates contribute zero. Contract observation calendars are independent. Replacement preserves omitted volatility values without unit conversion when changing the clock.

Raises ​

  • InvalidInputError — If scalar rates are non-finite or volatility is negative or non-finite.

calendar ​

Return an owned variance calendar, or None for Actual/365 Fixed.

dividend_curve ​

Return an owned copy of the dividend curve.

flat_dividend_yield ​

Return the scalar yield for dated or undated constant curves.

Use dividend_curve to preserve coverage when passing yields to constructors or replacements.

Raises ​

  • UnsupportedOperationError — If the curve is nonconstant.

flat_risk_free_rate ​

Return the scalar rate for dated or undated constant curves.

Use risk_free_curve to preserve coverage when passing rates to constructors or replacements.

Raises ​

  • UnsupportedOperationError — If the curve is nonconstant.

replace ​

python
replace(self, /, *, risk_free_rate=Ellipsis, dividend_yield=Ellipsis, volatility=Ellipsis, variance_time_convention=Ellipsis, calendar=Ellipsis)

Return a validated copy with the supplied fields applied.

Omit a field or pass Ellipsis to use its instance value.

Parameters ​

  • risk_free_rate (float or RateTermStructure, optional) — Continuously compounded risk-free rate or discount curve.
  • dividend_yield (float or RateTermStructure, optional) — Continuously compounded dividend yield or curve.
  • volatility (float, optional) — Nonnegative annualized log-return volatility.
  • variance_time_convention ({'actual_365_fixed', 'business'}, optional) — Clock for accumulating variance.
  • calendar (TradingCalendar or None, optional) — Calendar for business time. Pass None to clear it.

Returns ​

  • object — Validated copy of the same class.

Raises ​

  • InvalidInputError — If the merged fields fail model validation.
  • TypeError — If a representation or keyword is invalid.
  • ValueError — If the variance_time_convention choice is unknown.

risk_free_curve ​

Return an owned copy of the risk-free curve.

variance_time_convention ​

Return the model's variance time convention.

volatility ​

Return nonnegative finite annualized volatility in decimal units.

BusinessDayConvention ​

python
BusinessDayConvention = typing.Literal['following', 'preceding']

HestonParameters ​

python
HestonParameters(*, risk_free_rate, dividend_yield, initial_variance, long_run_variance, mean_reversion_speed, vol_of_vol, correlation)

Heston stochastic-volatility parameters under the risk-neutral measure.

Variance parameters use Actual/365 Fixed. The rate curves define rate and dividend accrual independently.

Parameters ​

  • risk_free_rate, dividend_yield (float or RateTermStructure) — Continuously compounded annual rates or owned deterministic curves.
  • initial_variance (float) — Variance at valuation; 20% initial volatility means 0.04 variance.
  • long_run_variance (float) — Long-run variance level theta.
  • mean_reversion_speed (float) — Mean-reversion coefficient kappa, with time measured in years.
  • vol_of_vol (float) — Volatility-of-volatility parameter xi in dv = kappa * (theta - v) dt + xi * sqrt(v) dW.
  • correlation (float) — Correlation between the asset and variance Brownian motions in [-1, 1], including endpoints.

Raises ​

  • InvalidInputError — For non-finite inputs, negative variance parameters or invalid correlation.

Notes ​

Zero parameters and violations of the Feller condition (2 * kappa * theta

= xi**2) are accepted. AnalyticHestonEuropeanEngine prices European options; FiniteDifferenceHestonVanillaEngine prices European and American options. Requested Greeks have status "unsupported"; implied-parameter solvers raise UnsupportedOperationError. Numeric conversion rejects booleans. Replacement uses Rust validation and returns a separate owned model.

calendar ​

Return an owned variance calendar, or None for Actual/365 Fixed.

correlation ​

Return the correlation between the asset and variance Brownian motions.

dividend_curve ​

Return an owned copy of the dividend curve.

flat_dividend_yield ​

Return the scalar yield for dated or undated constant curves.

Use dividend_curve to preserve coverage when passing yields to constructors or replacements.

Raises ​

  • UnsupportedOperationError — If the curve is nonconstant.

flat_risk_free_rate ​

Return the scalar rate for dated or undated constant curves.

Use risk_free_curve to preserve coverage when passing rates to constructors or replacements.

Raises ​

  • UnsupportedOperationError — If the curve is nonconstant.

initial_variance ​

Return instantaneous variance at valuation.

long_run_variance ​

Return the long-run variance level.

mean_reversion_speed ​

Return mean-reversion speed per year.

replace ​

python
replace(self, /, *, risk_free_rate=Ellipsis, dividend_yield=Ellipsis, initial_variance=Ellipsis, long_run_variance=Ellipsis, mean_reversion_speed=Ellipsis, vol_of_vol=Ellipsis, correlation=Ellipsis)

Return a validated copy with the supplied fields applied.

Omit a field or pass Ellipsis to use its instance value.

Parameters ​

  • risk_free_rate (float or RateTermStructure, optional) — Continuously compounded risk-free rate or discount curve.
  • dividend_yield (float or RateTermStructure, optional) — Continuously compounded dividend yield or curve.
  • initial_variance (float, optional) — Initial instantaneous variance.
  • long_run_variance (float, optional) — Long-run mean variance.
  • mean_reversion_speed (float, optional) — Rate of mean reversion of variance.
  • vol_of_vol (float, optional) — Volatility of the variance process.
  • correlation (float, optional) — Correlation between the spot and variance shocks.

Returns ​

  • object — Validated copy of the same class.

Raises ​

  • InvalidInputError — If the merged fields fail model validation.
  • TypeError — If a representation or keyword is invalid.

risk_free_curve ​

Return an owned copy of the risk-free curve.

variance_time_convention ​

Return the model's variance time convention.

vol_of_vol ​

Return the volatility-of-volatility parameter xi.

LocalVolatilityParameters ​

python
LocalVolatilityParameters(*, risk_free_rate, dividend_yield, surface, variance_time_convention='actual_365_fixed', calendar=None)

Local-volatility model parameters.

Parameters ​

  • risk_free_rate, dividend_yield (float or RateTermStructure) — Finite continuously compounded rates or validated rate curves.
  • surface (LocalVolatilitySurface) — Validated surface in absolute time and price coordinates.
  • variance_time_convention ({"actual_365_fixed", "business"}, optional) — Volatility annualization and variance clock. The Rust default is actual_365_fixed. The rate curves define rate and dividend accrual.
  • calendar (TradingCalendar or None, optional) — Required for business time and rejected for actual_365_fixed. Business time accumulates uniformly over each trading date's 24 hours, divided by the calendar's fixed annualization basis; closed dates contribute zero. Contract observation calendars are independent. Replacement preserves omitted volatility values without unit conversion when changing the clock.

Raises ​

  • InvalidInputError — If a scalar rate is non-finite.

Notes ​

Surface and curve coverage are checked by the context and during pricing over the required remaining horizons. The one-dimensional finite-difference engines support price, delta and gamma with deterministic rate curves.

calendar ​

Return an owned variance calendar, or None for Actual/365 Fixed.

dividend_curve ​

Return an owned copy of the dividend curve.

flat_dividend_yield ​

Return the scalar yield for dated or undated constant curves.

Use dividend_curve to preserve coverage when passing yields to constructors or replacements.

Raises ​

  • UnsupportedOperationError — If the curve is nonconstant.

flat_risk_free_rate ​

Return the scalar rate for dated or undated constant curves.

Use risk_free_curve to preserve coverage when passing rates to constructors or replacements.

Raises ​

  • UnsupportedOperationError — If the curve is nonconstant.

replace ​

python
replace(self, /, *, risk_free_rate=Ellipsis, dividend_yield=Ellipsis, surface=Ellipsis, variance_time_convention=Ellipsis, calendar=Ellipsis)

Return a validated copy with the supplied fields applied.

Omit a field or pass Ellipsis to use its instance value.

Parameters ​

  • risk_free_rate (float or RateTermStructure, optional) — Continuously compounded risk-free rate or discount curve.
  • dividend_yield (float or RateTermStructure, optional) — Continuously compounded dividend yield or curve.
  • surface (LocalVolatilitySurface, optional) — Local volatility by absolute timestamp and spot.
  • variance_time_convention ({'actual_365_fixed', 'business'}, optional) — Clock for accumulating variance.
  • calendar (TradingCalendar or None, optional) — Calendar for business time. Pass None to clear it.

Returns ​

  • object — Validated copy of the same class.

Raises ​

  • InvalidInputError — If the merged fields fail model validation.
  • TypeError — If a representation or keyword is invalid.
  • ValueError — If the variance_time_convention choice is unknown.

risk_free_curve ​

Return an owned copy of the risk-free curve.

surface ​

Return an owned copy of the fixed surface.

variance_time_convention ​

Return the model's variance time convention.

LocalVolatilitySurface ​

python
LocalVolatilitySurface(*, times, spots, values)

Local-volatility table indexed by time (rows) and absolute spot (columns).

Parameters ​

  • times (iterable of datetime.datetime) — At least two strictly increasing instants; the first is the reference.
  • spots (iterable of float) — At least two strictly increasing positive finite prices.
  • values (iterable of iterable of float) — Rectangular positive finite annualized volatilities (20% is 0.2).

Raises ​

  • InvalidInputError — If the table shape, nodes or values are invalid, or the table exceeds 16,777,216 cells.

Notes ​

Local volatility interpolates bilinearly in time and absolute spot price, using Actual/365 Fixed year fractions. Time extrapolation is rejected; extrapolation in the spot dimension holds the nearest endpoint volatility constant. Inputs are copied. Properties return owned copies; spot changes and time rolls never translate the surface. Native conversion errors reject booleans, dates, timezone-aware datetimes and invalid iterable elements. Construction polls Python signals. Large tables release the GIL during native validation and copying.

maximum_volatility ​

Return the largest supplied annualized volatility.

spots ​

Return copied absolute price nodes.

times ​

Return copied absolute time nodes as datetimes.

values ​

Return copied volatility rows, indexed by time then price.

volatility ​

python
volatility(self, /, time, spot)

Interpolate sigma at an absolute time and positive spot.

Parameters ​

  • time (datetime.datetime) — Covered query instant.
  • spot (float) — Positive finite underlying price; extrapolation holds endpoint volatility constant.

Returns ​

  • float — Annualized local volatility in decimal units.

Raises ​

  • InvalidInputError — If time is outside coverage or spot is nonpositive or non-finite.

ObservationSchedule ​

python
ObservationSchedule(*, times, start_time, end_time, calendar=Ellipsis)

Ordered observation times with sequence access.

Parameters ​

  • times (iterable of datetime.datetime) — Strictly increasing observation timestamps; empty input is valid.
  • start_time, end_time (datetime.datetime) — Inclusive validation bounds, with start_time at or before end_time.
  • calendar (TradingCalendar, optional) — Calendar used to validate each observation date. Omission or Ellipsis inherits times.calendar for an ObservationSchedule, otherwise weekdays.

Raises ​

  • InvalidInputError — If life bounds are reversed, the count exceeds 4,194,304, times are unordered or outside life, or an observation date is closed.

Notes ​

Construct from explicit times, or use fixed_interval or monthly. Bounds and calendar validate the input; the schedule owns its times and calendar. The times property returns a copy; forward and reverse iteration retrieve timestamps lazily and retain the schedule owner. Integer indexing accepts negative indices, rejects bool, and raises IndexError outside the sequence. Slices return independent schedules with the same calendar. Decreasing selections raise InvalidInputError. Slice bounds and steps accept integers excluding bool; a zero step raises ValueError. len(schedule) counts observations. Long validation and slicing release the GIL and poll Python signals.

__getitem__ ​

python
__getitem__(self, key, /)

Return self[key].

__iter__ ​

python
__iter__(self, /)

Implement iter(self).

__len__ ​

python
__len__(self, /)

Return len(self).

calendar ​

Return an owned copy of the calendar used to validate the schedule.

fixed_interval ​

python
fixed_interval(*, start_time, end_time, interval_days, observation_clock_time, calendar=TradingCalendar(kind='weekdays', trading_days_per_year=261))

Create adjusted observations at positive fixed calendar-day intervals.

Parameters ​

  • start_time (datetime.datetime) — First timestamp of the interval.
  • end_time (datetime.datetime) — Last timestamp of the interval.
  • interval_days (int) — Positive calendar-day spacing of unadjusted observations, up to 2**63 - 1.
  • observation_clock_time (datetime.time) — Required observation time of day, without timezone information.
  • calendar (TradingCalendar, optional) — Trading calendar. Defaults to weekdays with a 261-day basis.

Returns ​

  • ObservationSchedule — Ordered observation times and their validation calendar.

Raises ​

  • InvalidInputError — If end_time precedes start_time, interval_days is nonpositive, or the schedule exceeds 4,194,304 observations.
  • TypeError — If interval_days is not an integer or is bool.
  • OverflowError — If interval_days is outside the signed 64-bit range.

Notes ​

Exclude start_time and include candidates through end_time. Following adjustment merges collisions and stops before crossing end_time; end_time need not appear. Long scans release the GIL and poll Python signals.

monthly ​

python
monthly(*, start_time, end_time, first_observation_month, observation_clock_time, calendar=TradingCalendar(kind='weekdays', trading_days_per_year=261))

Create monthly observations anchored to the start_time day.

Parameters ​

  • start_time (datetime.datetime) — First timestamp of the interval.
  • end_time (datetime.datetime) — Last timestamp of the interval.
  • first_observation_month (int) — Positive month offset from start_time to the first observation.
  • observation_clock_time (datetime.time) — Required observation time of day, without timezone information.
  • calendar (TradingCalendar, optional) — Trading calendar. Defaults to weekdays with a 261-day basis.

Returns ​

  • ObservationSchedule — Ordered observation times and their validation calendar.

Raises ​

  • InvalidInputError — If end_time precedes start_time, first_observation_month is nonpositive, or the schedule exceeds 4,194,304 observations.

Notes ​

Clamp each candidate to its month end while retaining the original starting-day anchor for later months. Exclude start_time and include candidates through end_time. Following adjustment merges collisions and stops before crossing end_time; end_time need not appear. Long scans release the GIL and poll Python signals.

times ​

Return a copy of the strictly ordered observation times.

PricingContext ​

python
PricingContext(*, model_parameters, spot_price, valuation_time)

Market snapshot for one valuation instant.

Parameters ​

  • model_parameters (model object) — A BlackScholesMertonParameters, LocalVolatilityParameters, or HestonParameters object with validated rates and volatility inputs.
  • spot_price (float) — Positive finite underlying spot price.
  • valuation_time (datetime.datetime) — Valuation time.

Raises ​

  • InvalidInputError — If spot_price is nonpositive or non-finite or valuation_time is outside either rate curve or the local-volatility surface. Contract-life and expiry coverage checks occur at pricing.

model_parameters ​

Return an owned copy of the model parameters.

replace ​

python
replace(self, /, *, model_parameters=Ellipsis, spot_price=Ellipsis, valuation_time=Ellipsis)

Return a validated copy with replacement fields.

Omitted fields and fields set to Ellipsis use the instance's values. None clears nullable fields. The class documentation describes the accepted type and meaning of each field.

Parameters ​

  • model_parameters (object, optional) — Replacement field.
  • spot_price (object, optional) — Replacement field.
  • valuation_time (object, optional) — Replacement field.

Returns ​

  • object — Validated instance of the same class.

Raises ​

  • InvalidInputError — If fields fail constructor validation.
  • TypeError — If a field name or representation is invalid.

spot_price ​

Return positive finite underlying spot price.

valuation_time ​

Return valuation time.

RateTermStructure ​

python
RateTermStructure(*, reference_time, times, factors)

Rate term structure with log-linear discount factors.

Parameters ​

  • reference_time (datetime.datetime) — Inclusive curve reference; factors equal one at this instant.
  • times (iterable of datetime.datetime) — Strictly increasing nodes after the reference.
  • factors (iterable of float) — Positive finite factors at the nodes; log factors interpolate linearly.

Raises ​

  • InvalidInputError — If nodes or factors are empty or mismatched, the curve has more than 1,048,576 nodes, times do not increase after the reference, factors are nonpositive or non-finite, or implied forward rates are non-finite.

Notes ​

Uses Actual/365 Fixed by default. Factor nodes interpolate log-linearly. A bounded flat quote can accrue on a calendar. Dated curves reject times outside their coverage. Negative rates are allowed. Constructing a large node curve releases the GIL and polls Python signals during core validation.

base_factors ​

Return original node factors without parallel shifts.

Quote-based curves have no supplied factors. For factor-node curves, pass these factors with reference_time and nodes to RateTermStructure, then call shifted(parallel_shift).

exact_flat_rate ​

Return the scalar rate when all implied forwards are exactly constant.

This read-only query returns None for nonconstant curves.

factor ​

python
factor(self, /, start_time, end_time)

Return the factor over an ordered, covered interval.

Parameters ​

  • start_time, end_time (datetime.datetime) — Ordered interval endpoints.

Returns ​

  • float — Interval factor; underflow to zero is allowed.

Raises ​

  • InvalidInputError — If endpoints are reversed or outside curve coverage.
  • ComputationFailureError — If the log factor is non-finite or exponentiation overflows.

factors ​

Return owned node factors including shifts, allowing underflow to zero.

Raises ​

  • ComputationFailureError — If a log factor is non-finite or exponentiation overflows.

Notes ​

Calendar curves return factors at their transition times. Reconstruct factor-node curves from base_factors, then apply shifted(parallel_shift). Large factor calculations release the GIL and poll Python signals.

flat ​

python
flat(rate, *, reference_time=None, max_time=None, calendar=None)

Create a flat curve from a continuously compounded annual rate.

Parameters ​

  • rate (float) — Finite annual rate in decimal units. Negative rates are allowed.
  • reference_time (datetime.datetime or None, optional) — Inclusive lower coverage bound. None creates an undated curve.
  • max_time (datetime.datetime or None, optional) — Inclusive upper coverage bound. Requires reference_time. Equal bounds select a single instant.
  • calendar (TradingCalendar or None, optional) — Actual/365 Fixed applies by default. A calendar requires both coverage bounds. Open days accrue their elapsed fraction divided by the calendar's annualization basis. Closed days contribute zero.

Returns ​

  • RateTermStructure — Owned curve retaining its annual quote and coverage through shifts. Calendar transitions within the bounds appear in nodes.

Raises ​

  • TypeError — If max_time is supplied without reference_time, or a calendar is supplied without both coverage bounds.
  • InvalidInputError — If the rate or an implied forward is non-finite, or max_time precedes reference_time.

Notes ​

Long calendar scans release the GIL and poll Python signals.

forward_rate ​

python
forward_rate(self, /, time)

Return the right-hand instantaneous forward rate.

Parameters ​

  • time (datetime.datetime) — Query instant. The coverage endpoint uses its left interval.

Returns ​

  • float — Continuously compounded forward rate in Actual/365 Fixed decimal units.

Raises ​

  • InvalidInputError — If the instant is outside curve coverage.

log_factor ​

python
log_factor(self, /, start_time, end_time)

Return the log factor over an ordered, covered interval.

Parameters ​

  • start_time, end_time (datetime.datetime) — Ordered interval endpoints.

Returns ​

  • float — Log of the interval factor, using the curve's accrual convention.

Raises ​

  • InvalidInputError — If endpoints are reversed or outside curve coverage.
  • ComputationFailureError — If the result is non-finite.

max_time ​

Return the inclusive upper bound, or None for an unbounded flat curve.

nodes ​

Return a copy of factor nodes or calendar transition times.

parallel_shift ​

Return the accumulated node-curve parallel shift in decimal units.

Quote-based curves include shifts in their rate and return zero here.

reference_time ​

Return the inclusive lower coverage bound, or None if undated.

shifted ​

python
shifted(self, /, shift)

Return a parallel-shifted copy of this curve.

Parameters ​

  • shift (float) — Finite additive rate shift in the curve's annual quote units.

Returns ​

  • RateTermStructure — Independent curve with the source curve's coverage bounds.

Raises ​

  • InvalidInputError — If the shift or resulting rates are non-finite.

TradingCalendar ​

Trading calendar with a fixed annualization basis.

Notes ​

Use the calendar factory functions to construct instances. Calendars with equal bases, normalized overrides and annualization bases compare equal. Empty overrides retain the base calendar's kind. Long searches and date counts release the GIL and poll Python signals.

adjust ​

python
adjust(self, /, nominal, convention)

Find a trading date in the selected direction, including the input date.

Parameters ​

  • nominal (datetime.date) — Unadjusted date.
  • convention ({'following', 'preceding'}) — Direction to search.

Returns ​

  • datetime.date — First trading date encountered.

Raises ​

  • InvalidInputError — If the Rust core's supported date range is exhausted.
  • ValueError — If the resulting date is outside Python's years 1 through 9999. For example, preceding adjustment of a closed datetime.date.min cannot be converted back to a Python date.

all_days ​

python
all_days()

Create a calendar with every date open and a 365-day basis.

Returns ​

  • TradingCalendar — Calendar with the stated annualization basis.

custom ​

python
custom(*, base, closed_dates=(), open_dates=(), trading_days_per_year=None)

Derive a calendar from a base calendar and open and closed date overrides.

Parameters ​

  • base (TradingCalendar) — Base calendar.
  • closed_dates (iterable of date, optional) — Dates forced closed; duplicates and unsorted input are accepted.
  • open_dates (iterable of date, optional) — Dates forced open, including weekends; must not also be closed.
  • trading_days_per_year (int or None, optional) — Positive annualization basis, or None to retain the base basis.

Returns ​

  • TradingCalendar — Calendar with normalized overrides and the selected annualization basis.

Raises ​

  • InvalidInputError — If a date is both open and closed, or the annualization basis is nonpositive.

Notes ​

Date conversion polls Python signals. Large override merges release the GIL and poll Python signals during normalization.

is_trading_day ​

python
is_trading_day(self, /, value)

Return whether a date is open in this calendar.

Parameters ​

  • value (datetime.date) — Date to test; datetime values are not accepted.

Returns ​

  • bool — Whether the date is a trading day, including explicit overrides.

sse ​

python
sse()

Create a Shanghai Stock Exchange (SSE) calendar with a 243-day basis.

Returns ​

  • TradingCalendar — Calendar with the stated annualization basis.

Notes ​

Uses recorded and forecast weekday closures for 1991-2099, and weekdays outside that range. Forecasts omit ad-hoc closures.

trading_days_between ​

python
trading_days_between(self, /, start, end)

Count trading dates in the half-open interval [start, end).

Parameters ​

  • start, end (datetime.date) — Ordered interval endpoints.

Returns ​

  • int — Number of trading dates.

Raises ​

  • InvalidInputError — If end precedes start.

trading_days_per_year ​

Return the positive calendar annualization basis.

trading_year_fraction ​

python
trading_year_fraction(self, /, start, end)

Return trading-day count divided by the calendar annualization basis.

Parameters ​

  • start, end (datetime.date) — Ordered endpoints of the half-open interval [start, end).

Returns ​

  • float — Trading-year fraction.

Raises ​

  • InvalidInputError — If end precedes start.

weekdays ​

python
weekdays()

Create a Monday-through-Friday calendar with a 261-day basis.

Returns ​

  • TradingCalendar — Calendar with the stated annualization basis.