init
This commit is contained in:
72
hts/HTS.py
72
hts/HTS.py
@@ -1,10 +1,10 @@
|
||||
import win32com.client
|
||||
#import win32com.client
|
||||
import time
|
||||
import os
|
||||
from datetime import datetime, timedelta
|
||||
import pandas as pd
|
||||
from enum import Enum
|
||||
#import plotly.graph_objects as go
|
||||
import plotly.graph_objects as go
|
||||
|
||||
|
||||
# enum 주문 상태 세팅용
|
||||
@@ -419,7 +419,7 @@ class HTS:
|
||||
objStockChart.SetInputValue(0, 'A'+stock_code) # 종목 코드
|
||||
objStockChart.SetInputValue(1, ord('1')) # 1: 기간으로 조회, 2: 개수로 조회
|
||||
objStockChart.SetInputValue(2, given_day) # 기간 조회 시, 시작일
|
||||
objStockChart.SetInputValue(3, given_day) # 기간 조회 시, 종료일
|
||||
objStockChart.SetInputValue(3, given_day) # 기간 조회 시, 종료일
|
||||
objStockChart.SetInputValue(4, 400) # 조회 시 가져오는 Line 개수
|
||||
objStockChart.SetInputValue(5, [0, 1, 2, 3, 4, 5, 8]) # 날짜,시간,시가,고가,저가,종가,거래량
|
||||
objStockChart.SetInputValue(6, ord('m')) # '차트 주가 - 월(M), 주(W), 일(D), 시(H), 분(m), 초(S) 차트 요청
|
||||
@@ -468,7 +468,7 @@ class HTS:
|
||||
|
||||
return
|
||||
|
||||
def getCSV(self, fileName, day, result):
|
||||
def getCSV(self, fileName, given_day, result):
|
||||
data = pd.read_csv(fileName)
|
||||
|
||||
days = data.날짜
|
||||
@@ -478,7 +478,7 @@ class HTS:
|
||||
high = data.고가
|
||||
low = data.저가
|
||||
vol = data.거래량
|
||||
start_time = datetime.strptime(day + " 090000", '%Y%m%d %H%M%S')
|
||||
start_time = datetime.strptime(given_day + " 090000", '%Y%m%d %H%M%S')
|
||||
|
||||
for i in range(len(data)):
|
||||
temp = datetime.strptime(str(days[i]) + " " + str(time[i]).zfill(4)+"00", '%Y%m%d %H%M%S')
|
||||
@@ -513,6 +513,18 @@ class HTS:
|
||||
low = [min(result["low"][i:i+window]) for i in range(0, size, window)]
|
||||
vol = [sum(result["vol"][i:i+window]) for i in range(0, size, window)]
|
||||
|
||||
close_df = pd.DataFrame(close)
|
||||
ma3_list = close_df.rolling(window=3).mean().fillna(close[0]).values.tolist()
|
||||
ma3 = [item[0] for item in ma3_list]
|
||||
ma5_list = close_df.rolling(window=5).mean().fillna(close[0]).values.tolist()
|
||||
ma5 = [item[0] for item in ma5_list]
|
||||
ma10_list = close_df.rolling(window=10).mean().fillna(close[0]).values.tolist()
|
||||
ma10 = [item[0] for item in ma10_list]
|
||||
ma15_list = close_df.rolling(window=15).mean().fillna(close[0]).values.tolist()
|
||||
ma15 = [item[0] for item in ma15_list]
|
||||
ma20_list = close_df.rolling(window=20).mean().fillna(close[0]).values.tolist()
|
||||
ma20 = [item[0] for item in ma20_list]
|
||||
|
||||
upper, lower = [], []
|
||||
for i in range(len(upper_df)):
|
||||
if i < window:
|
||||
@@ -526,7 +538,7 @@ class HTS:
|
||||
upper_temp = [upper[i] for i in range(size) if i % window == 0]
|
||||
lower_temp = [lower[i] for i in range(size) if i % window == 0]
|
||||
|
||||
temp = {"Open": open, "High": high, "Low": low, "Close": close, "Volume": vol, "Date": point_temp}
|
||||
temp = {"Date": point_temp, "Open": open, "High": high, "Low": low, "Close": close, "Volume": vol, "ma3": ma3, "ma5": ma5, "ma10": ma10, "ma15": ma15, "ma20": ma20}
|
||||
data = pd.DataFrame(temp)
|
||||
df_final_time = pd.DatetimeIndex(point_temp)
|
||||
data.index = df_final_time
|
||||
@@ -540,6 +552,11 @@ class HTS:
|
||||
data['Low'] = pd.to_numeric(data['Low'])
|
||||
data['Close'] = pd.to_numeric(data['Close'])
|
||||
data['Volume'] = pd.to_numeric(data['Volume'])
|
||||
data['ma3'] = pd.to_numeric(data['ma3'])
|
||||
data['ma5'] = pd.to_numeric(data['ma5'])
|
||||
data['ma10'] = pd.to_numeric(data['ma10'])
|
||||
data['ma15'] = pd.to_numeric(data['ma15'])
|
||||
data['ma20'] = pd.to_numeric(data['ma20'])
|
||||
|
||||
buy_colors = []
|
||||
for i in range(len(buy_line)):
|
||||
@@ -561,10 +578,17 @@ class HTS:
|
||||
sell_check = go.Scatter(x=data['Date'], y=sell_line, mode='markers', name="sell", marker=dict(size=14, color=sell_colors, line_width=0))
|
||||
bolinger_upper = go.Scatter(x=data['Date'], y=upper, name="upper", line_color='#8B4513')
|
||||
bolinger_lower = go.Scatter(x=data['Date'], y=lower, name="lower", line_color='#8B4513')
|
||||
ma3 = go.Scatter(x=data['Date'], y=data['ma3'], name="ma3", line_color='#F43B86')
|
||||
ma5 = go.Scatter(x=data['Date'], y=data['ma5'], name="ma5", line_color='#6D9886')
|
||||
ma10 = go.Scatter(x=data['Date'], y=data['ma10'], name="ma10", line_color='#406343')
|
||||
ma15 = go.Scatter(x=data['Date'], y=data['ma15'], name="ma15", line_color='#14279B')
|
||||
ma20 = go.Scatter(x=data['Date'], y=data['ma20'], name="ma20", line_color='#212121')
|
||||
|
||||
|
||||
candle_stick = go.Candlestick(x=data['Date'], open=data['Open'], high=data['High'], low=data['Low'], close=data['Close'], increasing_line_color='red', decreasing_line_color='blue')
|
||||
|
||||
# 그래프를 그린다.
|
||||
fig = go.Figure(data=[candle_stick, bolinger_upper, bolinger_lower, buy_check, sell_check])
|
||||
fig = go.Figure(data=[candle_stick, bolinger_upper, bolinger_lower, buy_check, sell_check, ma3, ma5, ma10, ma15, ma20])
|
||||
fig.update_layout(title=given_day + "_2x")
|
||||
fig.show()
|
||||
return
|
||||
@@ -586,15 +610,14 @@ class HTS:
|
||||
#buy_line[i] = low[i]
|
||||
check = True
|
||||
break
|
||||
|
||||
if check and i < len(lower) - 1:
|
||||
buy_line[i+1] = low[i] + 5
|
||||
check = False
|
||||
|
||||
"""
|
||||
if low[i-2] < lower[i-2] and low[i-1] < lower[i-1] and low[i] < open[i] == close[i] < high[i] and open[i] - low[i] == high [i] - open[i]:
|
||||
if not (open[i-2] < close[i-2] and open[i-1] < close[i-1]) and not (open[i-2] == close[i-2] or open[i-1] == close[i-1]):
|
||||
buy_line[i+1] = high[i]
|
||||
"""
|
||||
|
||||
# 팔 시점 체크
|
||||
# 산 가격에 5원 위로 매도를 건다.
|
||||
@@ -768,7 +791,7 @@ if __name__ == "__main__":
|
||||
RESOURCE_DIR = PROJECT_HOME + "/resources/analysis/"+today.strftime("%Y%m%d")
|
||||
|
||||
stock_code = "252670"
|
||||
given_day = datetime.today().strftime("%Y%m%d")
|
||||
given_day = datetime.today().strftime('%Y%m%d')
|
||||
|
||||
hts = HTS()
|
||||
#hts.all_stocks()
|
||||
@@ -776,30 +799,11 @@ if __name__ == "__main__":
|
||||
#hts.currentStock(stock_code)
|
||||
#hts.printStockData(stock_code, given_day)
|
||||
|
||||
"""
|
||||
given_day = '20210909'
|
||||
hts.simulate(stock_code, given_day)
|
||||
given_day = '20210910'
|
||||
hts.simulate(stock_code, given_day)
|
||||
given_day = '20210913'
|
||||
hts.simulate(stock_code, given_day)
|
||||
given_day = '20210914'
|
||||
hts.simulate(stock_code, given_day)
|
||||
given_day = '20210915'
|
||||
hts.simulate(stock_code, given_day)
|
||||
given_day = '20210916'
|
||||
hts.simulate(stock_code, given_day)
|
||||
given_day = '20210917'
|
||||
hts.simulate(stock_code, given_day)
|
||||
given_day = '20210923'
|
||||
hts.simulate(stock_code, given_day)
|
||||
given_day = '20210924'
|
||||
hts.simulate(stock_code, given_day)
|
||||
given_day = '20210927'
|
||||
hts.simulate(stock_code, given_day)
|
||||
"""
|
||||
#given_days = ['20210909','20210910','20210913','20210914','20210915','20210916','20210917','20210923','20210924','20210927','20210928','20210929']
|
||||
given_days = ['20210929']
|
||||
for given_day in given_days:
|
||||
hts.simulate(stock_code, given_day)
|
||||
|
||||
|
||||
hts.buyRealTime(stock_code, given_day)
|
||||
#hts.buyRealTime(stock_code, given_day_1, given_day)
|
||||
|
||||
print ("done...")
|
||||
|
||||
Reference in New Issue
Block a user