def 계산psar(self,barsdata, iaf=0.02, maxaf=0.2):
length = len(barsdata)
first_index = 0
high = list(barsdata['high'])
low = list(barsdata['low'])
close = list(barsdata['y'])
psar = close[0:len(close)]
bull = True
af = iaf
hp = high[first_index]
lp = low[first_index]
for i in range(first_index+2, length):
if bull:
psar[i] = psar[i - 1] + af * (hp - psar[i - 1])
else:
psar[i] = psar[i - 1] + af * (lp - psar[i - 1])
reverse = False
if bull:
if low[i] < psar[i]:
bull = False
reverse = True
psar[i] = hp
lp = low[i]
af = iaf
else:
if high[i] > psar[i]:
bull = True
reverse = True
psar[i] = lp
hp = high[i]
af = iaf
if not reverse:
if bull:
if high[i] > hp:
hp = high[i]
af = min(af + iaf, maxaf)
if low[i - 1] < psar[i]:
psar[i] = low[i - 1]
if low[i - 2] < psar[i]:
psar[i] = low[i - 2]
else:
if low[i] < lp:
lp = low[i]
af = min(af + iaf, maxaf)
if high[i - 1] > psar[i]:
psar[i] = high[i - 1]
if high[i - 2] > psar[i]:
psar[i] = high[i - 2]
barsdata["psar"] = psar
def 실시간계산psar(self,barsdata, iaf=0.02, maxaf=0.2):
length = len(barsdata)
first_index = len(barsdata)-2
high = list(barsdata['high'])
low = list(barsdata['low'])
bull = True
af = iaf
hp = high[first_index]
lp = low[first_index]
for i in range(first_index + 2, length):
if bull:
barsdata["psar"].iloc[i] = barsdata["psar"].iloc[i - 1] + af * (hp - barsdata["psar"].iloc[i - 1])
else:
barsdata["psar"].iloc[i] = barsdata["psar"].iloc[i - 1] + af * (lp - barsdata["psar"].iloc[i - 1])
reverse = False
if bull:
if low[i] < barsdata["psar"].iloc[i]:
bull = False
reverse = True
barsdata["psar"].iloc[i] = hp
lp = low[i]
af = iaf
else:
if high[i] > barsdata["psar"].iloc[i]:
bull = True
reverse = True
barsdata["psar"].iloc[i] = lp
hp = high[i]
af = iaf
if not reverse:
if bull:
if high[i] > hp:
hp = high[i]
af = min(af + iaf, maxaf)
if low[i - 1] < barsdata["psar"].iloc[i]:
barsdata["psar"].iloc[i] = low[i - 1]
if low[i - 2] < barsdata["psar"].iloc[i]:
barsdata["psar"].iloc[i] = low[i - 2]
else:
if low[i] < lp:
lp = low[i]
af = min(af + iaf, maxaf)
if high[i - 1] > barsdata["psar"].iloc[i]:
barsdata["psar"].iloc[i] = high[i - 1]
if high[i - 2] > barsdata["psar"].iloc[i]:
barsdata["psar"].iloc[i] = high[i - 2]
댓글 없음:
댓글 쓰기