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()

