1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-10 06:20:57 +08:00

Update CI & add black formatter

This commit is contained in:
Jactus
2020-10-09 14:33:29 +08:00
committed by you-n-g
parent 143f3f985b
commit 7c6e5e822c
26 changed files with 194 additions and 255 deletions

View File

@@ -1,4 +1,3 @@
import sys
from pathlib import Path
import qlib
@@ -10,7 +9,6 @@ from qlib.utils import exists_qlib_data
class TestDataset(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
# use default data
@@ -24,9 +22,9 @@ class TestDataset(unittest.TestCase):
qlib.init(provider_uri=provider_uri, region=REG_CN)
def testCSI300(self):
close_p = D.features(D.instruments('csi300'), ['$close'])
size = close_p.groupby('datetime').size()
cnt = close_p.groupby('datetime').count()['$close']
close_p = D.features(D.instruments("csi300"), ["$close"])
size = close_p.groupby("datetime").size()
cnt = close_p.groupby("datetime").count()["$close"]
size_desc = size.describe(percentiles=np.arange(0.1, 1.0, 0.1))
cnt_desc = cnt.describe(percentiles=np.arange(0.1, 1.0, 0.1))
@@ -35,22 +33,21 @@ class TestDataset(unittest.TestCase):
self.assertLessEqual(size_desc.loc["max"], 305, "Excessive number of CSI300 constituent stocks")
self.assertGreaterEqual(size_desc.loc["80%"], 290, "Insufficient number of CSI300 constituent stocks")
self.assertLessEqual(cnt_desc.loc["max"], 305, "Excessive number of CSI300 constituent stocks")
# FIXME: Due to the low quality of data. Hard to make sure there are enough data
# self.assertEqual(cnt_desc.loc["80%"], 300, "Insufficient number of CSI300 constituent stocks")
def testClose(self):
close_p = D.features(D.instruments('csi300'), ['Ref($close, 1)/$close - 1'])
close_p = D.features(D.instruments("csi300"), ["Ref($close, 1)/$close - 1"])
close_desc = close_p.describe(percentiles=np.arange(0.1, 1.0, 0.1))
print(close_desc)
self.assertLessEqual(abs(close_desc.loc["90%"][0]), 0.1, "Close value is abnormal")
self.assertLessEqual(abs(close_desc.loc["10%"][0]), 0.1, "Close value is abnormal")
# FIXME: The yahoo data is not perfect. We have to
# FIXME: The yahoo data is not perfect. We have to
# self.assertLessEqual(abs(close_desc.loc["max"][0]), 0.2, "Close value is abnormal")
# self.assertGreaterEqual(close_desc.loc["min"][0], -0.2, "Close value is abnormal")
if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()