1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-10 14:26:56 +08:00

Add util function to help automatically get horizon (#1509)

* Add util function to help automatically get horizon

* Reformat for CI

* Leverage horizon change

* Udpate config yaml

* Update for formatting

* Adapt to pickled handler

* Fix CI error

* remove blank

* Fix lint

* Update tests

* Remove redundant check

* modify the code as suggested

* format code with pylint

* fix pytest error

---------

Co-authored-by: Linlang <Lv.Linlang@hotmail.com>
This commit is contained in:
Di
2025-05-26 22:08:43 +08:00
committed by GitHub
parent 89ae312109
commit 14d54aa2a1
6 changed files with 43 additions and 4 deletions

View File

@@ -9,6 +9,7 @@ from qlib.config import C
from qlib.log import TimeInspector
from qlib.constant import REG_CN, REG_US, REG_TW
from qlib.utils.time import cal_sam_minute as cal_sam_minute_new, get_min_cal, CN_TIME, US_TIME, TW_TIME
from qlib.utils.data import guess_horizon
REG_MAP = {REG_CN: CN_TIME, REG_US: US_TIME, REG_TW: TW_TIME}
@@ -112,5 +113,24 @@ class TimeUtils(TestCase):
cal_sam_minute_new(*args, region=region)
class DataUtils(TestCase):
@classmethod
def setUpClass(cls):
init()
def test_guess_horizon(self):
label = ["Ref($close, -2) / Ref($close, -1) - 1"]
result = guess_horizon(label)
assert result == 2
label = ["Ref($close, -5) / Ref($close, -1) - 1"]
result = guess_horizon(label)
assert result == 5
label = ["Ref($close, -1) / Ref($close, -1) - 1"]
result = guess_horizon(label)
assert result == 1
if __name__ == "__main__":
unittest.main()