Predictor¶
- class hokohoko.entities.Predictor(lock, parameters=None)¶
Bases:
Random
Defines the interface for a Predictor, and provides routines for order management.
- Parameters
lock (multiprocessing.Lock) – A single lock shared by all Predictors in each Period for this invocation. Stored in
self.lock
.parameters (str) – The parameters passed in from
hokohoko.entities.Config
. Stored inself.parameters
.
Other Attributes:
symbol_ids [numpy.ndarray] The list of symbols available in the data source. account [hokohoko.entities.Account] The internal account keeping track of state.
Deterministic RNG:
In order that successive runs of Hokohoko with identical settings and data generate the exact same results, the Predictor class inherits from
random.Random
to provide a fully deterministic RNG. For any specific minute within the dataset, the generated random number sequence should be identical.The RNG should typically be accessed via
self.random()
orself.randint()
.See random for additional methods.
- __init__(lock, parameters=None)¶
- Parameters
lock (multiprocessing.Lock) – A single lock shared by all Predictors in each Period for this invocation. Stored in
self.lock
.parameters (str) – The parameters passed in from
hokohoko.entities.Config
. Stored inself.parameters
.
Other Attributes:
symbol_ids [numpy.ndarray] The list of symbols available in the data source. account [hokohoko.entities.Account] The internal account keeping track of state.
Deterministic RNG:
In order that successive runs of Hokohoko with identical settings and data generate the exact same results, the Predictor class inherits from
random.Random
to provide a fully deterministic RNG. For any specific minute within the dataset, the generated random number sequence should be identical.The RNG should typically be accessed via
self.random()
orself.randint()
.See random for additional methods.
- __enter__()¶
Any state required for the predictor should be setup in here, e.g., external data sources.
- Returns
As per with specification,
self
.- Return type
Important
This must be overridden.
- __exit__(exc_type, exc_val, exc_tb)¶
Clean up the predictor state, close and release handles, etc.
Important
This must be overridden.
- on_start(bars)¶
This is called when the predictor is first loaded. The order of the symbols within the list doesn’t change for the duration of the test.
- Parameters
bars (list[hokohoko.entities.Bar]) – A bar containing the closing values of the bar prior to the Period the Predictor is running.
Important
This must be overridden.
- on_bar(bars)¶
This is called at the end of every bar, and is where the majority of a Predictor’s work takes place. During this method, Orders and Positions can be requested closed, and Orders can be placed, but none are actioned until after this routine exits. Upon exit,
close_order
requests are handled first, thenplace_order[s]
.on_bar
is considered to happen between the end of one bar, and the start of the next.- Parameters
bars (list[hokohoko.entities.Bar]) – The latest bar in the data.
Important
This must be overridden.
- on_stop()¶
This is called at the end of each period. It may be overridden, otherwise does nothing.
- place_order(order)¶
Place a single Order into the market.
- Parameters
order (hokohoko.entities.Order) – The desired Order.
- place_orders(orders)¶
Place a collection of Orders into the market.
- Parameters
orders (list[hokohoko.entities.Order]) – A list of Orders to add to the orders stack.