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

fix sum index data bug

This commit is contained in:
Young
2021-09-02 00:45:04 +00:00
parent f71b0c1189
commit 88d2f9263e
3 changed files with 4 additions and 2 deletions

View File

@@ -492,7 +492,7 @@ class BaseTradeDecision:
for obj in self.get_decision():
if isinstance(obj, Order):
# Zero amount order will be treated as empty
if not np.isclose(obj.amount, 0.0):
if obj.amount > 1e-6:
return False
else:
return True

View File

@@ -74,7 +74,7 @@ def sum_by_index(data_list: Union["SingleData"], new_index: list, fill_value=0)
for id in new_index:
item_sum = 0
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]
else:
item_sum += fill_value

View File

@@ -107,6 +107,8 @@ class IndexDataTest(unittest.TestCase):
self.assertTrue(np.isnan((sd1 + sd2).iloc[3]))
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):
pass
# here are some examples which do not affect the current system, but it is weird not to support it