These functions assume that we have many point-wise predictions produced by individual algorithms
for some feature sets for some labels. The purpose of these functions is to post-process all these
point-wise predictions into some aggregated values which are optimized for trade signal generation.
We define two types of functions:
- Producing aggregated signal (continuous or boolean)
- Measuring quality (performance, precision etc.) for the given aggregation parameters over the input data set with certain point-wise predictions
Maybe split these two types of functions. The performance functions belong to simulation and grid-search.
--- OLD ---
GOAL:
Implement parameterized scoring function(s) which could be applied to results of ML predictions
with point-wise predictions, and compute the score, so that we can do grid search for best
interval-score computation parameters.
TODO: function for interval score: how frequently we
- hit an interval (at least one)
- miss an interval (no prediction at all)
- hit non-interval (predict true where it is false at least once)
- miss non-interval (no predictions of true within non-interval)
Our goal is to train best normal model or even several such models which output score (probablity to have top/bottom).
And then we want to apply various aggregation functions to this score or even train (simple) models in an exhaustive way
by maximizing the interval score or at least making better point-wise score
In fact, the ideal score should count
- if there is at least one alarm within an interval
- ignore alarms after the interval (if there was one in the interval)
we ignore alarms after an interval because we assume that anyway we do not have funds - aftershocks which do not influence the strategy
- if there are no alarms at all before the interval because they break the strategy (early start)
The main problem here is to define "before" interval and "after" interval.
There are these rules that can be used to determine the division:
- Constant tolerance: absolute, percentage from the length. Problem is that they can overlap if two intervals are close to each other.
- Between two intervals. We essentially estimate (opposite) extreme point - it is somewhere between these two intervals.
We could also extend this point my turning it to an interval which means estimating the opposite interval
- Using the opposite interval label. We have trend intervals between them.
We distinguish up and down trends before and after any interval for computing score.
Every interval has its own range, the previous range where we do not want to have alarms, and next range where alarms are allowed (provided that we have alarm within interval).
The scoring function for one-sided prediction should take these arguments:
- point-wise score column (top or bottom)
- interval label column (top or bottom)
- opposite interval label column (bottom or top) to determine after/before ranges
- It returns interval-based confusion matrix: how frequently hit and non-hit interval (true area), how frequently hit/non-hit before interval (false area, note that hit after are ignored only if there was hit in true interval)
The scoring function two-sided prediction:
- point-wise score column (two-sided)
- top interval label column
- bottom interval label column
The scoring function for integral performance. It chooses first alarm (relevant for the state) and computes all differences between them.
It is like finding overall profit if we ware trading. Note that here it is important not to miss extremums.
- Assume some initial state (buying or selling). We could even make two passes for two states and find average
- Find next nearest relevant extremum alarm, compute difference (do the trade) or simply mark this point to compute all differences at the end
- Changing the state and find next relevant nearest alarm by adding the difference or marking the timestamp as buy or sell point.
- Finally compute all differences. If we do it for two initial states then find their average.
Maybe compute average performance per time (say, per month or per year) in order to be independent of the time range