interface
TradingEnvironmentDefinition
What an environment simulates: the stepper's request plus the episode bound, the limits, the reward, the features.
/** What an environment simulates: the stepper's request plus the episode bound, the limits, the reward, the features. */
export interface TradingEnvironmentDefinition extends PortfolioStepperRequest {
/** The most steps an episode takes before `truncated` (default: the instant count; ceiling 100,000). */
maximumSteps?: number;
limits?: EnvironmentLimits;
reward?: RewardComposition;
features?: FeatureRecipes;
}Fields, parameters & returned members (147)
| Name / type | Meaning & unit | Optional / default |
|---|---|---|
accountingimport('@insiderfinance/totalfinance/backtest/portfolio').AccountingPolicy | unitless by name | Required / declared member No @default declared; consult the signature and description. |
accounting.baseCurrencystring | ISO-4217 currency code | Required / declared member No @default declared; consult the signature and description. |
accounting.initialCashreadonly { currency: string; amount: number; }[] | currency amount (the field or record currency) | Required / declared member No @default declared; consult the signature and description. |
accounting.lotReliefimport('@insiderfinance/totalfinance/portfolio').LotReliefPolicy | Default `'fifo'`. unitless by name | Optional No @default declared; consult the signature and description. |
accounting.settlementPartial<Record<import('@insiderfinance/totalfinance/backtest/portfolio').AssetClass, 'T+0' | 'T+1' | 'T+2'>> | Settlement lag per asset class; default equities/etf/option/bond `'T+1'`, everything else `'T+0'`. unitless by name | Optional No @default declared; consult the signature and description. |
calendarstring | A calendar name (`'NYSE'`, `'CBOE'`, `'ALWAYS_OPEN'`): sessions and settlement days. unitless by name | Optional No @default declared; consult the signature and description. |
executionimport('@insiderfinance/totalfinance/backtest/execution').ExecutionPolicy | unitless by name | Optional No @default declared; consult the signature and description. |
execution.ambiguityimport('@insiderfinance/totalfinance/backtest/execution').AmbiguityPolicy | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.costsimport('@insiderfinance/totalfinance/backtest/execution').ExecutionCosts | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.costs.borrowimport('@insiderfinance/totalfinance/backtest').BorrowModel | unitless by name | Optional No @default declared; consult the signature and description. |
execution.costs.borrow.annualRatenumber | Annualized borrow rate (decimal, e.g. `0.005` = 50 bps/yr). decimal rate (0.05 = 5%) | Required / declared member No @default declared; consult the signature and description. |
execution.costs.borrow.labelstring | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.costs.commissionimport('@insiderfinance/totalfinance/backtest').CostModel | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.costs.commission.commission(input: import('@insiderfinance/totalfinance/backtest/costs').CommissionInput) => number | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.costs.commission.commission(input)import('@insiderfinance/totalfinance/backtest/costs').CommissionInput | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.costs.commission.commission(input).pricenumber | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.costs.commission.commission(input).quantitynumber | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.costs.commission.labelstring | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.costs.latencyimport('@insiderfinance/totalfinance/backtest/execution').LatencyModel | unitless by name | Optional No @default declared; consult the signature and description. |
execution.costs.latency.labelstring | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.costs.latency.sessionsnumber | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.costs.marketImpactimport('@insiderfinance/totalfinance/backtest/execution').MarketImpactModel | unitless by name | Optional No @default declared; consult the signature and description. |
execution.costs.marketImpact.impact(input: { quantity: number; referencePrice: number; averageDailyVolume?: number; }) => number | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.costs.marketImpact.impact(input){ averageDailyVolume?: number; quantity: number; referencePrice: number; } | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.costs.marketImpact.impact(input).averageDailyVolumenumber | unitless by name | Optional No @default declared; consult the signature and description. |
execution.costs.marketImpact.impact(input).quantitynumber | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.costs.marketImpact.impact(input).referencePricenumber | currency amount (the field or record currency) | Required / declared member No @default declared; consult the signature and description. |
execution.costs.marketImpact.labelstring | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.costs.participationnumber | Fraction of the observation's volume one fill may take. unitless by name | Optional No @default declared; consult the signature and description. |
execution.costs.slippageimport('@insiderfinance/totalfinance/backtest').SlippageModel | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.costs.slippage.fill(input: import('@insiderfinance/totalfinance/backtest/costs').SlippageFillInput) => number | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.costs.slippage.fill(input)import('@insiderfinance/totalfinance/backtest/costs').SlippageFillInput | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.costs.slippage.fill(input).quantitynumber | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.costs.slippage.fill(input).referencePricenumber | currency amount (the field or record currency) | Required / declared member No @default declared; consult the signature and description. |
execution.costs.slippage.fill(input).sideOrderSide | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.costs.slippage.labelstring | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.costs.spreadimport('@insiderfinance/totalfinance/backtest/execution').SpreadModel | unitless by name | Optional No @default declared; consult the signature and description. |
execution.costs.spread.halfSpread(input: { referencePrice: number; side: OrderSide; }) => number | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.costs.spread.halfSpread(input){ referencePrice: number; side: OrderSide; } | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.costs.spread.halfSpread(input).referencePricenumber | currency amount (the field or record currency) | Required / declared member No @default declared; consult the signature and description. |
execution.costs.spread.halfSpread(input).sideOrderSide | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.costs.spread.labelstring | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.fillimport('@insiderfinance/totalfinance/backtest/execution').FillModel | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.fill.fill(request: import('@insiderfinance/totalfinance/backtest/execution').FillRequest) => import('@insiderfinance/totalfinance/backtest/execution').FillDecision | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.fill.fill().return.clampedToPriceLimitboolean | The fill price was clamped into a session price-limit band. unitless by name | Optional No @default declared; consult the signature and description. |
execution.fill.fill().return.detailstring | unitless by name | Optional No @default declared; consult the signature and description. |
execution.fill.fill().return.levelsConsumednumber | Order-book fills: how many levels the quantity consumed. unitless by name | Optional No @default declared; consult the signature and description. |
execution.fill.fill().return.outcome('filled') | ('unfilled') | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.fill.fill().return.partialboolean | Less than the requested quantity (participation, depth, size caps). unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.fill.fill().return.pricePerUnitnumber | currency per unit | Required / declared member No @default declared; consult the signature and description. |
execution.fill.fill().return.quantitynumber | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.fill.fill().return.reasonimport('@insiderfinance/totalfinance/backtest/execution').UnfilledReason | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.fill.fill().return.referencestring | Which price the fill referenced — `bar.open`, `bar.touch:limit`, `quote.ask`, `book.levels`, … unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.fill.fill(request)import('@insiderfinance/totalfinance/backtest/execution').FillRequest | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.fill.fill(request).contextimport('@insiderfinance/totalfinance/backtest/execution').FillContext | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.fill.fill(request).observationimport('@insiderfinance/totalfinance/backtest/execution').MarketObservation | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.fill.fill(request).orderimport('@insiderfinance/totalfinance/backtest/execution').OrderIntent | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.fill.labelstring | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.fill.observation'quote' | 'bar' | 'trade' | 'order-book' | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.fill.versionstring | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.labelstring | Echoed in every result's assumptions. unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.lockedCrossedimport('@insiderfinance/totalfinance/backtest/execution').LockedCrossedPolicy | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.marginimport('@insiderfinance/totalfinance/backtest/execution').MarginPolicy | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.margin.buyingPowerMultipliernumber | Gross notional an account may hold per unit of equity (1 = cash account). decimal fraction / multiple | Required / declared member No @default declared; consult the signature and description. |
execution.margin.forcedLiquidationimport('@insiderfinance/totalfinance/backtest/execution').ForcedLiquidationPolicy | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.margin.initialMarginRatenumber | Fraction of a new position's notional that must be equity at entry. decimal rate (0.05 = 5%) | Required / declared member No @default declared; consult the signature and description. |
execution.margin.maintenanceMarginRatenumber | Fraction of gross notional that must remain equity after every fold. decimal rate (0.05 = 5%) | Required / declared member No @default declared; consult the signature and description. |
execution.observation'quote' | 'bar' | 'trade' | 'order-book' | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.partialFillsimport('@insiderfinance/totalfinance/backtest/execution').PartialFillPolicy | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.queue{ model: import('@insiderfinance/totalfinance/backtest/execution').QueueModel; } | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.queue.modelimport('@insiderfinance/totalfinance/backtest/execution').QueueModel | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.realism'simplified' | 'declared' | `simplified` is the default and says so; `declared` means the caller named every member. unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.sessionsimport('@insiderfinance/totalfinance/backtest/execution').SessionRules | unitless by name | Optional No @default declared; consult the signature and description. |
execution.sessions.auction'ignore' | 'open-close-only' | How auction-only order types are treated by a model that has no auction: declared, never assumed. unitless by name | Optional No @default declared; consult the signature and description. |
execution.sessions.haltsreadonly import('@insiderfinance/totalfinance/backtest/execution').HaltWindow[] | unitless by name | Optional No @default declared; consult the signature and description. |
execution.sessions.priceLimitsreadonly import('@insiderfinance/totalfinance/backtest/execution').PriceLimitWindow[] | unitless by name | Optional No @default declared; consult the signature and description. |
execution.staleQuotesimport('@insiderfinance/totalfinance/backtest/execution').StaleQuotePolicy | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.staleQuotes.behavior'reject' | 'fill-at-last' | `reject` refuses the run (`backtest.stale_quote`); `fill-at-last` fills at the stale quote and reports it. unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.staleQuotes.maximumAgeMsnumber | null | A quote older than this at the decision instant is stale; `null` = never stale. milliseconds | Required / declared member No @default declared; consult the signature and description. |
execution.timeInForce{ default: TimeInForce; expireAtSessionClose: boolean; } | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.timeInForce.defaultTimeInForce | unitless by name | Required / declared member No @default declared; consult the signature and description. |
execution.timeInForce.expireAtSessionCloseboolean | unitless by name | Required / declared member No @default declared; consult the signature and description. |
externalFlowsreadonly import('@insiderfinance/totalfinance/backtest/portfolio').ExternalFlowRecord[] | unitless by name | Optional No @default declared; consult the signature and description. |
featuresFeatureRecipes | unitless by name | Optional No @default declared; consult the signature and description. |
features.drawdownboolean | 1 − close ÷ running peak close, per instrument. unitless by name | Optional No @default declared; consult the signature and description. |
features.lookbackReturnsreadonly number[] | Close-to-close returns over each lookback in bars. unitless by name | Optional No @default declared; consult the signature and description. |
features.realizedVolatility{ annualization: number; lookbacks: readonly number[]; } | Standard deviation of log returns over each lookback in bars, scaled by √annualization —
the bars per year (252 daily, 52 weekly, 12 monthly) or `1` for the per-bar σ. Required: the
environment never assumes the bar frequency. unitless by name | Optional No @default declared; consult the signature and description. |
features.realizedVolatility.annualizationnumber | unitless by name | Required / declared member No @default declared; consult the signature and description. |
features.realizedVolatility.lookbacksreadonly number[] | unitless by name | Required / declared member No @default declared; consult the signature and description. |
instrumentsReadonly<Record<string, InstrumentSpecification>> | unitless by name | Required / declared member No @default declared; consult the signature and description. |
limitsEnvironmentLimits | unitless by name | Optional No @default declared; consult the signature and description. |
limits.allowUndefinedRiskOptionsboolean | Default false: a sell that leaves an option position net short (and, for a call, uncovered) is disallowed. unitless by name | Optional No @default declared; consult the signature and description. |
limits.maximumDailyLossnumber | Maximum one-evaluation NAV loss (decimal of the prior NAV). unitless by name | Optional No @default declared; consult the signature and description. |
limits.maximumDaysToLiquidatenumber | Maximum days to liquidate any position at the supplied participation rate. unitless by name | Optional No @default declared; consult the signature and description. |
limits.maximumDrawdownnumber | Maximum peak-to-trough drawdown of NAV (decimal). unitless by name | Optional No @default declared; consult the signature and description. |
limits.maximumGrossLeveragenumber | Maximum gross exposure ÷ NAV (1 = unlevered). unitless by name | Optional No @default declared; consult the signature and description. |
limits.maximumGroupWeightsimport('@insiderfinance/totalfinance/portfolio').GroupWeightLimit[] | unitless by name | Optional No @default declared; consult the signature and description. |
limits.maximumPositionNotionalnumber | Base currency, per instrument: the largest absolute position value an order may project. currency amount (the field or record currency) | Optional No @default declared; consult the signature and description. |
limits.maximumPositionWeightnumber | Maximum absolute weight of any single instrument (decimal of NAV). decimal fraction / multiple | Optional No @default declared; consult the signature and description. |
limits.minimumSettledCashnumber | Minimum settled cash in base currency (a margin/buying-power floor; may be negative). currency amount (the field or record currency) | Optional No @default declared; consult the signature and description. |
limits.onBreach'terminate' | 'reject-and-continue' | What a post-trade breach does: end the episode (default) or record it and continue. unitless by name | Optional No @default declared; consult the signature and description. |
marketDataimport('@insiderfinance/totalfinance/backtest/portfolio').PortfolioMarketData | unitless by name | Required / declared member No @default declared; consult the signature and description. |
marketData.barsreadonly import('@insiderfinance/totalfinance/core').Bar[] | unitless by name | Optional No @default declared; consult the signature and description. |
marketData.corporateActionsreadonly import('@insiderfinance/totalfinance/core').CorporateAction[] | unitless by name | Optional No @default declared; consult the signature and description. |
marketData.couponsreadonly import('@insiderfinance/totalfinance/backtest/portfolio').CouponRecord[] | unitless by name | Optional No @default declared; consult the signature and description. |
marketData.dividendsreadonly import('@insiderfinance/totalfinance/backtest/portfolio').DividendRecord[] | unitless by name | Optional No @default declared; consult the signature and description. |
marketData.forwardRatesreadonly import('@insiderfinance/totalfinance/backtest/portfolio').ForwardRateRecord[] | Forward-rate series per fx-forward instrument. unitless by name | Optional No @default declared; consult the signature and description. |
marketData.fundingRatesreadonly import('@insiderfinance/totalfinance/backtest/portfolio').FundingRateRecord[] | unitless by name | Optional No @default declared; consult the signature and description. |
marketData.fxRatesreadonly import('@insiderfinance/totalfinance/backtest/portfolio').DatedCurrencyPairQuote[] | Dated quotes to the base currency; REQUIRED when any instrument's currency ≠ baseCurrency. unitless by name | Optional No @default declared; consult the signature and description. |
marketData.optionChainsreadonly import('@insiderfinance/totalfinance/backtest/options').ChainSnapshot[] | unitless by name | Optional No @default declared; consult the signature and description. |
marketData.orderBooksreadonly import('@insiderfinance/totalfinance/core').OrderBook[] | unitless by name | Optional No @default declared; consult the signature and description. |
marketData.quotesreadonly import('@insiderfinance/totalfinance/core').Quote[] | unitless by name | Optional No @default declared; consult the signature and description. |
marketData.tradesreadonly import('@insiderfinance/totalfinance/core').Trade[] | unitless by name | Optional No @default declared; consult the signature and description. |
maximumStepsnumber | The most steps an episode takes before `truncated` (default: the instant count; ceiling 100,000). unitless by name | Optional No @default declared; consult the signature and description. |
periodsPerYearnumber | per year (count) | Optional No @default declared; consult the signature and description. |
rewardRewardComposition | unitless by name | Optional No @default declared; consult the signature and description. |
reward.benchmark{ instrumentId: string; weight: number; } | On the step return minus the named instrument's bar return over the step. unitless by name | Optional No @default declared; consult the signature and description. |
reward.benchmark.instrumentIdstring | unitless by name | Required / declared member No @default declared; consult the signature and description. |
reward.benchmark.weightnumber | unitless by name | Required / declared member No @default declared; consult the signature and description. |
reward.concentrationnumber | On the largest absolute position weight after the step. unitless by name | Optional No @default declared; consult the signature and description. |
reward.costnumber | On commissions, fees, and slippage ÷ NAV before the step. unitless by name | Optional No @default declared; consult the signature and description. |
reward.drawdownnumber | On the INCREASE in drawdown from the episode's running peak (a recovery pays 0). unitless by name | Optional No @default declared; consult the signature and description. |
reward.goal(frame: RewardFrame) => Record<string, number> | Extra named terms (weight 1 each); a callback, so the definition is not replayable. unitless by name | Optional No @default declared; consult the signature and description. |
reward.goal(frame)RewardFrame | unitless by name | Required / declared member No @default declared; consult the signature and description. |
reward.goal(frame).asOfnumber | an instant: epoch milliseconds or a YYYY-MM-DD / zoned ISO string (the resolveAsOf convention) | Required / declared member No @default declared; consult the signature and description. |
reward.goal(frame).benchmarkReturnnumber | null | The benchmark instrument's bar-close return over the step, or null without two closes. unitless by name | Required / declared member No @default declared; consult the signature and description. |
reward.goal(frame).costsnumber | Σ commission + fees + slippage adjustment of the step's fills, base currency. unitless by name | Required / declared member No @default declared; consult the signature and description. |
reward.goal(frame).drawdownAfternumber | unitless by name | Required / declared member No @default declared; consult the signature and description. |
reward.goal(frame).drawdownBeforenumber | 1 − NAV ÷ running peak, before and after the step. unitless by name | Required / declared member No @default declared; consult the signature and description. |
reward.goal(frame).fillsreadonly NormalizedFill[] | unitless by name | Required / declared member No @default declared; consult the signature and description. |
reward.goal(frame).grossExposurenumber | unitless by name | Required / declared member No @default declared; consult the signature and description. |
reward.goal(frame).largestPositionWeightnumber | decimal fraction / multiple | Required / declared member No @default declared; consult the signature and description. |
reward.goal(frame).netAssetValueAfternumber | unitless by name | Required / declared member No @default declared; consult the signature and description. |
reward.goal(frame).netAssetValueBeforenumber | unitless by name | Required / declared member No @default declared; consult the signature and description. |
reward.goal(frame).positionsreadonly SessionPosition[] | unitless by name | Required / declared member No @default declared; consult the signature and description. |
reward.goal(frame).stepnumber | unitless by name | Required / declared member No @default declared; consult the signature and description. |
reward.goal(frame).stepReturnnumber | Δ NAV ÷ NAV before the step (0 when the NAV before was not positive). unitless by name | Required / declared member No @default declared; consult the signature and description. |
reward.goal(frame).tradedNotionalnumber | Σ |quantity × price × multiplier| of the step's fills, base currency. currency amount (the field or record currency) | Required / declared member No @default declared; consult the signature and description. |
reward.goal(frame).violationsnumber | Limit breaches plus disallowed orders in the step. unitless by name | Required / declared member No @default declared; consult the signature and description. |
reward.leveragenumber | On gross exposure ÷ NAV after the step. unitless by name | Optional No @default declared; consult the signature and description. |
reward.pnlnumber | On the step's net return, Δ NAV ÷ NAV before the step. unitless by name | Optional No @default declared; consult the signature and description. |
reward.riskViolationnumber | On the count of limit breaches and disallowed orders in the step. unitless by name | Optional No @default declared; consult the signature and description. |
reward.turnovernumber | On traded notional ÷ NAV before the step. unitless by name | Optional No @default declared; consult the signature and description. |
seednumber | Seeds only the bootstrap confidence intervals. unitless by name | Optional No @default declared; consult the signature and description. |
window{ fromTimestampMs?: EpochMs; toTimestampMs?: EpochMs; } | unitless by name | Optional No @default declared; consult the signature and description. |
window.fromTimestampMsnumber | epoch milliseconds (UTC instant) | Optional No @default declared; consult the signature and description. |
window.toTimestampMsnumber | epoch milliseconds (UTC instant) | Optional No @default declared; consult the signature and description. |
Stability, warnings & conventions
stable-by-law (pre-1.0; not a 1.0 stability guarantee)
Declared field units are shown above. “Unitless by name” means the name alone does not establish a unit, not that a financial quantity has none. Check source descriptions, conventions, and the returned diagnostics. Errors and warnings are part of the result contract.