股票sar指标使用技巧视频教程

facai888 阅读:646 2024-05-01 06:54:56 评论:0

```html

SAR指标源代码

股票SAR指标源代码

下面是一个简单的Python示例代码,用于计算和绘制股票的SAR(Stop and Reverse)指标。

import yfinance as yf

import matplotlib.pyplot as plt

下载股票数据

data = yf.download('AAPL', start='20210101', end='20220101')

计算SAR指标

af = 0.02

max_af = 0.2

data['SAR'] = 0.0

data['EP'] = 0.0

data['AF'] = af

for i in range(1, len(data)):

if data['High'][i] > data['High'][i 1] and data['Low'][i] > data['Low'][i 1]:

data['EP'][i] = data['High'][i]

data['AF'][i] = min(af data['AF'][i 1], max_af)

elif data['High'][i] < data['High'][i 1] and data['Low'][i] < data['Low'][i 1]:

data['EP'][i] = data['Low'][i]

data['AF'][i] = min(af data['AF'][i 1], max_af)

else:

data['EP'][i] = data['EP'][i 1]

data['AF'][i] = data['AF'][i 1]

if i == 1:

data['SAR'][i] = data['Low'][i 1]

else:

if data['High'][i] <= data['High'][i 1]:

data['SAR'][i] = data['SAR'][i 1] data['AF'][i 1] * (data['EP'][i 1] data['SAR'][i 1])

if data['Low'][i] >= data['Low'][i 1]:

data['SAR'][i] = data['SAR'][i 1] data['AF'][i 1] * (data['EP'][i 1] data['SAR'][i 1])

绘制SAR指标

plt.figure(figsize=(10,5))

plt.plot(data['Close'], label='Close Price')

plt.plot(data['SAR'], label='SAR')

plt.title('SAR Indicator')

plt.xlabel('Date')

plt.ylabel('Price')

plt.legend()

plt.show()

```

希望这个示例代码对您有所帮助。在这个示例中,我们使用了yfinance库来下载股票数据,计算了SAR指标,并利用matplotlib库进行了绘图。您可以根据自己的需求对代码进行调整和扩展。

可以去百度分享获取分享代码输入这里。
声明

免责声明:本网站部分内容由用户上传,若侵犯您权益,请联系我们,谢谢!联系QQ:2760375052

搜索
关注我们

扫一扫关注我们,了解最新精彩内容