Skip to content

Commit 1c22ed1

Browse files
committed
简单修复了下bug
1 parent 6a1fd50 commit 1c22ed1

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

database/finhack_structure.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,4 @@ CREATE TABLE `rqalpha` (
255255
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
256256
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
257257

258-
-- Dump completed on 2024-09-10 1:12:17
258+
-- Dump completed on 2024-09-11 2:06:05

finhack/factor/default/indicatorCompute.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def computeListByStock(ts_code,list_name='all',where='',factor_list=None,c_list=
234234
single_factors_path=SINGLE_FACTORS_DIR+factor_name+'.csv'
235235
if os.path.isfile(single_factors_path):
236236
has_csv=True
237-
#df_factor没有此列,diff_date>100,且代码未发生变化,且存在csv
237+
#df_factor没有此列,diff_date>100,且代码未发生变化,或不存在csv
238238
if (not factor_name in df_factor.columns or diff_date>100 or has_csv==False) and (not factor_name in c_list):
239239
# if not factor_name in df_all.columns:
240240
if True:
@@ -243,7 +243,11 @@ def computeListByStock(ts_code,list_name='all',where='',factor_list=None,c_list=
243243
df_all[factor_name]=np.nan
244244
else:
245245
df_all=df_all_tmp
246-
246+
# print(factor_name)
247+
# print(df_all)
248+
249+
250+
247251
#否则计算250日数据
248252
else:
249253
if df_250 is None or isinstance(df_250, bool):
@@ -254,6 +258,9 @@ def computeListByStock(ts_code,list_name='all',where='',factor_list=None,c_list=
254258

255259

256260

261+
# print(df_all)
262+
# exit()
263+
257264
if(first_time):
258265
df_factor=df_all
259266
else:
@@ -346,12 +353,16 @@ def computeListByStock(ts_code,list_name='all',where='',factor_list=None,c_list=
346353

347354
#计算单个股票单个因子
348355
def computeFactorByStock(ts_code,factor_name,df_price=pd.DataFrame(),where='',db='tushare'):
356+
357+
349358
if(df_price.empty):
350359
df_price=AStock.getStockDailyPriceByCode(code=ts_code,where=where,db='tushare')
351360
#df_result=df_price.copy()
352361
if(df_price.empty):
353362
return pd.DataFrame()
354363

364+
if factor_name in df_price.columns:
365+
return df_price
355366

356367
indicators,func_name,code,return_fileds=indicatorCompute.getFactorInfo(factor_name)
357368

@@ -455,6 +466,8 @@ def computeFactorByStock(ts_code,factor_name,df_price=pd.DataFrame(),where='',db
455466
#print(suffix)
456467
#exit()
457468

469+
470+
458471
#如果返回多列,则需要同样进行shift计算
459472
if True:
460473
for f in rlist:
@@ -472,9 +485,10 @@ def computeFactorByStock(ts_code,factor_name,df_price=pd.DataFrame(),where='',db
472485
#print("f=%s,fs=%s" %(f,factor_name))
473486
#print(len(df.columns))
474487

488+
# print("hint")
475489
# print(factor_name)
476490
# print(df)
477-
491+
#exit()
478492
del df_price
479493
del func
480494
return df

finhack/factor/default/taskRunner.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,13 @@ def runTask(task_list):
2727
if True:
2828
for factor_list_name in task_list:
2929
#factor列表
30-
3130
if os.path.exists(CONFIG_DIR+"/factorlist/indicatorlist/"+factor_list_name):
3231

3332
with open(CONFIG_DIR+"/factorlist/indicatorlist/"+factor_list_name, 'r', encoding='utf-8') as f:
3433
factor_list=[_.rstrip('\n') for _ in f.readlines()]
35-
#print(factor_list)
3634
indicatorCompute.computeList(list_name=factor_list_name,factor_list=factor_list,c_list=c_list)
3735

38-
39-
40-
#continue
4136
#alpha列表
42-
4337
for factor_list_name in task_list:
4438
if os.path.exists(CONFIG_DIR+"/factorlist/alphalist/"+factor_list_name):
4539
with open(CONFIG_DIR+"/factorlist/alphalist/"+factor_list_name, 'r', encoding='utf-8') as f:
@@ -51,9 +45,8 @@ def runTask(task_list):
5145
i=i+1
5246
alpha_name=factor_list_name+'_'+str(i).zfill(3)
5347
mytask=pool.submit(alphaEngine.calc,factor,pd.DataFrame(),alpha_name,False,True)
54-
48+
5549
#alphaEngine.calc(factor,pd.DataFrame(),alpha_name)
56-
#exit()
5750
os.system('mv '+CACHE_DIR+'/single_factors_tmp2/* '+SINGLE_FACTORS_DIR)
5851
factorPkl.save()
5952

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
UPPER_0
2+
MIDDLE_0
3+
LOWER
4+
DEMA_0
5+
EMA_90_0
6+
HTTRENDLINE_0
7+
MACD
8+
MACDSIGNAL_0
9+
MACDHIST

0 commit comments

Comments
 (0)