Config
Backtest
parse_filters_expr(s: str | None)
Parse a pyarrow.dataset filter expression from a string.
>>> parse_filters_expr('field("Currency") == "CHF"')
<pyarrow.dataset.Expression (Currency == "CHF")>
>>> parse_filters_expr("print('hello')")
>>> parse_filters_expr("None")
class BacktestVenueConfig
Bases:
PoseiConfig
Represents a venue configuration for one specific backtest engine.
-
Parameters:
- name (str) – The name of the venue.
-
oms_type (str) –
The order management system type for the
exchange. If
HEDGING
will generate new position IDs. - account_type (str) – The account type for the exchange.
- starting_balances (list [Money | str ]) – The starting account balances (specify one for a single asset account).
-
base_currency (Currency
| str ,
optional) – The account base
currency for the exchange. Use
None
for multi-currency accounts. - default_leverage (float , optional) – The account default leverage (for margin accounts).
- leverages (dict *[*str , float ] , optional) – The instrument specific leverage configuration (for margin accounts).
- book_type (str) – The default order book type.
- routing (bool , default False) – If multi-venue routing should be enabled for the execution client.
- frozen_account (bool , default False) – If the account for this exchange is frozen (balances will not change).
- reject_stop_orders (bool , default True) – If stop orders are rejected on submission if trigger price is in the market.
- support_gtd_orders (bool , default True) – If orders with GTD time in force will be supported by the venue.
- support_contingent_orders (bool , default True) – If contingent orders will be supported/respected by the venue. If False, then it’s expected the strategy will be managing any contingent orders.
- use_position_ids (bool , default True) – If venue position IDs will be generated on order fills.
- use_random_ids (bool , default False) – If all venue generated identifiers will be random UUID4’s.
- use_reduce_only (bool , default True) – If the reduce_only execution instruction on orders will be honored.
- bar_execution (bool , default True) – If bars should be processed by the matching engine(s) (and move the market).
-
bar_adaptive_high_low_ordering
(bool ,
default False) – Determines whether
the processing order of bar prices is
adaptive based on a heuristic. This setting
is only relevant when bar_execution is True.
If False, bar prices are always processed in
the fixed order: Open, High, Low, Close. If
True, the processing order adapts with the
heuristic:
- If High is closer to Open than Low then the processing order is Open, High, Low, Close.
- If Low is closer to Open than High then the processing order is Open, Low, High, Close.
- trade_execution (bool , default False) – If trades should be processed by the matching engine(s) (and move the market).
- modules (list [ImportableActorConfig ] , optional) – The simulation modules for the venue.
- fill_model (ImportableFillModelConfig , optional) – The fill model for the venue.
- latency_model (ImportableLatencyModelConfig , optional) – The latency model for the venue.
- fee_model (ImportableFeeModelConfig , optional) – The fee model for the venue.
name : str
oms_type : str
account_type : str
starting_balances : list[str]
base_currency : str | None
default_leverage : float
leverages : dict[str, float] | None
book_type : str
routing : bool
frozen_account : bool
reject_stop_orders : bool
support_gtd_orders : bool
support_contingent_orders : bool
use_position_ids : bool
use_random_ids : bool
use_reduce_only : bool
bar_execution : bool
bar_adaptive_high_low_ordering : bool
trade_execution : bool
modules : list[ImportableActorConfig] | None
fill_model : ImportableFillModelConfig | None
latency_model : ImportableLatencyModelConfig | None
fee_model : ImportableFeeModelConfig | None
dict() → dict[str, Any]
Return a dictionary representation of the configuration.
- Return type: dict[str, Any]
classmethod fully_qualified_name() → str
Return the fully qualified name for the PoseiConfig class.
- Return type: str
property id : str
Return the hashed identifier for the configuration.
- Return type: str
json() → bytes
Return serialized JSON encoded bytes.
- Return type: bytes
json_primitives() → dict[str, Any]
Return a dictionary representation of the configuration with JSON primitive types as values.
- Return type: dict[str, Any]
classmethod json_schema() → dict[str, Any]
Generate a JSON schema for this configuration class.
- Return type: dict[str, Any]
classmethod parse(raw: bytes | str) → Any
Return a decoded object of the given cls.
-
Parameters:
- cls (type) – The type to decode to.
- raw (bytes or str) – The raw bytes or JSON string to decode.
- Return type: Any
validate() → bool
Return whether the configuration can be represented as valid JSON.
- Return type: bool
class BacktestDataConfig
Bases:
PoseiConfig
Represents the data configuration for one specific backtest run.
-
Parameters:
- catalog_path (str) – The path to the data catalog.
- data_cls (str) – The data type for the configuration.
- catalog_fs_protocol (str , optional) – The fsspec filesystem protocol for the catalog.
- catalog_fs_storage_options (dict , optional) – The fsspec storage options.
- instrument_id (InstrumentId | str , optional) – The instrument ID for the data configuration.
- start_time (str or int , optional) – The start time for the data configuration. Can be an ISO 8601 format datetime string, or UNIX nanoseconds integer.
- end_time (str or int , optional) – The end time for the data configuration. Can be an ISO 8601 format datetime string, or UNIX nanoseconds integer.
- filter_expr (str , optional) – The additional filter expressions for the data catalog query.
- client_id (str , optional) – The client ID for the data configuration.
- metadata (dict , optional) – The metadata for the data catalog query.
- bar_spec (BarSpecification | str , optional) – The bar specification for the data catalog query.
- instrument_ids (list [InstrumentId | str ] , optional) – The instrument IDs for the data catalog query. Can be used if instrument_id is not specified. If bar_spec is specified an equivalent list of bar_types will be constructed.
- bar_types (list [BarType | str ] , optional) – The bar types for the data catalog query. Can be used if instrument_id is not specified.
catalog_path : str
data_cls : str
catalog_fs_protocol : str | None
catalog_fs_storage_options : dict | None
instrument_id : InstrumentId | None
start_time : str | int | None
end_time : str | int | None
filter_expr : str | None
client_id : str | None
metadata : dict | None
bar_spec : str | None
instrument_ids : list[str] | None
bar_types : list[str] | None
property data_type : type
Return a type for the specified data_cls for the configuration.
- Return type: type
property query : dict[str, Any]
Return a catalog query object for the configuration.
- Return type: dict[str, Any]
property start_time_nanos : int
Return the data configuration start time in UNIX nanoseconds.
Will be zero if no start_time was specified.
- Return type: int
property end_time_nanos : int
Return the data configuration end time in UNIX nanoseconds.
Will be sys.maxsize if no end_time was specified.
- Return type: int
dict() → dict[str, Any]
Return a dictionary representation of the configuration.
- Return type: dict[str, Any]
classmethod fully_qualified_name() → str
Return the fully qualified name for the PoseiConfig class.
- Return type: str
property id : str
Return the hashed identifier for the configuration.
- Return type: str
json() → bytes
Return serialized JSON encoded bytes.
- Return type: bytes
json_primitives() → dict[str, Any]
Return a dictionary representation of the configuration with JSON primitive types as values.
- Return type: dict[str, Any]
classmethod json_schema() → dict[str, Any]
Generate a JSON schema for this configuration class.
- Return type: dict[str, Any]
classmethod parse(raw: bytes | str) → Any
Return a decoded object of the given cls.
-
Parameters:
- cls (type) – The type to decode to.
- raw (bytes or str) – The raw bytes or JSON string to decode.
- Return type: Any
validate() → bool
Return whether the configuration can be represented as valid JSON.
- Return type: bool
class BacktestEngineConfig
Bases:
PoseiKernelConfig
Configuration for
BacktestEngine
instances.
-
Parameters:
- trader_id (TraderId) – The trader ID for the node (must be a name and ID tag separated by a hyphen).
- log_level (str , default "INFO") – The stdout log level for the node.
- loop_debug (bool , default False) – If the asyncio event loop should be in debug mode.
- cache (CacheConfig , optional) – The cache configuration.
- data_engine (DataEngineConfig , optional) – The live data engine configuration.
- risk_engine (RiskEngineConfig , optional) – The live risk engine configuration.
- exec_engine (ExecEngineConfig , optional) – The live execution engine configuration.
- streaming (StreamingConfig , optional) – The configuration for streaming to feather files.
- strategies (list [ImportableStrategyConfig ]) – The strategy configurations for the kernel.
- actors (list [ImportableActorConfig ]) – The actor configurations for the kernel.
- exec_algorithms (list [ImportableExecAlgorithmConfig ]) – The execution algorithm configurations for the kernel.
- controller (ImportableControllerConfig , optional) – The trader controller for the kernel.
- load_state (bool , default True) – If trading strategy state should be loaded from the database on start.
- save_state (bool , default True) – If trading strategy state should be saved to the database on stop.
- bypass_logging (bool , default False) – If logging should be bypassed.
- run_analysis (bool , default True) – If post backtest performance analysis should be run.
environment : Environment
trader_id : TraderId
data_engine : DataEngineConfig
risk_engine : RiskEngineConfig
exec_engine : ExecEngineConfig
run_analysis : bool
actors : list[ImportableActorConfig]
cache : CacheConfig | None
catalogs : list[DataCatalogConfig]
controller : ImportableControllerConfig | None
dict() → dict[str, Any]
Return a dictionary representation of the configuration.
- Return type: dict[str, Any]
emulator : OrderEmulatorConfig | None
exec_algorithms : list[ImportableExecAlgorithmConfig]
classmethod fully_qualified_name() → str
Return the fully qualified name for the PoseiConfig class.
- Return type: str
property id : str
Return the hashed identifier for the configuration.
- Return type: str
instance_id : UUID4 | None
json() → bytes
Return serialized JSON encoded bytes.
- Return type: bytes
json_primitives() → dict[str, Any]
Return a dictionary representation of the configuration with JSON primitive types as values.
- Return type: dict[str, Any]
classmethod json_schema() → dict[str, Any]
Generate a JSON schema for this configuration class.
- Return type: dict[str, Any]
load_state : bool
logging : LoggingConfig | None
loop_debug : bool
message_bus : MessageBusConfig | None
classmethod parse(raw: bytes | str) → Any
Return a decoded object of the given cls.
-
Parameters:
- cls (type) – The type to decode to.
- raw (bytes or str) – The raw bytes or JSON string to decode.
- Return type: Any
portfolio : PortfolioConfig | None
save_state : bool
strategies : list[ImportableStrategyConfig]
streaming : StreamingConfig | None
timeout_connection : PositiveFloat
timeout_disconnection : PositiveFloat
timeout_portfolio : PositiveFloat
timeout_post_stop : PositiveFloat
timeout_reconciliation : PositiveFloat
timeout_shutdown : PositiveFloat
validate() → bool
Return whether the configuration can be represented as valid JSON.
- Return type: bool
class BacktestRunConfig
Bases:
PoseiConfig
Represents the configuration for one specific backtest run.
This includes a backtest engine with its actors and strategies, with the external inputs of venues and data.
-
Parameters:
- venues (list [BacktestVenueConfig ]) – The venue configurations for the backtest run.
- data (list [BacktestDataConfig ]) – The data configurations for the backtest run.
- engine (BacktestEngineConfig) – The backtest engine configuration (the core system kernel).
- chunk_size (int , optional) – The number of data points to process in each chunk during streaming mode. If None, the backtest will run without streaming, loading all data at once.
- raise_exception (bool , default False) – If exceptions during an engine build or run should be raised to interrupt the nodes process.
- dispose_on_completion (bool , default True) – If the backtest engine should be disposed on completion of the run. If True, then will drop data and all state. If False, then will only drop data.
-
start (datetime
or str or
int , optional) –
The start datetime (UTC) for the backtest
run. If
None
engine runs from the start of the data. -
end (datetime
or str or
int , optional) –
The end datetime (UTC) for the backtest run.
If
None
engine runs to the end of the data.
venues : list[BacktestVenueConfig]
data : list[BacktestDataConfig]
engine : BacktestEngineConfig | None
chunk_size : int | None
raise_exception : bool
dispose_on_completion : bool
start : str | int | None
end : str | int | None
dict() → dict[str, Any]
Return a dictionary representation of the configuration.
- Return type: dict[str, Any]
classmethod fully_qualified_name() → str
Return the fully qualified name for the PoseiConfig class.
- Return type: str
property id : str
Return the hashed identifier for the configuration.
- Return type: str
json() → bytes
Return serialized JSON encoded bytes.
- Return type: bytes
json_primitives() → dict[str, Any]
Return a dictionary representation of the configuration with JSON primitive types as values.
- Return type: dict[str, Any]
classmethod json_schema() → dict[str, Any]
Generate a JSON schema for this configuration class.
- Return type: dict[str, Any]
classmethod parse(raw: bytes | str) → Any
Return a decoded object of the given cls.
-
Parameters:
- cls (type) – The type to decode to.
- raw (bytes or str) – The raw bytes or JSON string to decode.
- Return type: Any
validate() → bool
Return whether the configuration can be represented as valid JSON.
- Return type: bool
class SimulationModuleConfig
Bases:
ActorConfig
Configuration for
SimulationModule
instances.
component_id : ComponentId | None
dict() → dict[str, Any]
Return a dictionary representation of the configuration.
- Return type: dict[str, Any]
classmethod fully_qualified_name() → str
Return the fully qualified name for the PoseiConfig class.
- Return type: str