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
PastViewfor 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
PastUniversePricesstructure that holds close, open, high, and low prices for each period. Each price view is represented by aPastView. All price views except for close are optional.tradable – An optional
PastViewof tradability over the periods and securities of the reference view. volume: An optionalPastViewof volume over the periods and securities of the reference view.signals – An optional mapping from
strto any customPastViewspecified by the user.security_policy – A
SecurityAxisPolicydetermining how missing or misaligned securities are treated in the construction of theMarketView.period_policy – A
PeriodAxisPolicydetermining how missing periods are treated in the construction of theMarketView.reference_view_for_axis_values –
The
PastViewof 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 otherPastView(“tradable”, “prices.close”, etc.)PastViewnot found in the “volume”PastViewwill be counted as missing and will trigger an exception when the associated axis policy is set toSTRICT.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.