Market#

This page gives an overview of all public classes for interacting with a market view in backtest_lib

class backtest_lib.MarketView(prices: PastUniversePrices[Index] | PastView[float, Index] | Any, tradable: PastView[int, Index] | Any | None = None, volume: PastView[int, Index] | Any | None = None, signals: dict[str, PastView[Any, Index] | Any] | None = None, security_policy: SecurityAxisPolicy = SecurityAxisPolicy.STRICT, period_policy: PeriodAxisPolicy = PeriodAxisPolicy.STRICT, reference_view_for_axis_values: str = 'prices', backend: str = 'polars')#

Holds a common set of signals for backtesting, as well as any custom signals defined by the user.

Provides a mechanism for aligning, and enforcing the alignment of the PastView for each signal.

Type parameters:

Index: A type that is comparable with itself. This will commonly be a datetime-like type such as np.datetime64. This constraint allows us to enforce monotonicity on the market periods.

Parameters:
  • prices – A PastUniversePrices structure that holds close, open, high, and low prices for each period. Each price view is represented by a PastView. All price views except for close are optional.

  • tradable – An optional PastView of tradability over the periods and securities of the reference view. volume: An optional PastView of volume over the periods and securities of the reference view.

  • signals – An optional mapping from str to any custom PastView specified by the user.

  • security_policy – A SecurityAxisPolicy determining how missing or misaligned securities are treated in the construction of the MarketView.

  • period_policy – A PeriodAxisPolicy determining how missing periods are treated in the construction of the MarketView.

  • reference_view_for_axis_values

    The PastView of this market view used as a reference for the securities and periods for the market view as a whole. For example, when the reference view is “volume”, a security or period in any other PastView (“tradable”, “prices.close”, etc.) PastView not found in the “volume” PastView will be counted as missing and will trigger an exception when the associated axis policy is set to STRICT.

    The reference view can be specified as an value of “signals” by passing “signal:<SIGNAL_NAME>” as the reference i.e “signal:carry” for a signal named “carry”.

  • backend – See backtest_lib.Backtest._backend.

periods#

The periods of the reference view. A Sequence of Index (See Type parameters).

securities#

The securities of the reference view. A Sequence of str.