1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-02 02:21:18 +08:00

fix rule_strategy bug

This commit is contained in:
bxdd
2021-05-13 22:39:19 +08:00
parent c703dabcc7
commit de2658a8db
2 changed files with 7 additions and 1 deletions

View File

@@ -153,7 +153,6 @@ class Account:
# if stock is sold out, no stock price information in Position, then we should update account first, then update current position
# if stock is bought, there is no stock in current position, update current, then update account
# The cost will be substracted from the cash at last. So the trading logic can ignore the cost calculation
trade_amount = trade_val / trade_price
if order.direction == Order.SELL:
# sell stock
self.update_state_from_order(order, trade_val, cost, trade_price)

View File

@@ -138,6 +138,9 @@ class SBBStrategyBase(RuleStrategy, OrderEnhancement):
// (self.trade_len - self.trade_index)
* _amount_trade_unit
)
if order.direction == order.SELL:
if self.trade_amount[(order.stock_id, order.direction)] > 1e-5 and _order_amount is None:
_order_amount = self.trade_amount[(order.stock_id, order.direction)]
if _order_amount:
self.trade_amount[(order.stock_id, order.direction)] -= _order_amount
@@ -167,6 +170,10 @@ class SBBStrategyBase(RuleStrategy, OrderEnhancement):
* 2
* _amount_trade_unit
)
if order.direction == order.SELL:
if self.trade_amount[(order.stock_id, order.direction)] > 1e-5 and _order_amount is None:
_order_amount = self.trade_amount[(order.stock_id, order.direction)]
if _order_amount:
_order_amount = min(_order_amount, self.trade_amount[(order.stock_id, order.direction)])
self.trade_amount[(order.stock_id, order.direction)] -= _order_amount