小编Raj*_*air的帖子

如何在时间序列线图上绘制回归线

我对下面计算的斜率值(以度为单位)有疑问:

import pandas as pd
import yfinance as yf
import matplotlib.pyplot as plt
import datetime as dt
import numpy as np

df = yf.download('aapl', '2015-01-01', '2021-01-01')
df.rename(columns = {'Adj Close' : 'Adj_close'}, inplace= True)

x1 = pd.Timestamp('2019-01-02')
x2 = df.index[-1]
y1 = df[df.index == x1].Adj_close[0]
y2 = df[df.index == x2].Adj_close[0]

slope = (y2 - y1)/ (x2 - x1).days
angle = round(np.rad2deg(np.arctan2(y2 - y1, (x2 - x1).days)), 1)

fig, ax1 = plt.subplots(figsize= (15, 6))
ax1.grid(True, linestyle= ':')
ax1.set_zorder(1)
ax1.set_frame_on(False)
ax1.plot(df.index, df.Adj_close, …
Run Code Online (Sandbox Code Playgroud)

python time-series matplotlib pandas scikit-learn

4
推荐指数
1
解决办法
4594
查看次数

标签 统计

matplotlib ×1

pandas ×1

python ×1

scikit-learn ×1

time-series ×1