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))
# 計算されたラベルを、新しい「labels」列としてDataFrameに追加する。
dataset['labels'] = 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...
これは特徴としてスライディングウィンドウで計算され、データセットに追加されます。クラスタリングはこの特徴に従って行われ、クラスタ・ラベルがデータセット全体に割り当てられます。そして、クラスタの1つに属する行が選択される。価格とその他の属性はそのまま残る。以上である。
なぜZZじゃないんだ?
ちょっとした説明を見つけた。
おそらく、いくつかの頂点をZZ列から放り出しても同じ効果が得られるだろう。このコードは、自分でディールマークアップライブラリに追加することができる。
さらに悪化した。
さらに悪化した。
MT5でモデルを組み合わせることは可能ですか?例えば、トップ20を選択し、40のonnxファイルが表示されたとします。この場合、どうすればよいですか?
MT5でモデルを組み合わせることは可能ですか?例えば、トップ20を選択し、40のonnxファイルが表示されたとします。この場合、どうすればよいですか?
もちろん、ドローダウンを追加することは可能でしょう。滑らかなラインは分かりにくいので、私はそこではドローダウンは最大-80%またはそれ以上であったと感じています)。
pandasモジュールの基本属性をすべて追加。
https://pandas.pydata.org/docs/reference/window.html
その結果、このようなグラフになった。マキシム、ご苦労様。