Skip to content

Instantly share code, notes, and snippets.

@mohneesh7
Last active December 20, 2022 06:35
Show Gist options
  • Save mohneesh7/b51a668ffb49f426cdb36b89cb0319e9 to your computer and use it in GitHub Desktop.
Save mohneesh7/b51a668ffb49f426cdb36b89cb0319e9 to your computer and use it in GitHub Desktop.
savgol_filter
import pandas as pd
import plotly.graph_objects as go
from scipy.signal import savgol_filter
data = pd.read_csv('DOGE-USD.csv', index_col=0, parse_dates=True)
data.head()
# Savitzky-Golay filter
y_filtered = savgol_filter(data.High, 11, 2)
y_filtered_7_3 = savgol_filter(data.High, 7, 3)
f = go.Figure()
f.add_trace(go.Scatter(x=data.index, y=y_filtered, name="High Smoothed (11, 2)"))
f.add_trace(go.Scatter(x=data.index, y=y_filtered_7_3, name="High Smoothed (7, 3)"))
f.add_trace(go.Scatter(x=data.index, y=data.High, name="High Unsmoothed"))
f.update_layout(
title="DOGE-USD",
xaxis_title="Date-Time axis",
yaxis_title="USD",
legend_title="Legend",
font=dict(
family="Courier New, monospace",
size=18,
color="RebeccaPurple"
)
)
f.show()ow()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment