SpeculativeAccuracy¶
- class hokohoko.assessors.SpeculativeAccuracy(parameters)¶
Bases:
Assessor
Historically, researchers in foreign exchange prediction have shunned the use of an absolute measure (such as maximum profit possible per trade). Hokohoko aims to change that, with the introduction of a new metric, Speculative Accuracy. This measures how close to maximum profit a position makes from the
OPEN
price, whilst making allowance for trades for which profit was impossible.The logic behind this metric is that, for any given future period of time, the conditions of a taken Position may be met, and thus the Position/prediction is correct. However, it is only maximally correct if its
take_profit
matches the observedHIGH
/LOW
(depending on trade Direction), and thus anything otherwise is only partially correct. We also need to take into account the times where a Position cannot be profitable, and other times when there is no movement in the market.Therefore, given a Position with
\[\begin{equation} result=\lbrace max\_profit \in \mathbb{R}_{\geq 0}, max\_loss \in \mathbb{R}_{\leq 0}, actual\_profit \in \mathbb{R}, taken \in \lbrace 0, 1 \rbrace \rbrace\ \ \ \ (1) \end{equation}\]we define thus
\[\begin{split}\begin{equation} accuracy(result) = \left\{ \begin{array}{@{}rl@{}} \frac{actual\_profit}{max\_profit}, & \text{if}\ max\_profit \gt 0 \\ 1.0, & \text{if}\ max\_profit = 0 \land taken = 0\ \ \ \ (2) \\ \frac{-actual\_profit}{max\_loss}, & \text{if}\ max\_loss \lt 0 \\ 0.0, & \text{otherwise} \end{array}\right. \end{equation}\end{split}\]The astute observer will note that these equations are:
Unbounded to the negative—incorrect predictions are heavily penalised.
Highly optimistic—making a loss for a potential 1 pip profit is very heavily penalised.
Heavily skewed for correct
DONT_BUY
,DONT_SELL
.Not the absolute profit possible, allowing possible results > 100%.
To these, the author notes:
Accepted, no apologies. Make better predictions.
Accepted, still no apologies. As above.
Within the default dataset provided,
¬taken
will only be correct about two percent of the time. The heavy skew is considered acceptable in this scenario (and is logically true).If a predictor can more accurately predict the dips and rises that allow for profits greater than from
OPEN
toHIGH
/LOW
, it deserves the score it gets. Accepted.
This Assessor takes the following options:
--show_results Prints out the list of all given results, which may be piped into a file for further processing.
- Parameters
parameters (str) – The
assessor_parameters
provided via HokohokoConfig.
- analyse(period_results)¶
This is the routine that is called by Hokohoko after initialization. It calculates and collates the provided account data into an overview table.
- Parameters
period_results (Iterable[multiprocessing.pool.AsyncResult[hokohoko.entities.Account]]) – The accounts from benchmarking.
- static calculate_rate_changes(history)¶
Calculates the maximum profit, maximum loss, and actual profit (in pips) for a given Result.
- Parameters
history (hokohoko.entities.Position) – The Position History to analyse.
- Returns
A tuple of the order: max_profit, max_loss, actual_profit. actual_profit may be negative (and therefore a loss).
- Return type
tuple<numpy.float64, numpy.float64, numpy.float64>
- static calculate_accuracy(max_profit, max_loss, actual_profit, status, mode=0, weight=1)¶
Calculates the accuracy measure for the given parameters.
- Parameters
max_profit (float) – The maximum profit possible (
OPEN
toHIGH
/LOW
forBUY
,SELL
respectively), in pips.max_loss (float) – The maximum loss possible (
OPEN
toLOW
/HIGH
forBUY
,SELL
respectively), in pips.actual_profit (float) – The actual profit/loss made, in pips.
status (hokohoko.entities.Status) – The status of the result. Used to check if an order was requested or not.
mode (int) – The type of Speculative Performance metric to use: 0 - Basic SP. 1 - Taking a Position without Profit-potential = -1 2 - Normalises via symlog_10 3 - Normalises via symlog_e 4 - Normalises via tanh 5 - Normalises with the provided weight.
weight (float) – A weigting to normalise the score with.
- Returns
Returns an accuracy score. See Bradley et al for the historical background for this measure.
- Return type
float