init
This commit is contained in:
@@ -89,8 +89,9 @@ class Analyzer:
|
||||
def draw(self, stock):
|
||||
|
||||
last_index = self.get_last_index(stock)
|
||||
if last_index > 300:
|
||||
index = 300 # 최대 300일치 그래프 확인
|
||||
|
||||
if last_index > 540:
|
||||
index = 540 # 최대 540일치 그래프 확인
|
||||
df_stock = pd.DataFrame(stock["PRICE"][len(stock["PRICE"]) - index:])
|
||||
df_stochastic = pd.DataFrame(stock["STOCHASTIC"][len(stock["STOCHASTIC"]) - index:last_index+1])
|
||||
else:
|
||||
@@ -99,6 +100,13 @@ class Analyzer:
|
||||
df_stochastic = pd.DataFrame(stock["STOCHASTIC"][:index+1])
|
||||
|
||||
# general
|
||||
candle_stick = go.Candlestick(x=df_stock.DATE, open=df_stock.open, high=df_stock.high, low=df_stock.low, close=df_stock.close, increasing_line_color='red', decreasing_line_color='blue')
|
||||
avg5 = go.Scatter(x=df_stock.DATE, y=df_stock.avg5, name="avg5", line_color='#000000')
|
||||
avg20 = go.Scatter(x=df_stock.DATE, y=df_stock.avg20, name="avg20", line_color='#f84c43')
|
||||
avg60 = go.Scatter(x=df_stock.DATE, y=df_stock.avg60, name="avg60", line_color='#f89543')
|
||||
avg120 = go.Scatter(x=df_stock.DATE, y=df_stock.avg120, name="avg120", line_color='#0ed604')
|
||||
candle_data = [candle_stick, avg5, avg20, avg60, avg120]
|
||||
|
||||
volume = go.Bar(x=df_stock.DATE, y=df_stock['volume'], name="volume")
|
||||
volume_data = [volume]
|
||||
|
||||
@@ -107,14 +115,16 @@ class Analyzer:
|
||||
slow_d = go.Scatter(x=df_stochastic.DATE, y=df_stochastic['slow_d'], name="Slow%D", line_color='#4169E1')
|
||||
stochastic_data = [slow_k, slow_d]
|
||||
|
||||
fig = subplots.make_subplots(rows=2, cols=1, subplot_titles=('거래량', 'Stochastic'))
|
||||
fig = subplots.make_subplots(rows=3, cols=1, subplot_titles=('차트', '거래량', 'Stochastic'))
|
||||
|
||||
for trace in volume_data:
|
||||
for trace in candle_data:
|
||||
fig.append_trace(trace, 1, 1)
|
||||
for trace in stochastic_data:
|
||||
for trace in volume_data:
|
||||
fig.append_trace(trace, 2, 1)
|
||||
for trace in stochastic_data:
|
||||
fig.append_trace(trace, 3, 1)
|
||||
|
||||
fig.update_layout(height=800)
|
||||
fig.update_layout(height=1200, xaxis_rangeslider_visible=False)
|
||||
|
||||
return fig
|
||||
|
||||
@@ -368,26 +378,19 @@ class Analyzer:
|
||||
return status, buy_price
|
||||
|
||||
def getPositionalEnergy(self, stock, i):
|
||||
# 350일 중 가장 찾은 금액과 가장 높았던 금액 중 현재가의 위치 계산
|
||||
# 260 (= 52 * 5)일 중 가장 찾은 금액과 가장 높았던 금액 중 현재가의 위치 계산
|
||||
|
||||
top = stock[i]['close']
|
||||
bottom = stock[i]['close']
|
||||
price = stock[i]['close']
|
||||
|
||||
for i in range(8, 540):
|
||||
for i in range(8, 260):
|
||||
if i > len(stock) or not stock[-i]:
|
||||
break
|
||||
|
||||
if top < stock[-i]["close"]:
|
||||
top = stock[-i]["close"]
|
||||
|
||||
if stock[-i]["close"] < bottom:
|
||||
bottom = stock[-i]["close"]
|
||||
|
||||
if top - bottom == 0:
|
||||
energy = 100
|
||||
else:
|
||||
energy = round(((price - bottom) / (top - bottom)), 2)
|
||||
energy = round(bottom / top, 2)
|
||||
|
||||
return energy
|
||||
|
||||
@@ -515,7 +518,7 @@ class Analyzer:
|
||||
isbuy = 0
|
||||
|
||||
# 스토케스틱이 20이하이어야 하며, 볼린저밴드 0.3 보다 작으며, 위치에너지도 0.2보다 낮다면,
|
||||
if stochastic_score < 30 and bolingerband_score < 0.3 and positionalEnergy < 0.3:
|
||||
if stochastic_score < 30 and bolingerband_score < 0.3 and positionalEnergy < 0.6:
|
||||
isbuy = 1
|
||||
|
||||
# 위치에너지가 낮거나 240일선 아래에 있는 상태에서 상태값을 갖는 경우 매수한다.
|
||||
@@ -553,7 +556,7 @@ class Analyzer:
|
||||
if (STOCK[last_index]['close'] < STOCK[last_index]['open']) and (STOCK[last_index-1]['close'] < STOCK[last_index]['open'] and STOCK[last_index-1]['open'] < STOCK[last_index]['close']):
|
||||
isbuy = 5
|
||||
|
||||
if isbuy==4 and stochastic_score < 30 and bolingerband_score < 0.3 and positionalEnergy < 0.3:
|
||||
if isbuy==4 and stochastic_score < 30 and bolingerband_score < 0.3 and positionalEnergy < 0.5:
|
||||
isbuy = 9
|
||||
|
||||
fig = self.draw(stock)
|
||||
|
||||
Reference in New Issue
Block a user