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

[807] Move the REG_CONSTANT/EPS to constant.py. (#811)

* [807] Move the REG_CONSTANT to constant.py.

* import REG_US.

* Move EPS to constant.py.
This commit is contained in:
Chia-hung Tai
2022-01-09 21:39:46 +08:00
committed by GitHub
parent 382ababc01
commit 184ce34a34
26 changed files with 42 additions and 35 deletions

View File

@@ -14,7 +14,8 @@ import numpy as np
import pandas as pd
from ..data.data import D
from ..config import C, REG_CN
from ..config import C
from ..constant import REG_CN
from ..log import get_module_logger
from .decision import Order, OrderDir, OrderHelper
from .high_performance_ds import BaseQuote, PandasQuote, NumpyQuote

View File

@@ -22,6 +22,8 @@ from pathlib import Path
from typing import Optional, Union
from typing import TYPE_CHECKING
from qlib.constant import REG_CN, REG_US
if TYPE_CHECKING:
from qlib.utils.time import Freq
@@ -74,10 +76,6 @@ class Config:
self.update(**config_c.__dict__["_config"])
# REGION CONST
REG_CN = "cn"
REG_US = "us"
# pickle.dump protocol version: https://docs.python.org/3/library/pickle.html#data-stream-format
PROTOCOL_VERSION = 4

9
qlib/constant.py Normal file
View File

@@ -0,0 +1,9 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# REGION CONST
REG_CN = "cn"
REG_US = "us"
# Epsilon for avoiding division by zero.
EPS = 1e-12

View File

@@ -25,6 +25,7 @@ except:
from tqdm import tqdm
from qlib.utils import get_or_create_path
from qlib.constant import EPS
from qlib.log import get_module_logger
from qlib.model.base import Model
from qlib.contrib.data.dataset import MTSDatasetH
@@ -791,7 +792,7 @@ def minmax_norm(x):
xmin = x.min(dim=-1, keepdim=True).values
xmax = x.max(dim=-1, keepdim=True).values
mask = (xmin == xmax).squeeze()
x = (x - xmin) / (xmax - xmin + 1e-12)
x = (x - xmin) / (xmax - xmin + EPS)
x[mask] = 1
return x

View File

@@ -5,15 +5,12 @@ import abc
from typing import Union, Text
import numpy as np
import pandas as pd
import copy
from ...log import TimeInspector
from ...constant import EPS
from .utils import fetch_df_by_index
from ...utils.serial import Serializable
from ...utils.paral import datetime_groupby_apply
EPS = 1e-12
def get_group_columns(df: pd.DataFrame, group: Union[Text, None]):
"""

View File

@@ -1,7 +1,7 @@
import unittest
from .data import GetData
from .. import init
from ..config import REG_CN
from ..constant import REG_CN
class TestAutoData(unittest.TestCase):