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) # 将所有标签初始化为 2.0(无信号)for i inrange(len_close):
if i in peaks:
labels[i] = 1.0# 在峰值时发出卖出信号elif i in troughs:
labels[i] = 0.0# 谷底出现买入信号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.
"""# 找出收盘价的波峰和波谷
peaks, _ = find_peaks(dataset['close'], prominence=peak_prominence)
troughs, _ = find_peaks(-dataset['close'], prominence=peak_prominence)
# 使用新的 "之 "字形标签功能计算买入/卖出标签
labels = calculate_labels_zigzag(peaks, troughs, len(dataset))
# 将计算出的标签作为新的 "标签 "列添加到 DataFrame 中
dataset['labels'] = labels
# 删除 "标签 "列值为 2.0(无信号)的行
dataset = dataset.drop(dataset[dataset.labels == 2.0].index)
# 返回修改后的 DataFrame return dataset
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...
它是在一个滑动窗口中作为一个特征计算出来并添加到数据集中的。根据这一特征进行聚类,为整个数据集分配聚类标签。然后选择属于其中一个聚类的行。价格和所有其他属性保持不变。仅此而已。
那为什么不是 ZZ?
不过,我找到了一个小小的解释。
也许,把一些顶点从 ZZ 行中扔出去也会产生同样的效果。您可以自行将这些代码添加到交易标记库中。
情况变得更糟了。
情况变得更糟了。
MT5 是否可以合并模型?比方说,我选择了前 20 位,因此出现了 40 个 onnx 文件。在这种情况下,我该怎么办?
MT5 是否可以合并模型?比方说,我选择了前 20 名,因此出现了 40 个 onnx 文件。在这种情况下,我该怎么办?
当然,也可以增加缩水,因为平滑的线条让人困惑,我觉得那里的缩水率高达 -80%,甚至更高)。
添加了 pandas 模块中的所有基本属性。
https://pandas.pydata.org/docs/reference/window.html
结果,我得到了这张图。马克西姆,感谢你的劳动。