Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion qlib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from typing import Callable, Optional, Union
from typing import TYPE_CHECKING

from qlib.constant import REG_CN, REG_US, REG_TW
from qlib.constant import REG_CN, REG_IN, REG_US, REG_TW

if TYPE_CHECKING:
from qlib.utils.time import Freq
Expand Down Expand Up @@ -303,6 +303,11 @@ def register_from_C(config, skip_register=True):
"limit_threshold": None,
"deal_price": "close",
},
REG_IN: {
"trade_unit": 1,
"limit_threshold": None,
"deal_price": "close",
},
REG_TW: {
"trade_unit": 1000,
"limit_threshold": 0.1,
Expand Down
1 change: 1 addition & 0 deletions qlib/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
REG_CN = "cn"
REG_US = "us"
REG_TW = "tw"
REG_IN = "in"

# Epsilon for avoiding division by zero.
EPS = 1e-12
Expand Down
2 changes: 1 addition & 1 deletion qlib/tests/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def qlib_data(
interval: str
data freq, value from [1d], by default 1d
region: str
data region, value from [cn, us], by default cn
data region, value from [cn, us, in], by default cn
delete_old: bool
delete an existing directory, by default True
exists_skip: bool
Expand Down
22 changes: 21 additions & 1 deletion qlib/utils/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import pandas as pd

from qlib.config import C
from qlib.constant import REG_CN, REG_TW, REG_US
from qlib.constant import REG_CN, REG_IN, REG_TW, REG_US


CN_TIME = [
Expand All @@ -26,6 +26,10 @@
datetime.strptime("9:00", "%H:%M"),
datetime.strptime("13:30", "%H:%M"),
]
IN_TIME = [
datetime.strptime("9:15", "%H:%M"),
datetime.strptime("15:30", "%H:%M"),
]


@functools.lru_cache(maxsize=240)
Expand Down Expand Up @@ -65,6 +69,11 @@ def get_min_cal(shift: int = 0, region: str = REG_CN) -> List[time]:
pd.date_range(US_TIME[0], US_TIME[1] - timedelta(minutes=1), freq="1min") - pd.Timedelta(minutes=shift)
):
cal.append(ts.time())
elif region == REG_IN:
for ts in list(
pd.date_range(IN_TIME[0], IN_TIME[1] - timedelta(minutes=1), freq="1min") - pd.Timedelta(minutes=shift)
):
cal.append(ts.time())
else:
raise ValueError(f"{region} is not supported")
return cal
Expand Down Expand Up @@ -107,6 +116,12 @@ def is_single_value(start_time, end_time, freq, region: str = REG_CN):
if start_time.hour == 15 and start_time.minute == 59 and start_time.second == 0:
return True
return False
elif region == REG_IN:
if end_time - start_time < freq:
return True
if start_time.hour == 15 and start_time.minute == 29 and start_time.second == 0:
return True
return False
else:
raise NotImplementedError(f"please implement the is_single_value func for {region}")

Expand Down Expand Up @@ -276,6 +291,11 @@ def time_to_day_index(time_obj: Union[str, datetime], region: str = REG_CN):
return int((time_obj - TW_TIME[0]).total_seconds() / 60)
else:
raise ValueError(f"{time_obj} is not the opening time of the {region} stock market")
elif region == REG_IN:
if IN_TIME[0] <= time_obj < IN_TIME[1]:
return int((time_obj - IN_TIME[0]).total_seconds() / 60)
else:
raise ValueError(f"{time_obj} is not the opening time of the {region} stock market")
else:
raise ValueError(f"{region} is not supported")

Expand Down
8 changes: 4 additions & 4 deletions tests/misc/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from qlib import init
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.constant import REG_CN, REG_IN, REG_US, REG_TW
from qlib.utils.time import cal_sam_minute as cal_sam_minute_new, get_min_cal, CN_TIME, IN_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}
REG_MAP = {REG_CN: CN_TIME, REG_US: US_TIME, REG_TW: TW_TIME, REG_IN: IN_TIME}


def cal_sam_minute(x: pd.Timestamp, sam_minutes: int, region: str):
Expand Down Expand Up @@ -77,7 +77,7 @@ def setUpClass(cls):
def test_cal_sam_minute(self):
# test the correctness of the code
random_n = 1000
regions = [REG_CN, REG_US, REG_TW]
regions = [REG_CN, REG_US, REG_TW, REG_IN]

def gen_args(cal: List):
for time in np.random.choice(cal, size=random_n, replace=True):
Expand Down