From 7d32321d066d5174fb9a8afe2ba7c0d677738c57 Mon Sep 17 00:00:00 2001
From: xiahaoyuan <xiahaoyuan@citics.com>
Date: Fri, 13 Oct 2023 15:12:10 +0800
Subject: [PATCH] fixamount

---
 qlib/backtest/position.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qlib/backtest/position.py b/qlib/backtest/position.py
index 18b084fb64..ad433e3cbd 100644
--- a/qlib/backtest/position.py
+++ b/qlib/backtest/position.py
@@ -354,7 +354,7 @@ def _sell_stock(self, stock_id: str, trade_val: float, cost: float, trade_price:
         if stock_id not in self.position:
             raise KeyError("{} not in current position".format(stock_id))
         else:
-            if np.isclose(self.position[stock_id]["amount"], trade_amount):
+            if np.isclose(self.position[stock_id]["amount"], trade_amount) or self.position[stock_id]["amount"] <= trade_amount:
                 # Selling all the stocks
                 # we use np.isclose instead of abs(<the final amount>) <= 1e-5  because `np.isclose` consider both
                 # relative amount and absolute amount