|
@@ -9,7 +9,7 @@ import datetime
|
|
auth('18019403367', 'Qwer4321')
|
|
auth('18019403367', 'Qwer4321')
|
|
|
|
|
|
stocks = list(get_all_securities(['stock'], date=dt.today().strftime('%Y-%m-%d')).index)
|
|
stocks = list(get_all_securities(['stock'], date=dt.today().strftime('%Y-%m-%d')).index)
|
|
-stocks = stocks[0:80]
|
|
|
|
|
|
+stocks = stocks[0:1]
|
|
|
|
|
|
start = dt.now()
|
|
start = dt.now()
|
|
# 确定级别
|
|
# 确定级别
|
|
@@ -37,7 +37,7 @@ for stock in stocks:
|
|
# 有历史数据
|
|
# 有历史数据
|
|
index_len = pd.read_sql_table('stk%s_%s' % (stock, fre), con=engine2).iloc[-1, 0]
|
|
index_len = pd.read_sql_table('stk%s_%s' % (stock, fre), con=engine2).iloc[-1, 0]
|
|
# 注意修改time delta
|
|
# 注意修改time delta
|
|
- startdate = pd.read_sql_table('stk%s_%s' % (stock, fre), con=engine2).iloc[-1, 1] + datetime.timedelta(days=1)
|
|
|
|
|
|
+ startdate = pd.read_sql_table('stk%s_%s' % (stock, fre), con=engine2).iloc[-1, 1]
|
|
thd.get_price = pd.read_sql_query(
|
|
thd.get_price = pd.read_sql_query(
|
|
'select date,open,close,high,low,volume,money from `stk%s_%s`' % (stock, fre), engine)
|
|
'select date,open,close,high,low,volume,money from `stk%s_%s`' % (stock, fre), engine)
|
|
thd.get_price = thd.get_price.loc[thd.get_price['date'] > startdate]
|
|
thd.get_price = thd.get_price.loc[thd.get_price['date'] > startdate]
|
|
@@ -64,66 +64,62 @@ for stock in stocks:
|
|
thd.df_day.iloc[-1, 3] = max(thd.df_day.iloc[-1, 3], thd.get_price.loc[i, 'high'])
|
|
thd.df_day.iloc[-1, 3] = max(thd.df_day.iloc[-1, 3], thd.get_price.loc[i, 'high'])
|
|
thd.df_day.iloc[-1, 4] = max(thd.df_day.iloc[-1, 4], thd.get_price.loc[i, 'low'])
|
|
thd.df_day.iloc[-1, 4] = max(thd.df_day.iloc[-1, 4], thd.get_price.loc[i, 'low'])
|
|
# 寻找顶底分型
|
|
# 寻找顶底分型
|
|
- # hlfx判断
|
|
|
|
- for x in range(index_len, len(thd.df_day.index)):
|
|
|
|
- m = x - 1
|
|
|
|
- # 底
|
|
|
|
- if ((thd.df_day.loc[x, 'high'] > thd.df_day.loc[x - 1, 'high']) and (
|
|
|
|
- thd.df_day.loc[x - 2, 'high'] > thd.df_day.loc[x - 1, 'high'])):
|
|
|
|
- # if ((stk.df_day.loc[i-2, 'date'] != stk.fxdf.iloc[-1,0]) and (stk.df_day.loc[i-3,'date'] != stk.fxdf.iloc[-1,0]) and (stk.df_day.loc[i-1,'date'] != stk.fxdf.iloc[-1,0])):
|
|
|
|
- # stk.fxdf = pd.concat([stk.fxdf, stk.df_day.iloc[[i]]], ignore_index=True)
|
|
|
|
- thd.df_day.loc[x, 'HL'] = 'L*'
|
|
|
|
- if x == len(thd.df_day.index) - 1:
|
|
|
|
- pass
|
|
|
|
- # print(stock, '$$$$$$$', '\n', thd.df_day.loc[x, 'date'], '考虑————买入!!')
|
|
|
|
- while m:
|
|
|
|
- if thd.df_day.loc[m, 'HL'] == 'H':
|
|
|
|
- if (x - m) > 3:
|
|
|
|
- thd.df_day.loc[x, 'HL'] = 'L'
|
|
|
|
- if x == len(thd.df_day.index) - 1:
|
|
|
|
- print(stock, '$$$$$$$', '\n', '买买买买买!!')
|
|
|
|
- break
|
|
|
|
- elif (thd.df_day.loc[m, 'HL'] == 'L'):
|
|
|
|
- if thd.df_day.loc[x - 1, 'low'] < thd.df_day.loc[m - 1, 'low']:
|
|
|
|
- # 前一个为底,且中间存在不包含 or 更低的底
|
|
|
|
- thd.df_day.loc[x, 'HL'] = 'L'
|
|
|
|
- if x == len(thd.df_day.index) - 1:
|
|
|
|
- print(stock, '$$$$$$$', '\n', '中继后的底————买吗?!')
|
|
|
|
|
|
+ if len(thd.df_day.index) > 2:
|
|
|
|
+ # 寻找顶底分型
|
|
|
|
+ for x in range(index_len, len(thd.df_day.index)):
|
|
|
|
+ m = x - 1
|
|
|
|
+ # 底
|
|
|
|
+ if ((thd.df_day.loc[x, 'high'] > thd.df_day.loc[x - 1, 'high']) and (
|
|
|
|
+ thd.df_day.loc[x - 2, 'high'] > thd.df_day.loc[x - 1, 'high'])):
|
|
|
|
+ # if ((stk.df_day.loc[i-2, 'date'] != stk.fxdf.iloc[-1,0]) and (stk.df_day.loc[i-3,'date'] != stk.fxdf.iloc[-1,0]) and (stk.df_day.loc[i-1,'date'] != stk.fxdf.iloc[-1,0])):
|
|
|
|
+ # stk.fxdf = pd.concat([stk.fxdf, stk.df_day.iloc[[i]]], ignore_index=True)
|
|
|
|
+ thd.df_day.loc[x, 'HL'] = 'L*'
|
|
|
|
+ while m:
|
|
|
|
+ if thd.df_day.loc[m, 'HL'] == 'H':
|
|
|
|
+ if (x - m) > 3:
|
|
|
|
+ thd.df_day.loc[x, 'HL'] = 'L'
|
|
|
|
+ if x == len(thd.df_day.index) - 1:
|
|
|
|
+ print(stock, '$$$$$$$', '\n', thd.df_day.loc[x, 'date'], '买买买买买!!')
|
|
break
|
|
break
|
|
- else:
|
|
|
|
|
|
+ elif (thd.df_day.loc[m, 'HL'] == 'L'):
|
|
|
|
+ if thd.df_day.loc[x - 1, 'low'] < thd.df_day.loc[m - 1, 'low']:
|
|
|
|
+ # 前一个为底,且中间存在不包含 or 更低的底
|
|
|
|
+ thd.df_day.loc[x, 'HL'] = 'L'
|
|
|
|
+ if x == len(thd.df_day.index) - 1:
|
|
|
|
+ # pass
|
|
|
|
+ print(stock, '$$$$$$$', '\n', thd.df_day.loc[x, 'date'], '中继后的底————买吗?!')
|
|
|
|
+ break
|
|
|
|
+ else:
|
|
|
|
+ break
|
|
|
|
+ m = m - 1
|
|
|
|
+ # 顶
|
|
|
|
+ elif ((thd.df_day.loc[x, 'high'] < thd.df_day.loc[x - 1, 'high']) and (
|
|
|
|
+ thd.df_day.loc[x - 2, 'high'] < thd.df_day.loc[x - 1, 'high'])):
|
|
|
|
+ # if ((stk.df_day.loc[i-2, 'date'] != stk.fxdf.iloc[-1,0]) and (stk.df_day.loc[i-3,'date'] != stk.fxdf.iloc[-1,0]) and (stk.df_day.loc[i-1,'date'] != stk.fxdf.iloc[-1,0])):
|
|
|
|
+ # stk.fxdf = pd.concat([stk.fxdf, stk.df_day.iloc[[i]]], ignore_index=True)
|
|
|
|
+ thd.df_day.loc[x, 'HL'] = 'H*'
|
|
|
|
+ while m:
|
|
|
|
+ if thd.df_day.loc[m, 'HL'] == 'L':
|
|
|
|
+ if x - m > 3:
|
|
|
|
+ thd.df_day.loc[x, 'HL'] = 'H'
|
|
|
|
+ if x == len(thd.df_day.index) - 1:
|
|
|
|
+ # print(stock, '!!!!!!!', '\n', '卖卖卖卖卖卖卖!')
|
|
|
|
+ pass
|
|
|
|
+ thd.df_day.loc[x, 9] = thd.df_day.loc[x, 'close'] - thd.df_day.loc[m, 'close']
|
|
break
|
|
break
|
|
- m = m - 1
|
|
|
|
-
|
|
|
|
- # 顶
|
|
|
|
- elif ((thd.df_day.loc[x, 'high'] < thd.df_day.loc[x - 1, 'high']) and (
|
|
|
|
- thd.df_day.loc[x - 2, 'high'] < thd.df_day.loc[x - 1, 'high'])):
|
|
|
|
- # if ((stk.df_day.loc[i-2, 'date'] != stk.fxdf.iloc[-1,0]) and (stk.df_day.loc[i-3,'date'] != stk.fxdf.iloc[-1,0]) and (stk.df_day.loc[i-1,'date'] != stk.fxdf.iloc[-1,0])):
|
|
|
|
- # stk.fxdf = pd.concat([stk.fxdf, stk.df_day.iloc[[i]]], ignore_index=True)
|
|
|
|
- thd.df_day.loc[x, 'HL'] = 'H*'
|
|
|
|
- if x == len(thd.df_day.index) - 1:
|
|
|
|
- # print(stock, '!!!!!!!', '\n', thd.df_day.loc[x, 'date'], '考虑————卖出!!')
|
|
|
|
- pass
|
|
|
|
- while m:
|
|
|
|
- if thd.df_day.loc[m, 'HL'] == 'L':
|
|
|
|
- if x - m > 3:
|
|
|
|
- thd.df_day.loc[x, 'HL'] = 'H'
|
|
|
|
- if x == len(thd.df_day.index) - 1:
|
|
|
|
- # print(stock, '!!!!!!!', '\n', '卖卖卖卖卖卖卖!')
|
|
|
|
- pass
|
|
|
|
- thd.df_day.loc[x, 9] = thd.df_day.loc[x, 'close'] - thd.df_day.loc[m, 'close']
|
|
|
|
- break
|
|
|
|
- elif (thd.df_day.loc[m, 'HL'] == 'H'):
|
|
|
|
- if thd.df_day.loc[x - 1, 'high'] > thd.df_day.loc[m - 1, 'high']:
|
|
|
|
- # 前一个为顶,且中间存在不包含 or 更高的顶
|
|
|
|
- thd.df_day.loc[x, 'HL'] = 'H'
|
|
|
|
- if x == len(thd.df_day.index) - 1:
|
|
|
|
- pass
|
|
|
|
- # print(stock, '/\/\/\/\/\/\/', '一顶更有一顶高!')
|
|
|
|
|
|
+ elif (thd.df_day.loc[m, 'HL'] == 'H'):
|
|
|
|
+ if thd.df_day.loc[x - 1, 'high'] > thd.df_day.loc[m - 1, 'high']:
|
|
|
|
+ # 前一个为顶,且中间存在不包含 or 更高的顶
|
|
|
|
+ thd.df_day.loc[x, 'HL'] = 'H'
|
|
|
|
+ if x == len(thd.df_day.index) - 1:
|
|
|
|
+ pass
|
|
|
|
+ # print(stock, '/\/\/\/\/\/\/', '一顶更有一顶高!')
|
|
|
|
+ break
|
|
break
|
|
break
|
|
- break
|
|
|
|
- m = m - 1
|
|
|
|
- else:
|
|
|
|
- thd.df_day.loc[x, 'HL'] = '-'
|
|
|
|
|
|
+ m = m - 1
|
|
|
|
+ else:
|
|
|
|
+ thd.df_day.loc[x, 'HL'] = '-'
|
|
|
|
+
|
|
# 更新数据库
|
|
# 更新数据库
|
|
thd.df_day[index_len + 1:].to_sql('stk%s_%s' % (stock, fre), con=engine2, index=True, if_exists='append')
|
|
thd.df_day[index_len + 1:].to_sql('stk%s_%s' % (stock, fre), con=engine2, index=True, if_exists='append')
|
|
else:
|
|
else:
|
|
@@ -151,68 +147,60 @@ for stock in stocks:
|
|
# 右高,上升
|
|
# 右高,上升
|
|
thd.df_day.iloc[-1, 3] = max(thd.df_day.iloc[-1, 3], thd.get_price.loc[i, 'high'])
|
|
thd.df_day.iloc[-1, 3] = max(thd.df_day.iloc[-1, 3], thd.get_price.loc[i, 'high'])
|
|
thd.df_day.iloc[-1, 4] = max(thd.df_day.iloc[-1, 4], thd.get_price.loc[i, 'low'])
|
|
thd.df_day.iloc[-1, 4] = max(thd.df_day.iloc[-1, 4], thd.get_price.loc[i, 'low'])
|
|
- # hlfx判断
|
|
|
|
- for x in thd.df_day.index:
|
|
|
|
- print(len(thd.df_day.index), x)
|
|
|
|
- m = x-1
|
|
|
|
- if x < 3:
|
|
|
|
- continue
|
|
|
|
- # 底
|
|
|
|
- elif ((thd.df_day.loc[x, 'high'] > thd.df_day.loc[x - 1, 'high']) and (
|
|
|
|
- thd.df_day.loc[x - 2, 'high'] > thd.df_day.loc[x - 1, 'high'])):
|
|
|
|
- # if ((stk.df_day.loc[i-2, 'date'] != stk.fxdf.iloc[-1,0]) and (stk.df_day.loc[i-3,'date'] != stk.fxdf.iloc[-1,0]) and (stk.df_day.loc[i-1,'date'] != stk.fxdf.iloc[-1,0])):
|
|
|
|
- # stk.fxdf = pd.concat([stk.fxdf, stk.df_day.iloc[[i]]], ignore_index=True)
|
|
|
|
- thd.df_day.loc[x, 'HL'] = 'L*'
|
|
|
|
- if x == len(thd.df_day.index) - 1:
|
|
|
|
- pass
|
|
|
|
- # print(stock, '$$$$$$$', '\n', thd.df_day.loc[x, 'date'], '考虑————买入!!')
|
|
|
|
- while m:
|
|
|
|
- if thd.df_day.loc[m, 'HL'] == 'H':
|
|
|
|
- if (x - m) > 3:
|
|
|
|
- thd.df_day.loc[x, 'HL'] = 'L'
|
|
|
|
- if x == len(thd.df_day.index) - 1:
|
|
|
|
- print(stock, '$$$$$$$', '\n', '买买买买买!!')
|
|
|
|
- break
|
|
|
|
- elif (thd.df_day.loc[m, 'HL'] == 'L'):
|
|
|
|
- if thd.df_day.loc[x - 1, 'low'] < thd.df_day.loc[m - 1, 'low']:
|
|
|
|
- # 前一个为底,且中间存在不包含 or 更低的底
|
|
|
|
- thd.df_day.loc[x, 'HL'] = 'L'
|
|
|
|
- if x == len(thd.df_day.index) - 1:
|
|
|
|
- print(stock, '$$$$$$$', '\n', '中继后的底————买吗?!')
|
|
|
|
|
|
+ if len(thd.df_day.index) > 2:
|
|
|
|
+ # 寻找顶底分型
|
|
|
|
+ for x in range(index_len, len(thd.df_day.index)):
|
|
|
|
+ m = x - 1
|
|
|
|
+ # 底
|
|
|
|
+ if ((thd.df_day.loc[x, 'high'] > thd.df_day.loc[x - 1, 'high']) and (
|
|
|
|
+ thd.df_day.loc[x - 2, 'high'] > thd.df_day.loc[x - 1, 'high'])):
|
|
|
|
+ # if ((stk.df_day.loc[i-2, 'date'] != stk.fxdf.iloc[-1,0]) and (stk.df_day.loc[i-3,'date'] != stk.fxdf.iloc[-1,0]) and (stk.df_day.loc[i-1,'date'] != stk.fxdf.iloc[-1,0])):
|
|
|
|
+ # stk.fxdf = pd.concat([stk.fxdf, stk.df_day.iloc[[i]]], ignore_index=True)
|
|
|
|
+ thd.df_day.loc[x, 'HL'] = 'L*'
|
|
|
|
+ while m:
|
|
|
|
+ if thd.df_day.loc[m, 'HL'] == 'H':
|
|
|
|
+ if (x - m) > 3:
|
|
|
|
+ thd.df_day.loc[x, 'HL'] = 'L'
|
|
|
|
+ if x == len(thd.df_day.index) - 1:
|
|
|
|
+ print(stock, '$$$$$$$', '\n', thd.df_day.loc[x, 'date'], '买买买买买!!')
|
|
break
|
|
break
|
|
- else:
|
|
|
|
|
|
+ elif (thd.df_day.loc[m, 'HL'] == 'L'):
|
|
|
|
+ if thd.df_day.loc[x - 1, 'low'] < thd.df_day.loc[m - 1, 'low']:
|
|
|
|
+ # 前一个为底,且中间存在不包含 or 更低的底
|
|
|
|
+ thd.df_day.loc[x, 'HL'] = 'L'
|
|
|
|
+ if x == len(thd.df_day.index) - 1:
|
|
|
|
+ # pass
|
|
|
|
+ print(stock, '$$$$$$$', '\n', thd.df_day.loc[x, 'date'], '中继后的底————买吗?!')
|
|
|
|
+ break
|
|
|
|
+ else:
|
|
|
|
+ break
|
|
|
|
+ m = m - 1
|
|
|
|
+ # 顶
|
|
|
|
+ elif ((thd.df_day.loc[x, 'high'] < thd.df_day.loc[x - 1, 'high']) and (
|
|
|
|
+ thd.df_day.loc[x - 2, 'high'] < thd.df_day.loc[x - 1, 'high'])):
|
|
|
|
+ # if ((stk.df_day.loc[i-2, 'date'] != stk.fxdf.iloc[-1,0]) and (stk.df_day.loc[i-3,'date'] != stk.fxdf.iloc[-1,0]) and (stk.df_day.loc[i-1,'date'] != stk.fxdf.iloc[-1,0])):
|
|
|
|
+ # stk.fxdf = pd.concat([stk.fxdf, stk.df_day.iloc[[i]]], ignore_index=True)
|
|
|
|
+ thd.df_day.loc[x, 'HL'] = 'H*'
|
|
|
|
+ while m:
|
|
|
|
+ if thd.df_day.loc[m, 'HL'] == 'L':
|
|
|
|
+ if x - m > 3:
|
|
|
|
+ thd.df_day.loc[x, 'HL'] = 'H'
|
|
|
|
+ if x == len(thd.df_day.index) - 1:
|
|
|
|
+ # print(stock, '!!!!!!!', '\n', '卖卖卖卖卖卖卖!')
|
|
|
|
+ pass
|
|
|
|
+ thd.df_day.loc[x, 9] = thd.df_day.loc[x, 'close'] - thd.df_day.loc[m, 'close']
|
|
break
|
|
break
|
|
- m = m - 1
|
|
|
|
-
|
|
|
|
- # 顶
|
|
|
|
- elif ((thd.df_day.loc[x, 'high'] < thd.df_day.loc[x - 1, 'high']) and (
|
|
|
|
- thd.df_day.loc[x - 2, 'high'] < thd.df_day.loc[x - 1, 'high'])):
|
|
|
|
- # if ((stk.df_day.loc[i-2, 'date'] != stk.fxdf.iloc[-1,0]) and (stk.df_day.loc[i-3,'date'] != stk.fxdf.iloc[-1,0]) and (stk.df_day.loc[i-1,'date'] != stk.fxdf.iloc[-1,0])):
|
|
|
|
- # stk.fxdf = pd.concat([stk.fxdf, stk.df_day.iloc[[i]]], ignore_index=True)
|
|
|
|
- thd.df_day.loc[x, 'HL'] = 'H*'
|
|
|
|
- if x == len(thd.df_day.index) - 1:
|
|
|
|
- # print(stock, '!!!!!!!', '\n', thd.df_day.loc[x, 'date'], '考虑————卖出!!')
|
|
|
|
- pass
|
|
|
|
- while m:
|
|
|
|
- if thd.df_day.loc[m, 'HL'] == 'L':
|
|
|
|
- if x - m > 3:
|
|
|
|
- thd.df_day.loc[x, 'HL'] = 'H'
|
|
|
|
- if x == len(thd.df_day.index) - 1:
|
|
|
|
- # print(stock, '!!!!!!!', '\n', '卖卖卖卖卖卖卖!')
|
|
|
|
- pass
|
|
|
|
- thd.df_day.loc[x, 9] = thd.df_day.loc[x, 'close'] - thd.df_day.loc[m, 'close']
|
|
|
|
- break
|
|
|
|
- elif (thd.df_day.loc[m, 'HL'] == 'H'):
|
|
|
|
- if thd.df_day.loc[x - 1, 'high'] > thd.df_day.loc[m - 1, 'high']:
|
|
|
|
- # 前一个为顶,且中间存在不包含 or 更高的顶
|
|
|
|
- thd.df_day.loc[x, 'HL'] = 'H'
|
|
|
|
- if x == len(thd.df_day.index) - 1:
|
|
|
|
- pass
|
|
|
|
- # print(stock, '/\/\/\/\/\/\/', '一顶更有一顶高!')
|
|
|
|
|
|
+ elif (thd.df_day.loc[m, 'HL'] == 'H'):
|
|
|
|
+ if thd.df_day.loc[x - 1, 'high'] > thd.df_day.loc[m - 1, 'high']:
|
|
|
|
+ # 前一个为顶,且中间存在不包含 or 更高的顶
|
|
|
|
+ thd.df_day.loc[x, 'HL'] = 'H'
|
|
|
|
+ if x == len(thd.df_day.index) - 1:
|
|
|
|
+ pass
|
|
|
|
+ # print(stock, '/\/\/\/\/\/\/', '一顶更有一顶高!')
|
|
|
|
+ break
|
|
break
|
|
break
|
|
- break
|
|
|
|
- m = m - 1
|
|
|
|
- else:
|
|
|
|
- thd.df_day.loc[x, 'HL'] = '-'
|
|
|
|
|
|
+ m = m - 1
|
|
|
|
+ else:
|
|
|
|
+ thd.df_day.loc[x, 'HL'] = '-'
|
|
# 更新数据库
|
|
# 更新数据库
|
|
thd.df_day.to_sql('stk%s_%s' % (stock, fre), con=engine2, index=True, if_exists='append')
|
|
thd.df_day.to_sql('stk%s_%s' % (stock, fre), con=engine2, index=True, if_exists='append')
|