mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-13 15:56:57 +08:00
fix sum index data bug
This commit is contained in:
@@ -492,7 +492,7 @@ class BaseTradeDecision:
|
|||||||
for obj in self.get_decision():
|
for obj in self.get_decision():
|
||||||
if isinstance(obj, Order):
|
if isinstance(obj, Order):
|
||||||
# Zero amount order will be treated as empty
|
# Zero amount order will be treated as empty
|
||||||
if not np.isclose(obj.amount, 0.0):
|
if obj.amount > 1e-6:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ def sum_by_index(data_list: Union["SingleData"], new_index: list, fill_value=0)
|
|||||||
for id in new_index:
|
for id in new_index:
|
||||||
item_sum = 0
|
item_sum = 0
|
||||||
for data in data_list:
|
for data in data_list:
|
||||||
if id in data and data[id] != np.NaN:
|
if id in data and not np.isnan(data[id]):
|
||||||
item_sum += data[id]
|
item_sum += data[id]
|
||||||
else:
|
else:
|
||||||
item_sum += fill_value
|
item_sum += fill_value
|
||||||
|
|||||||
@@ -107,6 +107,8 @@ class IndexDataTest(unittest.TestCase):
|
|||||||
self.assertTrue(np.isnan((sd1 + sd2).iloc[3]))
|
self.assertTrue(np.isnan((sd1 + sd2).iloc[3]))
|
||||||
self.assertTrue(sd1.add(sd2).sum() == 13)
|
self.assertTrue(sd1.add(sd2).sum() == 13)
|
||||||
|
|
||||||
|
self.assertTrue(idd.sum_by_index([sd1, sd2], sd1.index, fill_value=0.0).sum() == 13)
|
||||||
|
|
||||||
def test_todo(self):
|
def test_todo(self):
|
||||||
pass
|
pass
|
||||||
# here are some examples which do not affect the current system, but it is weird not to support it
|
# here are some examples which do not affect the current system, but it is weird not to support it
|
||||||
|
|||||||
Reference in New Issue
Block a user