-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add util function to help automatically get horizon #1509
base: main
Are you sure you want to change the base?
Changes from 10 commits
af4b68f
1146f17
d779bdd
dfe5045
d62206c
6767462
54d12f1
e3a6b2d
b3af983
091dae6
adb3d04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,12 @@ | |
""" | ||
This module covers some utility functions that operate on data or basic object | ||
""" | ||
import re | ||
from copy import deepcopy | ||
from typing import List, Union | ||
import pandas as pd | ||
|
||
import numpy as np | ||
import pandas as pd | ||
|
||
|
||
def robust_zscore(x: pd.Series, zscore=False): | ||
|
@@ -103,3 +105,19 @@ def update_config(base_config: dict, ext_config: Union[dict, List[dict]]): | |
# one of then are not dict. Then replace | ||
base_config[key] = ec[key] | ||
return base_config | ||
|
||
|
||
def guess_horizon(label): | ||
""" | ||
Try to guess the horizon by parsing label | ||
""" | ||
regex = r"Ref\(\s*\$[a-zA-Z]+,\s*-(\d+)\)" | ||
horizon_list = [int(x) for x in re.findall(regex, label)] | ||
|
||
if len(horizon_list) == 0: | ||
return 0 | ||
max_horizon = max(horizon_list) | ||
# Unlikely the label doesn't use future information | ||
if max_horizon < 2: | ||
return 0 | ||
return max_horizon + 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is consistent with exisiting deinition of "horizon" in other code like DDG-DA and TRA. There is no official documentation, TRA workflow config use max_horizon to truncate and DDG-DA use max_horizon + 1. I use max_horizon + 1 here just to make things safe. Any suggestion from qlib team? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we write it like this?
if isinstance(handler, (dict, str))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done