mlfinlab.labeling.trend_scanning

Implementation of Trend-Scanning labels described in Advances in Financial Machine Learning: Lecture 3/10

Module Contents

Functions

trend_scanning_labels(→ pandas.DataFrame)

Trend scanning is both a classification and

trend_scanning_labels(price_series: pandas.Series, t_events: list = None, observation_window: int = 20, metric: str = 't_value', look_forward: bool = True, min_sample_length: int = 5, step: int = 1) pandas.DataFrame

Trend scanning is both a classification and regression labeling technique.

That can be used in the following ways:

  1. Classification: By taking the sign of t-value for a given observation we can set {-1, 1} labels to define the trends as either downward or upward.

  2. Classification: By adding a minimum t-value threshold you can generate {-1, 0, 1} labels for downward, no-trend, upward.

  3. The t-values can be used as sample weights in classification problems.

  4. Regression: The t-values can be used in a regression setting to determine the magnitude of the trend.

The output of this algorithm is a DataFrame with t1 (time stamp for the farthest observation), t-value, returns for the trend, and bin.

This function allows using both forward-looking and backward-looking window (use the look_forward parameter).

Parameters:
  • price_series – (pd.Series) Close prices used to label the data set.

  • t_events – (list) Filtered events, array of pd.Timestamps.

  • observation_window – (int) Maximum look forward window used to get the trend value.

  • metric – (str) Metric used to define top-fit regression. Either ‘t_value’, ‘mean_squared_error’ or ‘mean_absolute_error’.

  • look_forward – (bool) True if using a forward-looking window, False if using a backward-looking one.

  • min_sample_length – (int) Minimum sample length used to fit regression.

  • step – (int) Optimal t-value index is searched every ‘step’ indices.

Returns:

(pandas.DataFrame) DataFrame consisting of the columns t1, t-value, ret, bin.

  • Index - (pd.Timestamp) TimeIndex of the labels.

  • t1 - (pd.Timestamp) Label end-time where the observed trend has the highest t-value i.e. end of a strong upward trend (for look forward) and start of a strong downward trend (for look backward).

  • t-value - (float) Sign of t-value represents the direction of the trend. Positive t-value represents upwards trend.

  • ret - (float) Price change percentage from index time to label end time.

  • bin - (int) Binary label value based on sign of price change.