有没有一种方法可以可视化“呼叫时间序列”数据?

时间:2019-07-15 08:54:22

标签: python matplotlib time-series data-visualization

我的虚拟数据以收盘价

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天移动均线,应该有一个绿色标记,表示卖出。我如何以这种方式注释这些标记?

0 个答案:

没有答案
相关问题