Skip to content
All library documents

Designing Flexible-Horizon Labels for Trading Models

Article Quant Q&A · Author: SuperCodeBrah

Summary

The author considers how to assign training targets to a machine-learning trading model that can choose entries and exits at variable horizons. The proposed workflow separates input features, a value assigned to each market moment, and the trading rules that turn model output into positions. Instead of forcing every example into a fixed holding period, the target might represent potential profit associated with future price swings or pivot points.

Two candidate labeling ideas are discussed: measuring the move between detected turning points, and weighting future prices with a time-decaying curve. The author reports that pivot-based values can jump sharply when a peak is reached, while the time-weighted approach has shown some promise but may be too rigid. A blended target could emphasize turning points while discounting peaks where prices do not remain stable. These are exploratory proposals rather than validated methods; the document gives no dataset, performance results, or procedure for avoiding look-ahead bias when defining future pivots.

Key ideas

  • Training targets can encode the value of a market moment separately from features and trading rules.
  • Variable-horizon labels may avoid imposing a fixed trade duration on a model.
  • Pivot-based targets capture swing opportunities but can change discontinuously around turning points.
  • Time-decaying weights offer a flexible target idea but may impose an arbitrary preferred horizon.
  • The proposed blended labels are unvalidated and require careful treatment of future information.

Tags

Full text
# Machine learning - assigning a value to each tradable moment


# Machine learning - assigning a value to each tradable moment












I've been looking at machine learning trading strategies for some time and realized recently that I've been neglecting a very important part of the equation in terms of training an effective model.

In reading about other machine learning strategies, I've noticed that most strategies revolve around trading in and out at fixed durations, which 1) doesn't really reflect "real" trading and 2) probably makes finding a profitable strategy more difficult by imposing unnecessary time constraints.

For a model that more flexibly determines entries and exits (similar to a human trader), my thoughts are that the process can be broken down into three parts:

- Determining input data: Recent prices, indicator values, etc.

- Assigning a value at each point in time: This would be an attempt to distill future price movements down to a single value or a small number of values. For example, a value of 0.01 might imply that a 1% profit can be obtained by buying at a given point in time.

- Determining trading rules given a trained model: This could include whether to use a stop loss, whether to rely on continuous model outputs or only use the model to determine the trade entry with a defined set of rules after the trade is opened, etc.

My focus has mainly been in #1, but I'm starting to think that #2 should be the starting point.

To illustrate an example, the value of the market at the first `X` below could be defined as the vertical distance between it and the second `X` since that's the maximum amount that could made on that trade given a threshold for determining swings and pivot points.

I've tried something like this but it struggles, I think because of the fact that the assigned value is not smooth and jumps when the peak is reached (i.e., the value changes from the distance from the current price to the peak, a small positive number, to the distance between the peak and the next trough, which would be a large negative number).

Another method I've tried is to assign a weighting to a forward looking range using a lognormal curve:

The idea is that a certain number of periods in the future is prioritized (i.e., the highest point in the curve - just above 2 in this example but realistically it would be something like 10+ if trying to trade with 1m bars) and the value assigned to each bar decreases over time after the peak. This actually does appear to work to a degree, but I don't think it's quite flexible enough.

I'd like to be able to combine the two approaches so that larger weightings are assigned to areas around peaks and troughs rather than at a fixed future point. Here's a rough example of what I mean, where each `X` represents a pivot point and the red line would represent the weights assigned at various points in time.

The idea is to prioritize peaks/troughs as these are opportunities to profit but assign greater values to pivot points where price stays near the point rather than a quick reversion. So in this example, even though the second `X` marking the peak is well above the first `X` and therefore shows large maximum gain potential, the price was not very stable around that point so the value assigned to the upswing would be discounted somewhat. By comparion, the first and last `X` are slightly more stable in that price spends more time around those points, which might imply a higher probability of profitably exiting short trades.

This is very open-ended and just one approach, but I would be curious to hear if anyone else has tried to address the question of assigning value for a flexible duration ML strategy. This is potentially unique to the ML problem since rule based strategies presumably don't go through a training process, but given the numerous articles out there about ML trading, it seems like a hugely undervalued aspect of building a successful strategy.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.