def rule_dayangLine(self, rows_all, batch): # now = int(time.time()) # timeStruct = time.localtime(now) # batch = time.strftime("%Y%m%d", timeStruct) sqlUtil = SqlUtil() rows_all_count = len(rows_all) if rows_all_count > 9: close = float(rows_all[rows_all_count - 1][3]) high = float(rows_all[rows_all_count - 1][4]) low = float(rows_all[rows_all_count - 1][5]) open = float(rows_all[rows_all_count - 1][6]) turn_over_rate = float(rows_all[rows_all_count - 1][10]) if open > 0: upRate = (close - open) / open if close > open: if (close == high) and (low == open): if upRate >= 0.05 and turn_over_rate > 5: remark = '当天大阳线,且涨幅超过5%' code = rows_all[rows_all_count - 1][1] name = rows_all[rows_all_count - 1][2] sqlUtil.insert_stock_select(batch, code, name, '2', remark) print(remark) print(code) print(name)
def rule_limitUp(self, rows_all, batch): # now = int(time.time()) # timeStruct = time.localtime(now) # batch = time.strftime("%Y%m%d", timeStruct) sqlUtil = SqlUtil() rows_all_count = len(rows_all) if rows_all_count > 2: close = float(rows_all[rows_all_count - 1][3]) close_pre = float(rows_all[rows_all_count - 2][3]) upRate = 0 if close_pre > 0: upRate = (close - close_pre) / close_pre if upRate >= 0.095: remark = '今天涨停' code = rows_all[rows_all_count - 1][1] name = rows_all[rows_all_count - 1][2] sqlUtil.insert_stock_select(batch, code, name, '6', remark) print(remark) print(code) print(name)
def rule_3Day15Up(self, rows_all, batch): sqlUtil = SqlUtil() rows_all_count = len(rows_all) if rows_all_count > 4: close_end = float(rows_all[rows_all_count - 1][3]) open_end = float(rows_all[rows_all_count - 1][6]) close_begin = float(rows_all[rows_all_count - 4][3]) upRate = 0 if close_begin > 0: upRate = (close_end - close_begin) / close_begin if upRate >= 0.15: if close_end > open_end: remark = '3天累计涨幅超过15%' code = rows_all[rows_all_count - 1][1] name = rows_all[rows_all_count - 1][2] sqlUtil.insert_stock_select(batch, code, name, '3', remark)
def get_stock_code(self, excel_name): wb = load_workbook(excel_name) ws = wb['stock_all'] rows = ws.max_row # 获取行数 cols = ws.max_column # 获取列数 # for i in range(1, rows + 1): # for j in range(1, cols + 1): # print(ws.cell(row = i, column = j).value) #pattern = re.compile(r'[0-9]+') sqlUtil = SqlUtil() for i in range(2, rows + 1): matchObj = re.search(r'[0-9]+', ws.cell(row=i, column=2).value, re.M | re.I) if matchObj: code = matchObj.group() else: code = '' name = ws.cell(row=i, column=3).value.strip() industry = ws.cell(row=i, column=15).value.strip() print(code) print(name) print(industry) sqlUtil.insert_stock2(code, name, industry, '', '', '')
def get_stock_industry(self, excel_name): wb = load_workbook(excel_name) ws = wb['industry'] rows = ws.max_row # 获取行数 cols = ws.max_column # 获取列数 # for i in range(1, rows + 1): # for j in range(1, cols + 1): # print(ws.cell(row = i, column = j).value) #pattern = re.compile(r'[0-9]+') sqlUtil = SqlUtil() for i in range(2, rows + 1): code = ws.cell(row=i, column=1).value name = ws.cell(row=i, column=2).value industry = ws.cell(row=i, column=3).value segment = ws.cell(row=i, column=4).value print(code[2:len(code)]) print(code) print(name) print(industry) print(segment) sqlUtil.insert_stock_industry(code[2:len(code)], name, industry, segment)
def get_date_start_end(self, n): sqlUtil = SqlUtil() sqlUtil.connect(); cursor = sqlUtil.db.cursor(); select_sql = "SELECT code, date FROM stock_history WhERE code = '000001' ORDER BY date desc LIMIT " + str(n) # 002752、300208 rows = []; try: cursor.execute(select_sql) rows = cursor.fetchall() except: print("Error: unable to fetch data") sqlUtil.db.close() rows_count = len(rows) date_start = rows[rows_count - 1][1] date_end = rows[0][1] return date_start, date_end
def rule_1WinN(self, rows_all): now = int(time.time()) timeStruct = time.localtime(now) batch = time.strftime("%Y%m%d", timeStruct) sqlUtil = SqlUtil() rule_win_n = 4 rows_all_count = len(rows_all) rows_target = rows_all[rows_all_count - rule_win_n:rows_all_count] rows_target_count = len(rows_target) if rows_target_count > 3: close_target = float(rows_target[rows_target_count - 1][3]) open_target = float(rows_target[rows_target_count - 1][6]) rule_count1 = 0 rule_count2 = 0 rule_count3 = 0 if close_target > open_target: for i in range(0, rows_target_count - 1): close = float(rows_target[i][3]) open = float(rows_target[i][6]) if close < open: rule_count1 = rule_count1 + 1 for i in range(0, rows_target_count - 1): close = float(rows_target[i][3]) open = float(rows_target[i][6]) if open_target < close: rule_count2 = rule_count2 + 1 if close_target > open: rule_count3 = rule_count3 + 1 if (rule_count1 == rows_target_count - 1) and (rule_count2 == rows_target_count - 1) and (rule_count3 == rows_target_count - 1): remark = '当天阳线吞没前' + str(rows_target_count - 1) + '天震荡K线' code = rows_target[rows_target_count - 1][1] name = rows_target[rows_target_count - 1][2] sqlUtil.insert_stock_select(batch, code, name, '2', remark) print(remark) print(code) print(name)
def get_today_data(self, data_path, today): sqlUtil = SqlUtil() netEase = NetEase() rows = sqlUtil.select_stock() print('下载当天csv数据文件, 当前时间:%s' % datetime.now()) for row in rows: code = row[0] netEase.get_today_data(code, data_path, today)
def get_today_data(self, thread_name, data_path, today, row_from, row_to): sqlUtil = SqlUtil() netEase = NetEase() rows = sqlUtil.select_stock() target_rows = rows[row_from:row_to] for row in target_rows: code = row[0] netEase.get_today_data_thread(thread_name, code, data_path, today)
def rule_3DayUp(self, rows_all, batch): # now = int(time.time()) # timeStruct = time.localtime(now) # batch = time.strftime("%Y%m%d", timeStruct) sqlUtil = SqlUtil() rule_vol_n = 3 rows_all_count = len(rows_all) rows_target = rows_all[rows_all_count - rule_vol_n:rows_all_count] # rows_target = rows_all [209 : 213] ruleUtil = RuleUtil() opens = [] closes = [] volumes = [] turn_over_rates = [] for row in rows_target: code = row[1] name = row[2] close = float(row[3]) open = float(row[6]) turn_over_rate = float(row[10]) bargain_volume = float(row[11]) if close > open: opens.append(open) closes.append(close) volumes.append(bargain_volume) turn_over_rates.append(float(turn_over_rate)) sort_closes = sorted(closes) sort_volumes = sorted(volumes) if len(closes) >= 3: if ruleUtil.check_turn_over_rate(turn_over_rates) and operator.eq( closes, sort_closes) and operator.eq( volumes, sort_volumes): remark = '连续3天换手率>=3,开始温和放量 # 连续3天股价逐渐升高 # 连续3天成交量依次放大' exist_rows = sqlUtil.check_stock_select(code, batch) exist_count = exist_rows[0][0] if exist_count == 0: sqlUtil.insert_stock_select(batch, code, name, '1', remark) print(remark) else: print('需要3天数据,实际只有' + str(len(closes)) + "天")
def get_history_data(self): sqlUtil = SqlUtil() netEase = NetEase() print('开始任务') print('step1:下载csv数据文件,当前时间:%s' % datetime.now()) rows = sqlUtil.select_stock() for row in rows: code = row[0] netEase.get_his_data_1year(code) print('step2:将csv数据导入数据库,当前时间:%s' % datetime.now()) for row in rows: csv_name = "../data/1year/" + row[0] + ".csv" print('处理文件:' + csv_name) with open(csv_name, 'r', encoding='gb2312') as f: reader = csv.reader(f) next(reader) for row in reader: date = row[0] matchObj = re.search(r'[0-9]+', row[1], re.M | re.I) if matchObj: code = matchObj.group() else: code = '' name = row[2] close = row[3] high = row[4] low = row[5] open2 = row[6] pre_close = row[7] up_down_price = row[8] up_down_range = row[9] turn_over_rate = row[10] bargain_volume = row[11] bargain_amount = row[12] total_market_value = row[13] flow_market_value = row[14] bargain_ticket_count = row[15] sqlUtil.insert_stock_history( date, code, name, close, high, low, open2, pre_close, up_down_price, up_down_range, turn_over_rate, bargain_volume, bargain_amount, total_market_value, flow_market_value, bargain_ticket_count)
def rule_1Win9(self, rows_all, batch): # now = int(time.time()) # timeStruct = time.localtime(now) # batch = time.strftime("%Y%m%d", timeStruct) sqlUtil = SqlUtil() rule_win_n = 10 rows_all_count = len(rows_all) rows_target = rows_all[rows_all_count - rule_win_n:rows_all_count] #rows_target = rows_all[233 : 243] rows_target_count = len(rows_target) for row in rows_target: print(row) if rows_target_count > 9: close_target = float(rows_target[rows_target_count - 1][3]) high_target = float(rows_target[rows_target_count - 1][4]) low_target = float(rows_target[rows_target_count - 1][5]) open_target = float(rows_target[rows_target_count - 1][6]) rule_count1 = 0 rule_count2 = 0 if close_target > open_target: for i in range(0, rows_target_count - 1): close = float(rows_target[i][3]) open = float(rows_target[i][6]) if (low_target <= open) and (low_target <= close): rule_count1 = rule_count1 + 1 if (close_target > open) and (close_target > close): rule_count2 = rule_count2 + 1 if (rule_count1 == rows_target_count - 1) and (rule_count2 == rows_target_count - 1): remark = '当天阳线吞没前' + str(rows_target_count - 1) + '天震荡K线' code = rows_target[rows_target_count - 1][1] name = rows_target[rows_target_count - 1][2] sqlUtil.insert_stock_select(batch, code, name, '9', remark) print(remark) print(code) print(name)
def update_ma(self, array_ma, n): sqlUtil = SqlUtil() sqlUtil.connect() cursor = sqlUtil.db.cursor() #print(array_ma) array_ma_count = len(array_ma) if array_ma_count: ma_n = "ma" + str(n) update_sql = "UPDATE stock_history SET " + ma_n + " = CASE id " when_str = "" id_str = "" for array_item in array_ma: #print(array_item) when_item = "WHEN " + str(array_item[0]) + " THEN " + str( array_item[1]) + " " when_str = when_str + when_item id_str = id_str + str(array_item[0]) + "," id_str = id_str[0:len(id_str) - 1] update_sql = update_sql + when_str + " END WHERE id IN (" + id_str + ")" try: cursor.execute(update_sql) sqlUtil.db.commit() #print("update_ma sucess"); except Exception as e: # 发生错误时回滚 sqlUtil.db.rollback() #print("update_ma error:" + e); sqlUtil.db.close()
def run(self): print("开始线程:" + self.threadName) threadUtil = ThreadUtil() sqlUtil = SqlUtil() rows = sqlUtil.select_stock() rowCount = len(rows) threadCount = 10 rowFrom, rowTo = threadUtil.get_row_index(rowCount, threadCount, self.threadID) print(self.threadName + ' rowFrom = ' + str(rowFrom)) print(self.threadName + ' rowTo = ' + str(rowTo)) threadUtil.get_today_data(self.threadName, self.data_path, self.today, rowFrom, rowTo) print("退出线程:" + self.threadName)
def select_stock(self): sqlUtil = SqlUtil() sqlUtil.connect(); cursor = sqlUtil.db.cursor(); select_sql = 'SELECT code, name, industry FROM stock ' # 002752、300208 rows = []; try: cursor.execute(select_sql) rows = cursor.fetchall() except: print("Error: unable to fetch data") sqlUtil.db.close() return rows
def rule_5Day30Up(self, rows_all, batch): sqlUtil = SqlUtil() rows_all_count = len(rows_all) if rows_all_count > 6: close_end = float(rows_all[rows_all_count - 1][3]) close_begin = float(rows_all[rows_all_count - 6][3]) upRate = 0 if close_begin > 0: upRate = (close_end - close_begin) / close_begin if upRate >= 0.32: remark = '5天累计涨幅超过30%' code = rows_all[rows_all_count - 1][1] name = rows_all[rows_all_count - 1][2] sqlUtil.insert_stock_select(batch, code, name, '4', remark)
def rule_30Day50Up(self, rows_all, batch): sqlUtil = SqlUtil() rows_all_count = len(rows_all) if rows_all_count > 30: close_end = float(rows_all[rows_all_count - 1][3]) close_begin = float(rows_all[rows_all_count - 30][3]) upRate = 0 if close_begin > 0: upRate = (close_end - close_begin) / close_begin if upRate >= 0.5: remark = '30天累计涨幅超过50%' code = rows_all[rows_all_count - 1][1] name = rows_all[rows_all_count - 1][2] sqlUtil.insert_stock_select(batch, code, name, '5', remark)
def select_stock_history_by_days(self, codes, date_start, date_end): sqlUtil = SqlUtil() sqlUtil.connect(); cursor = sqlUtil.db.cursor(); select_sql = "SELECT id, date, code, name, close, high, low, open, pre_close, up_down_price, up_down_range, turn_over_rate, bargain_volume, bargain_amount, total_market_value, flow_market_value, bargain_ticket_count FROM stock_history WHERE code in " + codes + " AND date >= \'" + date_start + "\' AND date <= \'" + date_end + "\' ORDER BY code, date desc"; #print('select_sql:'+select_sql) rows = []; try: cursor.execute(select_sql) rows = cursor.fetchall() except Exception: print("select_stock_history_by_codes error:" + Exception) sqlUtil.db.close() return rows
def select_stock_history_by_code(self, code): sqlUtil = SqlUtil() sqlUtil.connect(); cursor = sqlUtil.db.cursor(); select_sql = "SELECT id, date, code, name, close, high, low, open, pre_close, up_down_price, up_down_range, turn_over_rate, bargain_volume, bargain_amount, total_market_value, flow_market_value, bargain_ticket_count FROM stock_history WHERE code = \'" + code + "\' ORDER BY date desc"; print('select_sql:'+select_sql) rows = []; try: cursor.execute(select_sql) rows = cursor.fetchall() except: print("Error: unable to fetch data") sqlUtil.db.close() return rows
def insert_stock_nows(self, now_values): sqlUtil = SqlUtil() sqlUtil.connect() cursor = sqlUtil.db.cursor() insert_sql = "INSERT INTO stock_now(time, code, name, price, high, low, open, pre_close, bargain_volume, bargain_amount) VALUES " + now_values + "" print('insert_stock_nows insert_sql = ' + insert_sql) try: cursor.execute(insert_sql) sqlUtil.db.commit() #print("insert_stock_history sucess"); except Exception as e: # 发生错误时回滚 sqlUtil.db.rollback() print("insert_stock_nows error:" + e) # 关闭数据库连接 sqlUtil.db.close()
def insert_stock_select(self, batch, code, name, type, remark): sqlUtil = SqlUtil() sqlUtil.connect() cursor = sqlUtil.db.cursor() insert_sql = "INSERT INTO stock_select(batch, code, name, type, remark) VALUES ( \'" + batch + "\', \'" + code + "\' , \'" + name + "\' , \'" + type + "\' , \'" + remark + "\')" print(insert_sql) try: cursor.execute(insert_sql) sqlUtil.db.commit() #print("insert_stock_history sucess"); except Exception as e: # 发生错误时回滚 sqlUtil.db.rollback() print("insert_stock_history error:" + e) # 关闭数据库连接 sqlUtil.db.close()
def insert_stock_concepts(self, concept_values): sqlUtil = SqlUtil() sqlUtil.connect() cursor = sqlUtil.db.cursor() insert_sql = "INSERT INTO stock_concept(concept, code, name) VALUES " + concept_values + "" print('insert_stock_concept insert_sql = ' + insert_sql) try: cursor.execute(insert_sql) sqlUtil.db.commit() # print("insert_stock_history sucess"); except Exception as e: # 发生错误时回滚 sqlUtil.db.rollback() print("insert_stock_concept error:" + e) # 关闭数据库连接 sqlUtil.db.close()
def insert_stock_historys(self, history_values): sqlUtil = SqlUtil() sqlUtil.connect(); cursor = sqlUtil.db.cursor(); insert_sql = "INSERT INTO stock_history(date, code, name, close, high, low, open, pre_close, up_down_price, up_down_range, turn_over_rate, bargain_volume, bargain_amount, total_market_value, flow_market_value, bargain_ticket_count) VALUES " + history_values + "" print('insert_stock_historys insert_sql = ' + insert_sql) try: cursor.execute(insert_sql); sqlUtil.db.commit(); # print("insert_stock_history sucess"); except Exception as e: # 发生错误时回滚 sqlUtil.db.rollback(); print("insert_stock_history error:" + e); # 关闭数据库连接 sqlUtil.db.close()
def calculate_moving_average(self): sqlUtil = SqlUtil() marketUtil = MarketUtil() rows = sqlUtil.select_stock() for row in rows: code = row[0] rows_all = sqlUtil.select_stock_history_by_code(code) rows_all_count = len(rows_all) if rows_all_count >= 5: date = rows_all[rows_all_count - 1][0] code = rows_all[rows_all_count - 1][1] ma5, ma13, ma21, vma50 = marketUtil.cal_ma(rows_all) print('date = ' + date) print('code = ' + code) print('ma5 = ' + str(ma5)) print('ma13 = ' + str(ma13)) print('ma21 = ' + str(ma21)) print('vma50 = ' + str(vma50)) sqlUtil.update_stock_history_ma(date, code, str(ma5), str(ma13), str(ma21), str(vma50))
def cal_ma(self, rows_all, day_count): sqlUtil = SqlUtil() rows_all_count = len(rows_all) print('rows_all_count = ' + str(rows_all_count)) ma_5 = 0 ma_13 = 0 ma_21 = 0 array_5 = [] array_13 = [] array_21 = [] index = 0 for row in rows_all: print(row) print(index) # ma_5 = 0 # if index >= 5: # array_5 = rows_all[index - 5 : index] # print(array_5) # close_sum_5 = 0 # for array_5_row in array_5: # close = float(array_5_row[3]) # close_sum_5 = close_sum_5 + close # ma_5 = close_sum_5 / 5 # # print('ma_5 = ' + str(ma_5)) ma_5 = 0 array_5 = rows_all[index:index + 5] print(array_5) close_sum_5 = 0 for array_5_row in array_5: close = float(array_5_row[3]) close_sum_5 = close_sum_5 + close ma_5 = close_sum_5 / 5 print('ma_5 = ' + str(ma_5)) # ma_13 = 0 # if index >= 13: # array_13 = rows_all[index - 13: index] # #print(array_13) # close_sum_13 = 0 # for array_13_row in array_13: # close = float(array_13_row[3]) # close_sum_13 = close_sum_13 + close # ma_13 = close_sum_13 / 13 # # print('ma_13 = ' + str(ma_13)) # # ma_21 = 0 # if index >= 21: # array_21 = rows_all[index - 21: index] # # close_sum_21 = 0 # for array_21_row in array_21: # close = float(array_21_row[3]) # close_sum_21 = close_sum_21 + close # ma_21 = close_sum_21 / 21 # # print('ma_21 = ' + str(ma_21)) # # # # index = index + 1
# for array_21_row in array_21: # close = float(array_21_row[3]) # close_sum_21 = close_sum_21 + close # ma_21 = close_sum_21 / 21 # # print('ma_21 = ' + str(ma_21)) # # # # index = index + 1 if __name__ == "__main__": sqlUtil = SqlUtil() ruleUtil = MaUtil() rows = sqlUtil.select_stock() # print('开始时间:%s' % datetime.now()) # # for row in rows: # code = row[0] # rows_all = sqlUtil.select_stock_history_by_code(code) # ruleUtil.rule_1Win9(rows_all) # # print('结束时间:%s' % datetime.now()) rows_all = sqlUtil.select_stock_history_by_code_desc('000858') ruleUtil.cal_ma(rows_all, 5)
def send_email(self, batch): sender = '*****@*****.**' # 发件人邮箱账号 passwd = 'wkbhiknpajjmbjie' # 发件人邮箱密码 #receiver = '[email protected];[email protected];[email protected]' # 收件人邮箱账号,我这边发送给自己 receiver = ["*****@*****.**", "*****@*****.**"] # 收件人邮箱账号,我这边发送给自己 #receiver = ["*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**"] # 收件人邮箱账号,我这边发送给自己 #receiver = '*****@*****.**' # 收件人邮箱账号,我这边发送给自己 #receiver = '*****@*****.**' # 收件人邮箱账号,我这边发送给自己 # now = int(time.time()) # timeStruct = time.localtime(now) # batch = time.strftime("%Y%m%d", timeStruct) sqlUtil = SqlUtil() rows = sqlUtil.select_stock_select(batch) lines = "" index = 1 for row in rows: industry = row[0] segment = row[1] code = row[2] code_href = '<a href = "http://stockpage.10jqka.com.cn/' + code + '">' + code + '</a>' name = row[3] sector = row[4] turn_over_rate = row[5] close = row[6] remark = row[7] line = "<tr><td>" + str( index ) + "</td><td>" + industry + "</td><td>" + segment + "</td><td>" + code_href + "</td><td>" + name + "</td><td>" + sector + "</td><td>" + turn_over_rate + "</td><td>" + close + "</td><td>" + remark + "</td></tr> " lines = lines + line index = index + 1 try: mail_msg = """ <table border = "1" > <tr><th>序号</th><th>所属行业</th><th>细分行业</th><th>代码</th><th>名称</th><th>板块</th><th>换手</th><th>价格</th><th>备注</th></tr> """ + lines + """ </table > """ msg = MIMEText(mail_msg, 'html', 'utf-8') subject = batch + "股票信息筛选" msg['Subject'] = Header(subject, 'utf-8') # 邮件的主题,也可以说是标题 msg['From'] = formataddr(["贤小哥", sender]) # 括号里的对应发件人邮箱昵称、发件人邮箱账号 #msg['To'] = formataddr(["FK", receiver]) # 括号里的对应收件人邮箱昵称、收件人邮箱账号 server = smtplib.SMTP_SSL("smtp.qq.com", 465) # 发件人邮箱中的SMTP服务器,端口是25 server.login(sender, passwd) # 括号中对应的是发件人邮箱账号、邮箱密码 server.sendmail(sender, receiver, msg.as_string()) # 括号中对应的是发件人邮箱账号、收件人邮箱账号、发送邮件 server.quit() # 关闭连接 print('邮件发送成功') except Exception as e: # 如果 try 中的语句没有执行,则会执行下面的 ret=False ret = False print('错误明细是', e) print('邮件发送失败')
import csv import re from src.util.sqlutil import SqlUtil if __name__ == "__main__": sqlUtil = SqlUtil() rows = sqlUtil.select_stock() for row in rows: csv_name = "data_1year/" + row[0] + ".csv" print(csv_name) with open(csv_name, 'r', encoding='gb2312') as f: reader = csv.reader(f) for row in reader: date = row[0] matchObj = re.search(r'[0-9]+', row[1], re.M | re.I) if matchObj: code = matchObj.group() else: code = '' name = row[2] close = row[3] high = row[4] low = row[5] open2 = row[6]
def rule_littleUp(self, rows_all, batch): # now = int(time.time()) # timeStruct = time.localtime(now) # batch = time.strftime("%Y%m%d", timeStruct) sqlUtil = SqlUtil() rule_day_count = 10 rows_all_count = len(rows_all) rows_target = rows_all[rows_all_count - rule_day_count:rows_all_count] rows_target_count = len(rows_target) close_targets = [] open_targets = [] for row in rows_target: print(row) close_targets.append(float(row[3])) open_targets.append(float(row[6])) print('******') print(close_targets) print('******') print(open_targets) print('******') if rows_target_count > 9: close_target_max = max(close_targets) close_target_min = min(close_targets) open_target_max = max(open_targets) open_target_min = min(open_targets) target_max = max([ close_target_max, close_target_min, open_target_max, open_target_min ]) target_min = min([ close_target_max, close_target_min, open_target_max, open_target_min ]) print('close_target_max = ' + str(close_target_max)) print('close_target_min = ' + str(close_target_min)) print('open_target_max = ' + str(open_target_max)) print('open_target_min = ' + str(open_target_min)) print('target_max = ' + str(target_max)) print('target_min = ' + str(target_min)) if target_max > 0: rateUp_target = (target_max - target_min) / target_max if rateUp_target < 0.1: close = float(rows_all[rows_all_count - 1][3]) high = float(rows_all[rows_all_count - 1][4]) low = float(rows_all[rows_all_count - 1][5]) open = float(rows_all[rows_all_count - 1][6]) turn_over_rate = float(rows_all[rows_all_count - 1][10]) upRate = 0 if open > 0: upRate = (close - open) / open if close > open: if upRate >= 0.05: remark = '最近9天涨幅小于20%,今天涨幅超过5%' code = rows_all[rows_all_count - 1][1] name = rows_all[rows_all_count - 1][2] sqlUtil.insert_stock_select( batch, code, name, '5', remark) print(remark) print(code) print(name) if turn_over_rate >= 3: remark = '最近9天涨幅小于20%,今天换手率超过3%' code = rows_all[rows_all_count - 1][1] name = rows_all[rows_all_count - 1][2] sqlUtil.insert_stock_select( batch, code, name, '5', remark) print(remark) print(code) print(name)
if len(rows_vma50) == 50: vma50 = volume_sum50 / 50 else: vma50 = '' # print('ma5 = ' + str(ma5)) # print('ma13 = ' + str(ma13)) # print('ma21 = ' + str(ma21)) # print('vma50 = ' + str(vma50)) date = rows_all[rows_all_count - 1][0] code = rows_all[rows_all_count - 1][1] return ma5, ma13, ma21, vma50 if __name__ == "__main__": sqlUtil = SqlUtil() rows_all = sqlUtil.select_stock_history_by_code('601318') marketUtil = MarketUtil() ma5, ma13, ma21, vma50 = marketUtil.cal_ma(rows_all) print('ma5 = ' + str(ma5)) print('ma13 = ' + str(ma13)) print('ma21 = ' + str(ma21)) print('vma50 = ' + str(vma50)) #marketUtil.cal_vma(rows_all)