|
@@ -70,18 +70,20 @@ def his_vol(stock, num):
|
|
|
return df['volume_front'].iloc[num]
|
|
|
|
|
|
|
|
|
-def ma_judge(data, stock_list, results):
|
|
|
+def ma_judge(data, stock_list, rate, results):
|
|
|
print(f'这个ma_judge的PID为:{os.getpid()},收到的data数据为:{len(data.keys())},stock_pool长度为{len(stock_list)},now is {dt.now()}')
|
|
|
list_judge = list(set(data.keys()) & set(stock_list))
|
|
|
print(f'本轮计算:{len(list_judge)}个股')
|
|
|
for stock in list_judge:
|
|
|
i = stock.replace('XSHG', 'SH').replace('XSHE', 'SZ')
|
|
|
current_price, open_price = data[i]['lastPrice'], data[i]['open']
|
|
|
- MA5, MA10, MA20 = ma(i, 5, data), ma(i, 10, data), ma(i, 20, data)
|
|
|
+ MA5, MA10, MA20, MA30, MA60, MA120 = ma(i, 5, data), ma(i, 10, data), ma(i, 20, data), ma(i, 30, data),\
|
|
|
+ ma(i, 60, data), ma(i, 120, data)
|
|
|
MA5_1 = ma_1(i, 5)
|
|
|
# print(i, current_price, open_price, MA5, MA10, MA20, MA5_1)
|
|
|
+ # 入交易池标准:阳线\大于MA5\MA5向上\MA20<MA10\离120线有距离
|
|
|
if (current_price > open_price) & (current_price > MA5) & (MA5 > MA5_1) & (current_price < MA5 * 1.03) & (
|
|
|
- MA20 < MA10):
|
|
|
+ MA20 < MA10) & (current_price > MA120 or current_price < MA120*rate):
|
|
|
if his_vol(i, -1) > his_vol(i, -2):
|
|
|
results.append(i.replace('SH', 'XSHG').replace('SZ', 'XSHE'))
|
|
|
print('RRRRRRR,', results)
|
|
@@ -111,6 +113,10 @@ def sell_trader(data, positions_dict):
|
|
|
print(f'本轮没有持仓股票信息!')
|
|
|
|
|
|
|
|
|
+def get_fundamentals(results):
|
|
|
+ return results
|
|
|
+ pass
|
|
|
+
|
|
|
def buy_trader(data, positions):
|
|
|
print('买入函数:', dt.now(), f'接受到{len(data.keys())}个个股')
|
|
|
results = mp.Manager().list()
|
|
@@ -141,8 +147,9 @@ def buy_trader(data, positions):
|
|
|
|
|
|
step = math.ceil(len(stock_pool) / (mp.cpu_count()/2))
|
|
|
print('step:', step)
|
|
|
+ rate = 0.8
|
|
|
for i in range(0, len(stock_pool), step):
|
|
|
- p = mp.Process(target=ma_judge, args=(data, stock_pool[i:i + step], results))
|
|
|
+ p = mp.Process(target=ma_judge, args=(data, stock_pool[i:i + step], rate, results))
|
|
|
mp_list.append(p)
|
|
|
p.start()
|
|
|
for j in mp_list:
|
|
@@ -152,6 +159,8 @@ def buy_trader(data, positions):
|
|
|
|
|
|
# 选择板块
|
|
|
if len(results) != 0:
|
|
|
+ # 基本面过滤
|
|
|
+ results = get_fundamentals(results)
|
|
|
num_industry = get_industry(results)
|
|
|
print(num_industry)
|
|
|
industry_list = []
|
|
@@ -184,13 +193,15 @@ def buy_trader(data, positions):
|
|
|
new_keep_stock = [stock.replace('XSHG', 'SH').replace('XSHE', 'SZ') for stock in keep_stocks]
|
|
|
print(f'new_keep_stock is:{len(new_keep_stock)},{new_keep_stock}')
|
|
|
|
|
|
- max_pos = 15
|
|
|
+
|
|
|
+ #进入购买程序
|
|
|
+ max_pos = 7
|
|
|
for stock in new_keep_stock:
|
|
|
asset = xt_trader.query_stock_asset(acc)
|
|
|
cash = asset.cash
|
|
|
- if cash > 2000 and len(positions) < max_pos:
|
|
|
- if stock in new_keep_stock:
|
|
|
- current_price = data[stock]['lastPrice']
|
|
|
+ if stock in new_keep_stock:
|
|
|
+ current_price = data[stock]['lastPrice']
|
|
|
+ if cash > 5000 and len(positions) < max_pos and current_price > 9:
|
|
|
volume = int((cash / 2 / current_price) // 100 * 100)
|
|
|
print('买入信号!!!!!!', stock, volume, current_price)
|
|
|
order_id = xt_trader.order_stock(acc, stock, xtconstant.STOCK_BUY, volume, xtconstant.LATEST_PRICE,
|