```python
SAR指标计算函数
def calculate_sar(high, low, acceleration=0.02, maximum=0.2):
af = acceleration
ep = low[0]
sar = low[0]
trend = 1
trend_switch = False
sar_values = []
for i in range(1, len(high)):
if trend == 1:
if high[i] > ep:
ep = high[i]
af = min(af acceleration, maximum)
if low[i] < sar af * (ep sar):
sar = low[i]
trend = 1
trend_switch = True
else:
if low[i] < ep:
ep = low[i]
af = min(af acceleration, maximum)
if high[i] > sar af * (sar ep):
sar = high[i]
trend = 1
trend_switch = True
sar_values.append(sar)
if trend_switch:
trend_switch = False
ep = high[i 1]
sar = sar_values[1]
af = acceleration
return sar_values
```
这是一个简单的Python函数,用于计算SAR指标(停损和换仓点)。如果需要根据特定的数据进行计算,可以将股票的更高价和更低价数据传入该函数,并可以选择性地设置加速因子和更大值。
还没有评论,来说两句吧...