mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-12 23:36:54 +08:00
fix rule_strategy bug
This commit is contained in:
@@ -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 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
|
# 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
|
# 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:
|
if order.direction == Order.SELL:
|
||||||
# sell stock
|
# sell stock
|
||||||
self.update_state_from_order(order, trade_val, cost, trade_price)
|
self.update_state_from_order(order, trade_val, cost, trade_price)
|
||||||
|
|||||||
@@ -138,6 +138,9 @@ class SBBStrategyBase(RuleStrategy, OrderEnhancement):
|
|||||||
// (self.trade_len - self.trade_index)
|
// (self.trade_len - self.trade_index)
|
||||||
* _amount_trade_unit
|
* _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:
|
if _order_amount:
|
||||||
self.trade_amount[(order.stock_id, order.direction)] -= _order_amount
|
self.trade_amount[(order.stock_id, order.direction)] -= _order_amount
|
||||||
@@ -167,6 +170,10 @@ class SBBStrategyBase(RuleStrategy, OrderEnhancement):
|
|||||||
* 2
|
* 2
|
||||||
* _amount_trade_unit
|
* _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:
|
if _order_amount:
|
||||||
_order_amount = min(_order_amount, self.trade_amount[(order.stock_id, order.direction)])
|
_order_amount = min(_order_amount, self.trade_amount[(order.stock_id, order.direction)])
|
||||||
self.trade_amount[(order.stock_id, order.direction)] -= _order_amount
|
self.trade_amount[(order.stock_id, order.direction)] -= _order_amount
|
||||||
|
|||||||
Reference in New Issue
Block a user