init
This commit is contained in:
@@ -1,187 +1,27 @@
|
||||
import math
|
||||
import pandas as pd
|
||||
from stockpredictor.analysis.Common import Common
|
||||
from stockpredictor.analysis.Stochastic import Stochastic
|
||||
from stockpredictor.analysis.RSI import RSI
|
||||
from stockpredictor.analysis.MACD import MACD
|
||||
from stockpredictor.analysis.IchimokuCloud import IchimokuCloud
|
||||
|
||||
class BuySellChecker:
|
||||
|
||||
common = None
|
||||
stochastic = None
|
||||
rsi = None
|
||||
ichimokuCloud = None
|
||||
|
||||
def __init__(self):
|
||||
self.common = Common()
|
||||
self.stochastic = Stochastic()
|
||||
self.rsi = RSI()
|
||||
self.macd = MACD()
|
||||
self.ichimokuCloud = IchimokuCloud()
|
||||
|
||||
return
|
||||
|
||||
def checkStatus(self, STOCK, last_index):
|
||||
status = set()
|
||||
|
||||
# 정배열 체크
|
||||
temp_status = self.common.check_RightArrange(STOCK)
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
|
||||
# 돌파 체크
|
||||
temp_status = self.common.check_Dolpa(STOCK, last_index, "5", "20")
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
temp_status = self.common.check_Dolpa(STOCK, last_index, "5", "60")
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
temp_status = self.common.check_Dolpa(STOCK, last_index, "5", "120")
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
temp_status = self.common.check_Dolpa(STOCK, last_index, "5", "240")
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
temp_status = self.common.check_Dolpa(STOCK, last_index, "20", "60")
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
temp_status = self.common.check_Dolpa(STOCK, last_index, "20", "120")
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
temp_status = self.common.check_Dolpa(STOCK, last_index, "20", "240")
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
temp_status = self.common.check_Dolpa(STOCK, last_index, "60", "120")
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
temp_status = self.common.check_Dolpa(STOCK, last_index, "60", "240")
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
temp_status = self.common.check_Dolpa(STOCK, last_index, "120", "240")
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
|
||||
# 20일선 돌파
|
||||
temp_status = self.common.check_Dolpa_Jiji(STOCK, last_index, '20')
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
|
||||
# 60일선 돌파
|
||||
temp_status = self.common.check_Dolpa_Jiji(STOCK, last_index, '60')
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
|
||||
# 120일선 돌파
|
||||
temp_status = self.common.check_Dolpa_Jiji(STOCK, last_index, '120')
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
|
||||
# 240일선 돌파
|
||||
#temp_status = self.common.check_Dolpa_Jiji(STOCK, last_index, '240')
|
||||
#if temp_status != "":
|
||||
# status.add(temp_status)
|
||||
|
||||
# 20일선 지지 매수가 추천
|
||||
temp_status = self.common.check_Dolpa_Jiji_20(STOCK, last_index)
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
|
||||
# 음봉인데 어제보다 종가가 더 높은 경우
|
||||
# 이 경우 정배열 상태인지도 함께 체크를 한다.
|
||||
higher_umbong_status = self.common.checkHigherUmbong(STOCK, last_index)
|
||||
if higher_umbong_status != "":
|
||||
status.add(temp_status)
|
||||
|
||||
# GOLDENCROSS#1은 바로 매수하지 않고, 이 시점 이후로 5일선이 20일선을 하방으로 뚫었다가 다시 20일선을 상방으로 뚫는 순간 매수를 시도한다.
|
||||
# GOLDENCROSS#2은 바로 매수 가능
|
||||
# GOLDENCROSS#3은 바로 매수 가능
|
||||
temp_status = self.common.check_golded_cross(STOCK, last_index)
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
|
||||
# YANGBONG
|
||||
# 어제 음봉 이후 장대양봉이었다면, 매수
|
||||
temp_status = self.common.checkLongYangBongAfterUmBong(STOCK, last_index)
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
|
||||
# Doji
|
||||
# 하락 추세에서 도지가 나오면 매수
|
||||
temp_status = self.common.checkDoji(STOCK, last_index)
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
|
||||
# Gravestone
|
||||
# 상승 추세에서 그레이브스톤이 나오면 매도
|
||||
temp_status = self.common.checkGravestone(STOCK, last_index)
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
|
||||
# Dragonfly
|
||||
# 하락 추세에서 드레곤플라이가 나오면 매수
|
||||
temp_status = self.common.checkDragonfly(STOCK, last_index)
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
|
||||
# Hammer
|
||||
temp_status = self.common.checkHammer(STOCK, last_index)
|
||||
# 하락 추세에서 해머가 나오면 매수
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
|
||||
# Hangingman
|
||||
temp_status = self.common.checkHangingman(STOCK, last_index)
|
||||
# 상승 추세에서 행잉맨이 나오면 매도
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
|
||||
# 상승장악형 (Engulfing) - 다음 날도 양봉이라면 매수
|
||||
# 하락 추세에서 상승장악형이 나오면 매수
|
||||
temp_status = self.common.checkEngulfingHigh(STOCK, last_index)
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
|
||||
# 하락장악형 (Engulfing)
|
||||
# 상승 추세에서 하락장악형이 나오면 매도
|
||||
temp_status = self.common.checkEngulfingLow(STOCK, last_index)
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
|
||||
# 상승 포아형 (Harami)
|
||||
# 하락 추세에서 상승포아형이 나오면 매수
|
||||
temp_status = self.common.checkHaramiHigh(STOCK, last_index)
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
|
||||
# 하락 포아형 (Harami)
|
||||
# 상승 추세에서 하락포아형이 나오면 매도
|
||||
temp_status = self.common.checkHaramiLow(STOCK, last_index)
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
|
||||
# 관통형 (piercing)
|
||||
# 하락 추세에서 관통형이 나오면 매수
|
||||
temp_status = self.common.checkPiercing(STOCK, last_index)
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
|
||||
# 흑운형 (Dark-cloud)
|
||||
# 상승 추세에서 흑운형이 나오면 매도
|
||||
temp_status = self.common.checkDarkCloud(STOCK, last_index)
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
|
||||
# 샛별 (Morning start)
|
||||
# 하락 추세에서 샛별형이 나오면 매수
|
||||
temp_status = self.common.checkMorningstar(STOCK, last_index)
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
|
||||
# 저녁별 (Evening start)
|
||||
# 상승 추세에서 저녁별형이 나오면 매도
|
||||
temp_status = self.common.checkEveningstar(STOCK, last_index)
|
||||
if temp_status != "":
|
||||
status.add(temp_status)
|
||||
|
||||
return status
|
||||
|
||||
def getPriceAndWeight1(self, data, i):
|
||||
buy, weight, sell = -1, -1, -1
|
||||
|
||||
@@ -299,15 +139,26 @@ class BuySellChecker:
|
||||
buy, weight, sell = -1, -1, -1
|
||||
|
||||
# 381: 어제 날짜 데이터 개수
|
||||
if i >= 381+1:
|
||||
if i >= 381+3:
|
||||
# 매수 분석
|
||||
if data["macdo"][i] < 0 and data["macd"][i] < -5:
|
||||
if data["macd"][i-3] > data["macd"][i-2] and data["macd"][i-2] > data["macd"][i-1] and data["macd"][i-1] < data["macd"][i]:
|
||||
buy = data["close"][i]
|
||||
|
||||
# 표준편차를 이용한 매매
|
||||
mean = (data["avg3"][i] + data["avg5"][i] + data["avg10"][i] + data["avg20"][i] + data["avg30"][i])/5
|
||||
vsum = (data["avg3"][i] - mean) ** 2 + (data["avg5"][i] - mean) ** 2 + (data["avg10"][i] - mean) ** 2 + (data["avg20"][i] - mean) ** 2 + (data["avg30"][i] - mean) ** 2
|
||||
variance = vsum / 5
|
||||
std = math.sqrt(variance)
|
||||
if std < 1:
|
||||
sell = data["close"][i]
|
||||
|
||||
# 매도 분석
|
||||
"""
|
||||
if data["slow_d"][i] > 90 and data["rsi"][i] > 65:
|
||||
if data["upper"][i] <= data["high"][i]:
|
||||
sell = data["close"][i] - 5
|
||||
|
||||
"""
|
||||
return buy, weight, sell
|
||||
|
||||
|
||||
@@ -374,6 +225,14 @@ class BuySellChecker:
|
||||
rsi = rsi_df['rsi'].values.tolist()
|
||||
rsis = rsi_df['rsis'].values.tolist()
|
||||
|
||||
# ichimokuCloud 계산
|
||||
# ichimokuCloud_df = self.ichimokuCloud.apply(STOCK, c=9, b=26, l=52)
|
||||
# ichimokuCloud_df = rsi_df.fillna(100)
|
||||
# changeLine = rsi_df['changeLine'].values.tolist()
|
||||
# baseLine = rsi_df['baseLine'].values.tolist()
|
||||
# leadingSpan1 = rsi_df['leadingSpan1'].values.tolist()
|
||||
# leadingSpan2 = rsi_df['leadingSpan2'].values.tolist()
|
||||
|
||||
temp = {"date": point_temp,
|
||||
"open": open, "high": high, "low": low, "close": close, "volume": vol, "upper": upper, "lower": lower,
|
||||
"avg3": avg3, "avg5": avg5, "avg10": avg10, "avg20": avg20, "avg30": avg30, "avg60": avg60,
|
||||
|
||||
Reference in New Issue
Block a user