Bachelier1900¶
- class hokohoko.predictors.Bachelier1900(lock, args=None, debug=False)¶
Bases:
Predictor
This predictor is based on the paper Théorie de la Spéculation by Louis Bachelier [Bachelier1900], now widely regarded as the first academic attempt at predicting stock market prices through mathematical analysis. His formulae are significantly more complex than the implementation presented here, as he attempted to take into account the spread, as well as predict multiple epochs ahead and how many epochs there might be before a price was expected to eventuate.
Given
\[x_t, x_{t+1}:\ x \in \mathbb{R}\]and
\[\begin{equation} \delta x = x_{t+1} - x_t \end{equation}\]generate two probabilities:
\[P(x_t), P(\delta x)\]From these, we can generate
\[\begin{equation} P(x_{t+2}) = P(x_{t+2}) \times P(x_{t+2} - x_{t+1}) \end{equation}\]Maximise for predicted price.
- 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.
- 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.