Discussing the article: "Creating a mean-reversion strategy based on machine learning" - page 4

[Deleted]  
Evgeniy Chernish #:
Maxim, tell us more about how you cluster the price trajectory of a currency pair by the asymmetry coefficient.

It is calculated in a sliding window as a trait and added to the dataset. Clustering is performed according to this feature, cluster labels are assigned to the whole dataset. Then the rows that belong to one of the clusters are selected. Prices and all other attributes remain there. That's all.

[Deleted]  
fxsaber #:

Why not ZZ then?

However, I found a small explanation.

Probably, throwing some vertices out of the ZZ-row would have the same effect.
import pandas as pd
from scipy.signal import find_peaks

@njit
def calculate_labels_zigzag(peaks, troughs, len_close):
    """
    Generates labels based on the occurrence of peaks and troughs in the data.

    Args:
        peaks (np.array): Indices of the peaks in the data.
        troughs (np.array): Indices of the troughs in the data.
        len_close (int): The length of the close prices.

    Returns:
        np.array: An array of labels.
    """
    labels = np.empty(len_close, dtype=np.float64)
    labels.fill(2.0)  # Initialise all labels to 2.0 (no signal)
    
    for i in range(len_close):
        if i in peaks:
            labels[i] = 1.0  # Sell signal at peaks
        elif i in troughs:
            labels[i] = 0.0  # Buy signal at troughs
    return labels

def get_labels_filter_ZZ(dataset, peak_prominence=0.1) -> pd.DataFrame:
    """
    Generates labels for a financial dataset based on zigzag peaks and troughs.

    This function identifies peaks and troughs in the closing prices using the 'find_peaks' 
    function from scipy.signal. It generates buy signals at troughs and sell signals at peaks.

    Args:
        dataset (pd.DataFrame): DataFrame containing financial data with a 'close' column.
        peak_prominence (float, optional): Minimum prominence of peaks and troughs, 
                                           used to filter out insignificant fluctuations. 
                                           Defaults to 0.1.

    Returns:
        pd.DataFrame: The original DataFrame with a new 'labels' column and filtered rows:
                       - 'labels' column: 
                            - 0: Buy
                            - 1: Sell
                       - Rows where 'labels' is 2 (no signal) are removed.
                       - Rows with missing values (NaN) are removed.
    """

    # Find peaks and troughs in the closing prices
    peaks, _ = find_peaks(dataset['close'], prominence=peak_prominence)
    troughs, _ = find_peaks(-dataset['close'], prominence=peak_prominence)
    
    # Calculate buy/sell labels using the new zigzag-based labelling function
    labels = calculate_labels_zigzag(peaks, troughs, len(dataset)) 

    # Add the calculated labels as a new 'labels' column to the DataFrame
    dataset['labels'] = labels

    # Remove rows where the 'labels' column has a value of 2.0 (no signal)
    dataset = dataset.drop(dataset[dataset.labels == 2.0].index)
    
    # Return the modified DataFrame 
    return dataset


[Deleted]  
Maxim Dmitrievsky #:

You can add this code to the deal markup library yourself.

 
Maxim Dmitrievsky #:

It got worse.

[Deleted]  
fxsaber #:

It got worse.

Yeah, but it's a straight shot, no tricks.
 
Maxim Dmitrievsky #:

Is it possible to combine models in MT5? Let's say I selected top 20, therefore 40 onnx files appeared. What should I do in this case?

[Deleted]  
Evgeni Gavrilovi #:

Is it possible to combine models in MT5? Let's say I selected top 20, therefore 40 onnx files appeared. What should I do in this case?

This article is not about this topic. There is no provision for ensembling.
You can create as many copies of bots as you want.
 
Of course, we could add drawdowns, because the smooth lines are confusing, I feel that there the drain was up to -80% or even more).
[Deleted]  
Evgeni Gavrilovi #:
Of course, it would be possible to add drawdowns, because the smooth lines are confusing, I feel that there the drain was up to -80% or even more).
I don't accept any suggestions for improvement of the article, only discussion of the existing/questions.
 

Added all the basic attributes from the pandas module.

https://pandas.pydata.org/docs/reference/window.html

As a result, I got this graph. Maxim, thank you for your labour.


Window#
  • pandas.pydata.org
Window# instances are returned by calls: and . instances are returned by calls: and . instances are returned by calls: and . Rolling window functions# Weighted window functions# Expanding window functions# Exponentially-weighted window functions...