Skip to content

ENH: Support time-varying bid-ask spreads - #1393

Open
AtomicGlance wants to merge 1 commit into
kernc:masterfrom
AtomicGlance:codex/1300-time-varying-spread
Open

ENH: Support time-varying bid-ask spreads#1393
AtomicGlance wants to merge 1 commit into
kernc:masterfrom
AtomicGlance:codex/1300-time-varying-spread

Conversation

@AtomicGlance

Copy link
Copy Markdown

Summary

Fixes #1300.

Backtest(..., spread=...) now accepts either the existing scalar rate or a one-dimensional per-bar array-like value. A pandas Series must use the same index as the OHLC data. Values are validated as finite, numeric, and non-negative, and are applied at the bar where an order is filled. Scalar spreads keep the existing execution path and results.

The spread remains a relative rate, consistent with the current API. Data-source spreads expressed in price units can be converted to rates before passing them to Backtest.

Tests

  • scalar and constant Series spreads produce identical trades and equity curves
  • variable spreads affect market, limit, and stop fills at the fill bar
  • long and short fills use the correct direction
  • invalid length, shape, type, index, NaN, infinite, and negative values are rejected
  • full backtesting/test/_test.py suite: 83 passed, 1 skipped

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spread is Float but spread is typically different per row of the OHLC dataframe

1 participant