Trend Scanning



../_images/trend_scanning_plot.png

Trend Scanning is both a classification and regression labeling technique introduced by Marcos Lopez de Prado in the following lecture slides: Advances in Financial Machine Learning: Lecture 3/10 (seminar slides), and again in his text book Machine Learning for Asset Managers.

trend scanning backward-looking

Result of applying backward-looking Trend scanning to EEM ETF daily close prices. The colour of a point in the plot represents the t-value.

For some trading algorithms, the researcher may not want to explicitly set a fixed profit / stop loss level, but rather detect overall trend direction and sit in a position until the trend changes. For example, market timing strategy which holds ETFs except during volatile periods. Trend scanning labels are designed to solve this type of problems.

This algorithm is also useful for defining market regimes between downtrend, no-trend, and uptrend.

Implementation in the MlFinLab package supports both forward-looking and backward-looking window approaches.

The idea of forward-looking trend-scanning labels are to fit multiple regressions from time t to t + L (L is a maximum observation window) and select the one which yields maximum t-value for the slope coefficient, for a specific observation. For the backward-looking trend-scanning labels the regressions are fit from time t to t - L.

Tip

  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. The user can also specify MAE/MSE metric used to define best-fit linear regression by change the value of metric parameter in the function call.

Note

Underlying Literature

The following sources elaborate extensively on the topic:


Implementation

Code implementation demo

Example

Code example demo

Presentation Slides