How detrended data behave with candlestick chart#

The whole data are detrended using close price (chosen arbitrarily amongst open / close / high / low).
This way, the detrended data can be plotted on candlestick chart.
Otherwise, open / close / high / low prices may cross each other.

1import mplfinance as mpl
2import pandas as pd
3
4from src.utils import init_notebook
1init_notebook()

Choose detrend method

1detrend_model_name = "LinearMADetrend"
2model_options = "window-100"
1raw_data_folder = "data/raw_data"
2processed_data_folder = (
3    f"data/processed_data/detrend_data/{detrend_model_name}/{model_options}"
4)
5stock_name = "AAPL"
 1df = pd.read_csv(
 2    f"{raw_data_folder}/{stock_name}.csv", parse_dates=["Date"], index_col="Date"
 3)
 4print(f"{df.shape = }")
 5
 6df_detrend = pd.read_csv(
 7    f"{processed_data_folder}/{stock_name}.csv",
 8    parse_dates=["Date"],
 9    index_col="Date",
10)
df.shape = (756, 6)
1df_6_months = df[df.index > pd.Timestamp("2021-06-01")]
2df_detrend_6_months = df_detrend[df.index > pd.Timestamp("2021-06-01")]
 1mpl.plot(
 2    df_6_months,
 3    type="candle",
 4    title=f"Cours de l'action {stock_name}",
 5    style="yahoo",
 6)
 7mpl.plot(
 8    df_detrend_6_months,
 9    type="candle",
10    title=f"Cours de l'action {stock_name} sans la tendance",
11    style="yahoo",
12)
../_images/3327e246e401d5134767ac701eb2246d6f857d2c7ed12a00251d45bc1940f9a9.png ../_images/86f32f8eef006cbf4f11f22171cf25b8daede107ab9eba5f8ebc36b90e585dd5.png