有没有一种可视化调用timeseries数据的方法?

2024-04-25 19:40:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我的收盘价虚拟数据

Date          Close Price
2017-05-15    912.20
2017-05-16    894.70
2017-05-17    887.05
2017-05-18    871.35
2017-05-19    852.40
2017-05-22    844.85
2017-05-23    813.50
2017-05-24    783.30
2017-05-25    792.55
2017-05-26    808.90
2017-05-29    781.45
2017-05-30    797.80
2017-05-31    798.00
2017-06-01    803.70
2017-06-02    834.35
2017-06-05    839.95
2017-06-06    813.90
2017-06-07    825.30
2017-06-08    818.65
2017-06-09    795.70
2017-06-12    808.60
2017-06-13    813.00

我已经绘制了21天和34天的移动平均线,但我想想象一下,当较小的移动平均线穿过较长的移动平均线时,需要在某个特定点发出的买入指令,反之亦然

所以到目前为止我试过的是,画收盘价,然后移动平均21天,然后在同一个图上画34天

rolling_mean = df_close.rolling(window=21).mean()
rolling_mean2 = df_close.rolling(window=34).mean()
fig, ax = plt.subplots(figsize=(12, 6))
ax.plot(df_close, label='SUNTV')
ax.plot(rolling_mean, label='SUNTV 21 Day Moving Average', color='orange')
ax.plot(rolling_mean2, label='SUNTV 34 Day Moving Average', color='magenta')
ax.legend(loc='upper left')
plt.show()

我的输出是enter image description here 预期结果应该有绿色和黑色的标记,如图中所述 enter image description here

我想用这样一种方式来诠释我的曲线:每当21日移动平均线穿过31日移动平均线时,要用一个黑色的标记来表示买入,每当34日移动平均线穿过21日移动平均线时,应该用一个绿色的标记来表示卖出。我如何以这种方式注释这些标记


Tags: 标记dfcloseplotpltaxwindowmean