1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-01 18:11:18 +08:00

fix little bug

This commit is contained in:
wangwenxi.handsome
2021-07-23 05:50:41 +00:00
parent 2c8a3ded08
commit 0ec6b87d39
3 changed files with 32 additions and 29 deletions

View File

@@ -15,7 +15,7 @@ from ..config import C, REG_CN
from ..utils.resam import resam_ts_data, ts_data_last
from ..log import get_module_logger
from .order import Order, OrderDir, OrderHelper
from .high_performane_ds import PandasQuote
from .high_performance_ds import PandasQuote
class Exchange:

View File

@@ -25,6 +25,7 @@ class BaseQuote:
Iterable
all stock codes
"""
raise NotImplementedError(f"Please implement the `get_all_stock` method")
def get_data(
@@ -119,76 +120,80 @@ class BaseSingleMetric:
"""
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":
pass
raise NotImplementedError(f"Please implement the `__add__` method")
def __radd__(self, other: Union["BaseSingleMetric", int, float]) -> "BaseSingleMetric":
return self + other
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":
pass
raise NotImplementedError(f"Please implement the `__rsub__` method")
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":
pass
raise NotImplementedError(f"Please implement the `__truediv__` method")
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":
pass
raise NotImplementedError(f"Please implement the `__gt__` method")
def __lt__(self, other: Union["BaseSingleMetric", int, float]) -> "BaseSingleMetric":
pass
raise NotImplementedError(f"Please implement the `__lt__` method")
def __len__(self) -> int:
pass
raise NotImplementedError(f"Please implement the `__len__` method")
def sum(self) -> float:
pass
raise NotImplementedError(f"Please implement the `sum` method")
def mean(self) -> float:
pass
raise NotImplementedError(f"Please implement the `mean` method")
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":
pass
raise NotImplementedError(f"Please implement the `abs` method")
def astype(self, type: type) -> "BaseSingleMetric":
pass
raise NotImplementedError(f"Please implement the `astype` method")
@property
def empty(self) -> bool:
"""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":
"""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."""
pass
raise NotImplementedError(f"Please implement the `map` method")
class BaseOrderIndicator:
"""
The data structure of order indicator.
!!!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
structure of PandasOrderIndicator is Dict[str: PandasSingleMetric]. It uses
1. One way is using BaseSingleMetric to represent each metric. For example, the data
structure of PandasOrderIndicator is Dict[str, PandasSingleMetric]. It uses
PandasSingleMetric based on pd.Series to represent each metric.
2. the another way doesn't BaseSingleMetric to represent each metric. The data
structure of PandasOrderIndicator is a whole matrix.
2. The another way doesn't use BaseSingleMetric to represent each metric. The data
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]):
@@ -367,7 +372,7 @@ class PandasSingleMetric:
def add(self, other, fill_value=None):
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))

View File

@@ -6,8 +6,6 @@ from collections import OrderedDict
from logging import warning
import pathlib
from typing import Dict, List, Tuple, Union, Callable
import warnings
import inspect
import numpy as np
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.utils import TradeCalendarManager
from .high_performane_ds import PandasOrderIndicator
from .high_performance_ds import PandasOrderIndicator
from ..data import D
from ..tests.config import CSI300_BENCH
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")
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")