mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-11 23:06:58 +08:00
fix little bug
This commit is contained in:
@@ -15,7 +15,7 @@ from ..config import C, REG_CN
|
|||||||
from ..utils.resam import resam_ts_data, ts_data_last
|
from ..utils.resam import resam_ts_data, ts_data_last
|
||||||
from ..log import get_module_logger
|
from ..log import get_module_logger
|
||||||
from .order import Order, OrderDir, OrderHelper
|
from .order import Order, OrderDir, OrderHelper
|
||||||
from .high_performane_ds import PandasQuote
|
from .high_performance_ds import PandasQuote
|
||||||
|
|
||||||
|
|
||||||
class Exchange:
|
class Exchange:
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ class BaseQuote:
|
|||||||
Iterable
|
Iterable
|
||||||
all stock codes
|
all stock codes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
raise NotImplementedError(f"Please implement the `get_all_stock` method")
|
raise NotImplementedError(f"Please implement the `get_all_stock` method")
|
||||||
|
|
||||||
def get_data(
|
def get_data(
|
||||||
@@ -119,76 +120,80 @@ class BaseSingleMetric:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, metric: Union[dict, pd.Series]):
|
def __init__(self, metric: Union[dict, pd.Series]):
|
||||||
pass
|
raise NotImplementedError(f"Please implement the `__init__` method")
|
||||||
|
|
||||||
def __add__(self, other: Union["BaseSingleMetric", int, float]) -> "BaseSingleMetric":
|
def __add__(self, other: Union["BaseSingleMetric", int, float]) -> "BaseSingleMetric":
|
||||||
pass
|
raise NotImplementedError(f"Please implement the `__add__` method")
|
||||||
|
|
||||||
def __radd__(self, other: Union["BaseSingleMetric", int, float]) -> "BaseSingleMetric":
|
def __radd__(self, other: Union["BaseSingleMetric", int, float]) -> "BaseSingleMetric":
|
||||||
return self + other
|
return self + other
|
||||||
|
|
||||||
def __sub__(self, other: Union["BaseSingleMetric", int, float]) -> "BaseSingleMetric":
|
def __sub__(self, other: Union["BaseSingleMetric", int, float]) -> "BaseSingleMetric":
|
||||||
pass
|
raise NotImplementedError(f"Please implement the `__sub__` method")
|
||||||
|
|
||||||
def __rsub__(self, other: Union["BaseSingleMetric", int, float]) -> "BaseSingleMetric":
|
def __rsub__(self, other: Union["BaseSingleMetric", int, float]) -> "BaseSingleMetric":
|
||||||
pass
|
raise NotImplementedError(f"Please implement the `__rsub__` method")
|
||||||
|
|
||||||
def __mul__(self, other: Union["BaseSingleMetric", int, float]) -> "BaseSingleMetric":
|
def __mul__(self, other: Union["BaseSingleMetric", int, float]) -> "BaseSingleMetric":
|
||||||
pass
|
raise NotImplementedError(f"Please implement the `__mul__` method")
|
||||||
|
|
||||||
def __truediv__(self, other: Union["BaseSingleMetric", int, float]) -> "BaseSingleMetric":
|
def __truediv__(self, other: Union["BaseSingleMetric", int, float]) -> "BaseSingleMetric":
|
||||||
pass
|
raise NotImplementedError(f"Please implement the `__truediv__` method")
|
||||||
|
|
||||||
def __eq__(self, other: Union["BaseSingleMetric", int, float]) -> "BaseSingleMetric":
|
def __eq__(self, other: Union["BaseSingleMetric", int, float]) -> "BaseSingleMetric":
|
||||||
pass
|
raise NotImplementedError(f"Please implement the `__eq__` method")
|
||||||
|
|
||||||
def __gt__(self, other: Union["BaseSingleMetric", int, float]) -> "BaseSingleMetric":
|
def __gt__(self, other: Union["BaseSingleMetric", int, float]) -> "BaseSingleMetric":
|
||||||
pass
|
raise NotImplementedError(f"Please implement the `__gt__` method")
|
||||||
|
|
||||||
def __lt__(self, other: Union["BaseSingleMetric", int, float]) -> "BaseSingleMetric":
|
def __lt__(self, other: Union["BaseSingleMetric", int, float]) -> "BaseSingleMetric":
|
||||||
pass
|
raise NotImplementedError(f"Please implement the `__lt__` method")
|
||||||
|
|
||||||
def __len__(self) -> int:
|
def __len__(self) -> int:
|
||||||
pass
|
raise NotImplementedError(f"Please implement the `__len__` method")
|
||||||
|
|
||||||
def sum(self) -> float:
|
def sum(self) -> float:
|
||||||
pass
|
raise NotImplementedError(f"Please implement the `sum` method")
|
||||||
|
|
||||||
def mean(self) -> float:
|
def mean(self) -> float:
|
||||||
pass
|
raise NotImplementedError(f"Please implement the `mean` method")
|
||||||
|
|
||||||
def count(self) -> int:
|
def count(self) -> int:
|
||||||
pass
|
"""Return the count of the single metric, NaN is not included.
|
||||||
|
"""
|
||||||
|
|
||||||
|
raise NotImplementedError(f"Please implement the `count` method")
|
||||||
|
|
||||||
def abs(self) -> "BaseSingleMetric":
|
def abs(self) -> "BaseSingleMetric":
|
||||||
pass
|
raise NotImplementedError(f"Please implement the `abs` method")
|
||||||
|
|
||||||
def astype(self, type: type) -> "BaseSingleMetric":
|
def astype(self, type: type) -> "BaseSingleMetric":
|
||||||
pass
|
raise NotImplementedError(f"Please implement the `astype` method")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def empty(self) -> bool:
|
def empty(self) -> bool:
|
||||||
"""If metric is empyt, return True."""
|
"""If metric is empyt, return True."""
|
||||||
pass
|
raise NotImplementedError(f"Please implement the `empty` method")
|
||||||
|
|
||||||
def add(self, other: "BaseSingleMetric", fill_value: float = None) -> "BaseSingleMetric":
|
def add(self, other: "BaseSingleMetric", fill_value: float = None) -> "BaseSingleMetric":
|
||||||
"""Replace np.NaN with fill_value in two metrics and add them."""
|
"""Replace np.NaN with fill_value in two metrics and add them."""
|
||||||
pass
|
raise NotImplementedError(f"Please implement the `add` method")
|
||||||
|
|
||||||
def apply(self, map_dict: dict) -> "BaseSingleMetric":
|
def map(self, map_dict: dict) -> "BaseSingleMetric":
|
||||||
"""Replace the value of metric according to map_dict."""
|
"""Replace the value of metric according to map_dict."""
|
||||||
pass
|
raise NotImplementedError(f"Please implement the `map` method")
|
||||||
|
|
||||||
|
|
||||||
class BaseOrderIndicator:
|
class BaseOrderIndicator:
|
||||||
"""
|
"""
|
||||||
The data structure of order indicator.
|
The data structure of order indicator.
|
||||||
!!!NOTE: There are two ways to organize the data structure. Please choose a better way.
|
!!!NOTE: There are two ways to organize the data structure. Please choose a better way.
|
||||||
1. one way is use BaseSingleMetric to represent each metric. For example, the data
|
1. One way is using BaseSingleMetric to represent each metric. For example, the data
|
||||||
structure of PandasOrderIndicator is Dict[str: PandasSingleMetric]. It uses
|
structure of PandasOrderIndicator is Dict[str, PandasSingleMetric]. It uses
|
||||||
PandasSingleMetric based on pd.Series to represent each metric.
|
PandasSingleMetric based on pd.Series to represent each metric.
|
||||||
2. the another way doesn't BaseSingleMetric to represent each metric. The data
|
2. The another way doesn't use BaseSingleMetric to represent each metric. The data
|
||||||
structure of PandasOrderIndicator is a whole matrix.
|
structure of PandasOrderIndicator is a whole matrix. It means you are not neccesary
|
||||||
|
to inherit the BaseSingleMetric.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def assign(self, col: str, metric: Union[dict, pd.Series]):
|
def assign(self, col: str, metric: Union[dict, pd.Series]):
|
||||||
@@ -367,7 +372,7 @@ class PandasSingleMetric:
|
|||||||
def add(self, other, fill_value=None):
|
def add(self, other, fill_value=None):
|
||||||
return PandasSingleMetric(self.metric.add(other.metric, fill_value=fill_value))
|
return PandasSingleMetric(self.metric.add(other.metric, fill_value=fill_value))
|
||||||
|
|
||||||
def apply(self, map_dict: dict):
|
def map(self, map_dict: dict):
|
||||||
return PandasSingleMetric(self.metric.apply(map_dict))
|
return PandasSingleMetric(self.metric.apply(map_dict))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ from collections import OrderedDict
|
|||||||
from logging import warning
|
from logging import warning
|
||||||
import pathlib
|
import pathlib
|
||||||
from typing import Dict, List, Tuple, Union, Callable
|
from typing import Dict, List, Tuple, Union, Callable
|
||||||
import warnings
|
|
||||||
import inspect
|
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
@@ -18,7 +16,7 @@ from qlib.backtest.exchange import Exchange
|
|||||||
from qlib.backtest.order import BaseTradeDecision, Order, OrderDir
|
from qlib.backtest.order import BaseTradeDecision, Order, OrderDir
|
||||||
from qlib.backtest.utils import TradeCalendarManager
|
from qlib.backtest.utils import TradeCalendarManager
|
||||||
|
|
||||||
from .high_performane_ds import PandasOrderIndicator
|
from .high_performance_ds import PandasOrderIndicator
|
||||||
from ..data import D
|
from ..data import D
|
||||||
from ..tests.config import CSI300_BENCH
|
from ..tests.config import CSI300_BENCH
|
||||||
from ..utils.resam import get_higher_eq_freq_feature, resam_ts_data
|
from ..utils.resam import get_higher_eq_freq_feature, resam_ts_data
|
||||||
@@ -329,7 +327,7 @@ class Indicator:
|
|||||||
self.order_indicator.transfer(func, "trade_price")
|
self.order_indicator.transfer(func, "trade_price")
|
||||||
|
|
||||||
def func_apply(trade_dir):
|
def func_apply(trade_dir):
|
||||||
return trade_dir.apply(Order.parse_dir)
|
return trade_dir.map(Order.parse_dir)
|
||||||
|
|
||||||
self.order_indicator.transfer(func_apply, "trade_dir")
|
self.order_indicator.transfer(func_apply, "trade_dir")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user