程序如下:
print("开始在线测试!") while True: api.wait_update() current = datetime.datetime.strptime(quote.datetime, "%Y-%m-%d %H:%M:%S.%f") # 当前quote的时间 if api.is_changing(quote): # 出场 if position.pos_long > 0 or position.pos_short > 0: if abs(position.float_profit_long) >= take_profit or abs(position.float_profit_short) >= take_profit: target_pos.set_target_volume(0) if api.is_changing(klines.iloc[-1], 'datetime'): # 入场 if is_allow_trade(current): if position.pos_long == 0 and position.pos_short == 0: prediction = get_prediction_data(klines) assert not np.isnan(prediction).any() prediction = np.asarray([prediction], np.float32) X = [prediction for _ in range(6)] probs = model.predict(X)[0] print(probs) action = np.argmax(probs) buy = probs[1] sell = probs[2] if action == 1 and buy > 0.5: print("多单") target_pos.set_target_volume(1) elif action == 2 and sell > 0.5: print("空单") target_pos.set_target_volume(-1) <img src="https://www.shinnytech.com/wp-content/uploads/anspress-temp/0ab14b3273d3f64da7fb343f1d7e6da203a7b71f_2151.png" />
ringo 已回答的问题 2021年3月29日