Scripts calcul hyperopt multiple
This commit is contained in:
35
tools/statistique/spline.py
Normal file
35
tools/statistique/spline.py
Normal 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()
|
||||
Reference in New Issue
Block a user