1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-03 19:10:58 +08:00

Rename util functions

This commit is contained in:
Huoran Li
2022-07-26 11:25:01 +08:00
parent 80b2006a1f
commit e864bba47f
2 changed files with 19 additions and 19 deletions

View File

@@ -18,12 +18,12 @@ from qlib.rl.from_neutrader.config import ExchangeConfig
from qlib.rl.from_neutrader.feature import init_qlib
from qlib.rl.order_execution.simulator_simple import SAOEMetrics, SAOEState
from qlib.rl.order_execution.utils import (
_convert_tick_str_to_int,
_dataframe_append,
_get_common_infra,
_get_portfolio_and_indicator,
_get_ticks_slice,
_price_advantage,
convert_tick_str_to_int,
dataframe_append,
get_common_infra,
get_portfolio_and_indicator,
get_ticks_slice,
price_advantage,
)
from qlib.rl.simulator import Simulator
from qlib.strategy.base import BaseStrategy
@@ -138,7 +138,7 @@ class StateMaintainer:
assert market_price.shape == market_volume.shape == exec_vol.shape
self.history_exec = _dataframe_append(
self.history_exec = dataframe_append(
self.history_exec,
self._collect_multi_order_metric(
order=self._order,
@@ -150,7 +150,7 @@ class StateMaintainer:
),
)
self.history_steps = _dataframe_append(
self.history_steps = dataframe_append(
self.history_steps,
[
self._collect_single_order_metric(
@@ -237,7 +237,7 @@ class StateMaintainer:
trade_value=float(np.sum(market_price * exec_vol)),
position=self.position - exec_sum,
ffr=float(exec_sum / order.amount),
pa=_price_advantage(exec_avg_price, self._twap_price, order.direction),
pa=price_advantage(exec_avg_price, self._twap_price, order.direction),
)
@@ -264,7 +264,7 @@ class SingleAssetQlibSimulator(Simulator[Order, SAOEState, float]):
self._exchange_config = exchange_config
self._time_per_step = time_per_step
self._ticks_per_step = _convert_tick_str_to_int(time_per_step)
self._ticks_per_step = convert_tick_str_to_int(time_per_step)
self._executor: Optional[NestedExecutor] = None
self._collect_data_loop: Optional[Generator] = None
@@ -280,7 +280,7 @@ class SingleAssetQlibSimulator(Simulator[Order, SAOEState, float]):
init_qlib(self._qlib_config, instrument)
common_infra = _get_common_infra(
common_infra = get_common_infra(
self._exchange_config,
trade_date=pd.Timestamp(self._order_date),
codes=[instrument],
@@ -297,7 +297,7 @@ class SingleAssetQlibSimulator(Simulator[Order, SAOEState, float]):
exchange = self._inner_executor.trade_exchange
self._ticks_index = pd.DatetimeIndex([e[1] for e in list(exchange.quote_df.index)])
self._ticks_for_order = _get_ticks_slice(
self._ticks_for_order = get_ticks_slice(
self._ticks_index,
self._order.start_time,
self._order.end_time,
@@ -344,7 +344,7 @@ class SingleAssetQlibSimulator(Simulator[Order, SAOEState, float]):
except StopIteration:
self._done = True
_, all_indicators = _get_portfolio_and_indicator(self._executor)
_, all_indicators = get_portfolio_and_indicator(self._executor)
self._maintainer.update(
inner_executor=self._inner_executor,

View File

@@ -17,7 +17,7 @@ from qlib.rl.order_execution.simulator_simple import ONE_SEC, _float_or_ndarray
from qlib.utils.time import Freq
def _get_common_infra(
def get_common_infra(
config: ExchangeConfig,
trade_date: pd.Timestamp,
codes: List[str],
@@ -51,14 +51,14 @@ def _get_common_infra(
return CommonInfrastructure(trade_account=trade_account, trade_exchange=exchange)
def _convert_tick_str_to_int(time_per_step: str) -> int:
def convert_tick_str_to_int(time_per_step: str) -> int:
d = {
"30min": 30,
}
return d[time_per_step]
def _get_ticks_slice(
def get_ticks_slice(
ticks_index: pd.DatetimeIndex,
start: pd.Timestamp,
end: pd.Timestamp,
@@ -69,7 +69,7 @@ def _get_ticks_slice(
return ticks_index[ticks_index.slice_indexer(start, end)]
def _dataframe_append(df: pd.DataFrame, other: Any) -> pd.DataFrame:
def dataframe_append(df: pd.DataFrame, other: Any) -> pd.DataFrame:
# dataframe.append is deprecated
other_df = pd.DataFrame(other).set_index("datetime")
other_df.index.name = "datetime"
@@ -78,7 +78,7 @@ def _dataframe_append(df: pd.DataFrame, other: Any) -> pd.DataFrame:
return res
def _price_advantage(
def price_advantage(
exec_price: _float_or_ndarray,
baseline_price: float,
direction: OrderDir | int,
@@ -101,7 +101,7 @@ def _price_advantage(
return cast(_float_or_ndarray, res_wo_nan)
def _get_portfolio_and_indicator(executor: BaseExecutor) -> Tuple[dict, dict]:
def get_portfolio_and_indicator(executor: BaseExecutor) -> Tuple[dict, dict]:
all_executors = executor.get_all_executors()
all_portfolio_metrics = {
"{}{}".format(*Freq.parse(_executor.time_per_step)): _executor.trade_account.get_portfolio_metrics()