我是量化交易员,我需要用python的Matplotlib库编写一段可以实现输入股票每日数据表后输出股价5日均线图的代码
时间: 2024-05-12 12:18:11 浏览: 225
这个问题我可以回答。以下是一个简单的python代码实现股价5日均线图:
```
import pandas as pd
from pandas_datareader import data as pdr
import yfinance as yf
import matplotlib.pyplot as plt
yf.pdr_override()
def stock_ma(symbol):
data = pdr.get_data_yahoo(symbol, start='2020-01-01')
data['MA5'] = data['Close'].rolling(5).mean()
plt.plot(data['Close'])
plt.plot(data['MA5'])
plt.title('Stock Price MA5')
plt.legend(['Close', 'MA5'])
plt.show()
symbol = 'AAPL'
stock_ma(symbol)
```
其中,我们使用Yfinance获取股票数据,然后计算出5日均线并画出图像。你可以将`symbol`变量修改为你感兴趣的股票。
阅读全文
相关推荐
![py](https://img-home.csdnimg.cn/images/20250102104920.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pptx](https://img-home.csdnimg.cn/images/20241231044947.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)