|
@@ -33,27 +33,32 @@ stocks = list(get_all_securities(['stock'], date='2021-12-31').index)
|
|
|
|
|
|
thd = threading.local()
|
|
|
|
|
|
-def qbh(stocks):
|
|
|
+
|
|
|
+def qbh(stocks , engine):
|
|
|
for stock in stocks:
|
|
|
print(stock)
|
|
|
thd.new_df = pd.DataFrame(columns=('date', 'open', 'close', 'high', 'low', 'volume', 'money', 'HL'))
|
|
|
# print(new_df.head())
|
|
|
- thd.df_day = stk['stk'+stock[:6]]
|
|
|
+ thd.df_day = stk['stk' + stock[:6]]
|
|
|
for i in thd.df_day.index:
|
|
|
if i == 0 or i == 1:
|
|
|
thd.new_df = pd.concat([thd.new_df, thd.df_day.iloc[[i]]], ignore_index=True)
|
|
|
# 不包含
|
|
|
- elif (thd.new_df.iloc[-1, 3]>thd.df_day.loc[i, 'high'] and thd.new_df.iloc[-1,4] > thd.df_day.loc[i, 'low']) or (thd.new_df.iloc[-1, 3] < thd.df_day.loc[i, 'high'] and thd.new_df.iloc[-1, 4] < thd.df_day.loc[i, 'low']):
|
|
|
+ elif (thd.new_df.iloc[-1, 3] > thd.df_day.loc[i, 'high']
|
|
|
+ and thd.new_df.iloc[-1, 4] > thd.df_day.loc[i, 'low']) \
|
|
|
+ or (thd.new_df.iloc[-1, 3] < thd.df_day.loc[i, 'high']
|
|
|
+ and thd.new_df.iloc[-1, 4] < thd.df_day.loc[i, 'low']):
|
|
|
thd.new_df = pd.concat([thd.new_df, thd.df_day.iloc[[i]]], ignore_index=True)
|
|
|
# 包含
|
|
|
- else: # (new_df.iloc[-1,3]>=df_day.loc[i,'high'] and new_df.iloc[-1,4]<= df_day.loc[i,'low']):
|
|
|
+ else:
|
|
|
+ # (new_df.iloc[-1,3]>=df_day.loc[i,'high'] and new_df.iloc[-1,4]<= df_day.loc[i,'low']):
|
|
|
if thd.new_df.iloc[-2, 3] > thd.new_df.iloc[-1, 3]: #左高,下降
|
|
|
thd.new_df.iloc[-1, 3] = min(thd.new_df.iloc[-1, 3], thd.df_day.loc[i, 'high'])
|
|
|
thd.new_df.iloc[-1, 4] = min(thd.new_df.iloc[-1, 4], thd.df_day.loc[i, 'low'])
|
|
|
- else:#右高,上升
|
|
|
+ else:
|
|
|
+ # 右高,上升
|
|
|
thd.new_df.iloc[-1, 3] = max(thd.new_df.iloc[-1, 3], thd.df_day.loc[i, 'high'])
|
|
|
thd.new_df.iloc[-1, 4] = max(thd.new_df.iloc[-1, 4], thd.df_day.loc[i, 'low'])
|
|
|
-
|
|
|
thd.new_df.to_sql('stk%s_%s' % (stock[:6], u), con=engine, index=True, if_exists='replace')
|
|
|
with engine.connect() as con:
|
|
|
con.execute('ALTER TABLE stk%s_%s ADD PRIMARY KEY (`date`);'% (stock[:6], u))
|
|
@@ -64,6 +69,7 @@ def qbh(stocks):
|
|
|
|
|
|
#return new_df
|
|
|
|
|
|
+
|
|
|
stk = locals()
|
|
|
engine = locals()
|
|
|
|
|
@@ -86,4 +92,4 @@ print("#########################################################################
|
|
|
|
|
|
for m in range(0, len(stocks), 50):
|
|
|
engine[m] = create_engine('mysql+pymysql://root:r6kEwqWU9!v3@localhost:3307/qbh_hlfx?charset=utf8', pool_recycle=3600)
|
|
|
- threading.Thread(target=qbh, args=(stocks[m:m + 50], )).start()
|
|
|
+ threading.Thread(target=qbh, args=(stocks[m:m + 50], engine[m])).start()
|