How to use detrend classes

How to use detrend classes#

 1import pandas as pd
 2
 3from src.functions.detrend import (
 4    BSplinesDetrend,
 5    ExponentialMADetrend,
 6    LinearMADetrend,
 7    LinearRegressionDetrend,
 8    PolynomialRegressionDetrend,
 9)
10from src.utils.misc import init_notebook
1init_notebook()
1# Lecture des données
2data_folder = "data/raw"
3stock_name = "AAPL"
4df = pd.read_csv(
5    f"{data_folder}/{stock_name}.csv", parse_dates=["Date"], index_col="Date"
6)
7y = df["Close"]
1models = [
2    LinearRegressionDetrend(),
3    PolynomialRegressionDetrend(order=5, n_segments=15),
4    LinearMADetrend(window=500),
5    ExponentialMADetrend(alpha=0.9),
6    BSplinesDetrend(interval_length=50, degree=3),
7]
1for detrend_model in models:
2    y_fitted = detrend_model.fit(y)
3    y_detrend = detrend_model.predict(y)
4    detrend_model.fancy_plot(xticklabels=df.index.strftime("%Y-%m-%d"))
/home/runner/work/stock-analysis/stock-analysis/src/functions/detrend_fancy_plot.py:40: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
  axs[0].set_xticklabels(xticklabels)
/home/runner/work/stock-analysis/stock-analysis/src/functions/detrend_fancy_plot.py:48: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
  axs[1].set_xticklabels(xticklabels)
/home/runner/work/stock-analysis/stock-analysis/src/functions/detrend_fancy_plot.py:40: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
  axs[0].set_xticklabels(xticklabels)
/home/runner/work/stock-analysis/stock-analysis/src/functions/detrend_fancy_plot.py:48: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
  axs[1].set_xticklabels(xticklabels)
/home/runner/work/stock-analysis/stock-analysis/src/functions/detrend_fancy_plot.py:40: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
  axs[0].set_xticklabels(xticklabels)
/home/runner/work/stock-analysis/stock-analysis/src/functions/detrend_fancy_plot.py:48: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
  axs[1].set_xticklabels(xticklabels)
/home/runner/work/stock-analysis/stock-analysis/src/functions/detrend_fancy_plot.py:40: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
  axs[0].set_xticklabels(xticklabels)
/home/runner/work/stock-analysis/stock-analysis/src/functions/detrend_fancy_plot.py:48: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
  axs[1].set_xticklabels(xticklabels)
/home/runner/work/stock-analysis/stock-analysis/src/functions/detrend_fancy_plot.py:40: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
  axs[0].set_xticklabels(xticklabels)
/home/runner/work/stock-analysis/stock-analysis/src/functions/detrend_fancy_plot.py:48: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
  axs[1].set_xticklabels(xticklabels)
../_images/fab6d637cb9c25154f2ea9a5a9d12bbdbff15f7c451c3a5cb10cc051f44ca90b.png ../_images/40d1f857e4eb4e1734793f2508c874238ba1b25310715d8dc8518f91b3be1aa6.png ../_images/48d0772a0e03580dd7eb0bb89ea96ea409a72d84bd7b2feed7c09f57334d2c05.png ../_images/b0077c02d56189dfdc4c3678254ec33672b64206863dd86ac708e1eb6d3ed4aa.png ../_images/1a966f9208f0bf0cf396b3c5c243d60e17aa3d64f975e496345d0a0ed378c816.png