Scripts calcul hyperopt multiple
This commit is contained in:
@@ -33,44 +33,67 @@ if 'close' not in df.columns or 'timestamp' not in df.columns:
|
||||
sys.exit(1)
|
||||
|
||||
# --- paramètres ---
|
||||
SMOOTH_WIN = 5 # EMA pour lisser la pente
|
||||
NUM_TOP = 3 # nombre de segments à garder par classe
|
||||
SMOOTH_WIN = 10 # EMA pour lisser la pente
|
||||
NUM_TOP = 1 # nombre de segments à garder par classe
|
||||
|
||||
# --- charger les données ---
|
||||
df['timestamp'] = pd.to_datetime(df['timestamp'], errors='coerce')
|
||||
|
||||
# filtrer uniquement 2024 et 2025
|
||||
df = df[df['timestamp'].dt.year.isin([2024, 2025])]
|
||||
|
||||
# --- calcul SMA14 ---
|
||||
df['sma14'] = ta.trend.sma_indicator(df['close'], 14)
|
||||
df['sma'] = talib.SMA(df, timeperiod=20) #ta.trend.sma_indicator(df['close'], 14)
|
||||
|
||||
# --- pente brute ---
|
||||
df['slope'] = df['sma14'].diff()
|
||||
df['slope'] = df['sma'].diff()
|
||||
|
||||
# --- lissage EMA ---
|
||||
df['slope_smooth'] = df['slope'].ewm(span=SMOOTH_WIN, adjust=False).mean()
|
||||
|
||||
#df["slope_smooth"] = savgol_filter(df["slope_smooth"], window_length=21, polyorder=3)
|
||||
|
||||
# --- normalisation relative ---
|
||||
df['slope_norm'] = df['slope_smooth'] / df['close']
|
||||
df['slope_norm'].fillna(0, inplace=True)
|
||||
# df['slope_norm'].fillna(0, inplace=True)
|
||||
df['slope_norm'] = df['slope_norm'].fillna(0)
|
||||
|
||||
|
||||
# --- classification dynamique via quantiles ---
|
||||
q = df['slope_norm'].quantile([0.07, 0.21, 0.35, 0.65, 0.79, 0.93]).values
|
||||
q1, q2, q3, q4, q5, q6 = q
|
||||
|
||||
q = df['slope_norm'].quantile([0.125, 0.375, 0.625, 0.875]).values
|
||||
q1, q2, q3, q4 = q
|
||||
|
||||
def classify(v):
|
||||
if v <= q1:
|
||||
return 'BR3'
|
||||
elif v <= q2:
|
||||
return 'BR2'
|
||||
elif v <= q3:
|
||||
elif v <= q2:
|
||||
return 'BR1'
|
||||
elif v <= q4:
|
||||
elif v <= q3:
|
||||
return 'RG'
|
||||
elif v <= q5:
|
||||
elif v <= q4:
|
||||
return 'BU1'
|
||||
elif v <= q6:
|
||||
return 'BU2'
|
||||
else:
|
||||
return 'BU3'
|
||||
return 'BU2'
|
||||
|
||||
# q = df['slope_norm'].quantile([0.7, 0.21, 0.35, 0.65, 0.79, 0.93]).values
|
||||
# q1, q2, q3, q4, q5, q6 = q
|
||||
#
|
||||
# def classify(v):
|
||||
# if v <= q1:
|
||||
# return 'BR3'
|
||||
# elif v <= q2:
|
||||
# return 'BR2'
|
||||
# elif v <= q3:
|
||||
# return 'BR1'
|
||||
# elif v <= q4:
|
||||
# return 'RG'
|
||||
# elif v <= q5:
|
||||
# return 'BU1'
|
||||
# elif v <= q6:
|
||||
# return 'BU2'
|
||||
# else:
|
||||
# return 'BU3'
|
||||
|
||||
df['trend_class'] = df['slope_norm'].apply(classify)
|
||||
|
||||
@@ -100,7 +123,7 @@ if trend is not None and start_idx is not None:
|
||||
|
||||
# --- extraire les 5 plus longs segments par classe ---
|
||||
top_segments_by_class = {}
|
||||
for cls in ['BR3','BR2','BR1','RG','BU1','BU2','BU3']:
|
||||
for cls in ['BR2','BR1','RG','BU1','BU2']:
|
||||
cls_segments = [(t,s,e) for t,s,e in segments if t==cls]
|
||||
# calcul de la durée
|
||||
cls_segments = [(t,s,e,(e-s).total_seconds()) for t,s,e in cls_segments]
|
||||
|
||||
Reference in New Issue
Block a user