Scripts calcul hyperopt multiple

This commit is contained in:
Jérôme Delacotte
2025-10-26 16:20:33 +01:00
parent 04c7d190b1
commit f6951fd56f
6 changed files with 219 additions and 21 deletions

41
tools/statistique/ewm.py Normal file
View File

@@ -0,0 +1,41 @@
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(42)
# Générer 100 valeurs simulant un prix réel avec fluctuations
t = np.arange(100)
trend = np.sin(t/10) * 2 # tendance ondulante
noise = np.random.randn(100) * 0.5 # bruit
prices = 50 + trend + noise # prix centré autour de 50
df = pd.DataFrame({"price": prices})
# Rolling simple sur 5 périodes
df["rolling5"] = df["price"].rolling(5).mean()
# EMA plus réactive (span=5)
# EMA5 standard
df["ema5"] = df["price"].ewm(span=5, adjust=False).mean()
# EMA5 “lissée” avec double application
df["ema5_smooth"] = df["price"].ewm(span=5, adjust=False).mean().ewm(span=5, adjust=False).mean()
# EMA plus lissée (span=20)
df["ema20"] = df["price"].ewm(span=20, adjust=False).mean()
# Plot
plt.figure(figsize=(12,6))
plt.plot(df["price"], label="Prix", color='black', alpha=0.6)
plt.plot(df["rolling5"], label="Rolling 5", linestyle="--", color='blue')
plt.plot(df["ema5"], label="EMA 5", color='red')
plt.plot(df["ema5_smooth"], label="EMA 5S", color='blue')
plt.plot(df["ema20"], label="EMA 20", color='green')
plt.title("Rolling vs Exponential Moving Average (prix réaliste)")
plt.xlabel("Période")
plt.ylabel("Prix")
plt.legend()
plt.grid(True)
plt.show()

View File

@@ -0,0 +1,27 @@
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import make_interp_spline
from scipy.signal import savgol_filter
np.random.seed(42)
# Générer 100 valeurs simulant un prix réel avec fluctuations
t = np.arange(100)
trend = np.sin(t/10) * 2 # tendance ondulante
noise = np.random.randn(100) * 0.5 # bruit
prices = 50 + trend + noise # prix centré autour de 50
df = pd.DataFrame({"price": prices})
df["ema5"] = df["price"].ewm(span=5, adjust=False).mean()
# ATTENTION cela regarde dans le futur
df["ema5_savgol"] = savgol_filter(df["ema5"], window_length=21, polyorder=3)
# Plot
# fenetre=21 points, poly order 3
plt.plot(df["price"], alpha=0.5, label="Prix")
plt.plot(df["ema5_savgol"], label="EMA5 lissée Savitzky-Golay", color="red")
plt.legend()
plt.show()

View File

@@ -0,0 +1,35 @@
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import make_interp_spline
np.random.seed(42)
# Générer 100 valeurs simulant un prix réel avec fluctuations
t = np.arange(100)
trend = np.sin(t/10) * 2 # tendance ondulante
noise = np.random.randn(100) * 0.5 # bruit
prices = 50 + trend + noise # prix centré autour de 50
df = pd.DataFrame({"price": prices})
df["ema5"] = df["price"].ewm(span=5, adjust=False).mean()
x = np.arange(len(df))
y = df["ema5"].values
# Créer une nouvelle série de points x plus dense
x_smooth = np.linspace(x.min(), x.max(), 300)
# Spline (B-spline)
spl = make_interp_spline(x, y, k=3) # k=3 pour cubic spline
y_smooth = spl(x_smooth)
# Plot
plt.figure(figsize=(12,6))
plt.plot(df["price"], label="Prix", alpha=0.5, color="black")
plt.plot(df["ema5"], label="EMA 5", color='blue')
plt.plot(x_smooth, y_smooth, label="EMA5 lissée Bézier", color="red")
plt.title("EMA5 très lisse avec spline")
plt.legend()
plt.show()