From 00def78e7a20fab3b9f83089c538d16d22bc2996 Mon Sep 17 00:00:00 2001 From: Huoran Li Date: Fri, 22 Jul 2022 11:57:56 +0800 Subject: [PATCH] Format code --- .../rl/order_execution/from_neutrader/feature.py | 4 ++-- qlib/rl/order_execution/reward.py | 3 ++- qlib/rl/order_execution/simulator_qlib.py | 16 +++++++++++----- qlib/rl/order_execution/utils.py | 4 ++-- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/qlib/rl/order_execution/from_neutrader/feature.py b/qlib/rl/order_execution/from_neutrader/feature.py index ba0e5fff4..9c5d84a32 100644 --- a/qlib/rl/order_execution/from_neutrader/feature.py +++ b/qlib/rl/order_execution/from_neutrader/feature.py @@ -91,7 +91,7 @@ def init_qlib(config: dict, part: Optional[str] = None) -> None: "class": "FileCalendarStorage", "module_path": "qlib.data.storage.file_storage", "kwargs": {"provider_uri_map": provider_uri_map}, - } + }, }, }, feature_provider={ @@ -102,7 +102,7 @@ def init_qlib(config: dict, part: Optional[str] = None) -> None: "class": "FileFeatureStorage", "module_path": "qlib.data.storage.file_storage", "kwargs": {"provider_uri_map": provider_uri_map}, - } + }, }, }, provider_uri=provider_uri_map, diff --git a/qlib/rl/order_execution/reward.py b/qlib/rl/order_execution/reward.py index 43015407d..f15a152c6 100644 --- a/qlib/rl/order_execution/reward.py +++ b/qlib/rl/order_execution/reward.py @@ -6,9 +6,10 @@ from __future__ import annotations from typing import cast import numpy as np + from qlib.rl.reward import Reward -from .simulator_simple import SAOEState, SAOEMetrics +from .simulator_simple import SAOEMetrics, SAOEState __all__ = ["PAPenaltyReward"] diff --git a/qlib/rl/order_execution/simulator_qlib.py b/qlib/rl/order_execution/simulator_qlib.py index 63f71f75b..237656f8f 100644 --- a/qlib/rl/order_execution/simulator_qlib.py +++ b/qlib/rl/order_execution/simulator_qlib.py @@ -21,7 +21,8 @@ from qlib.rl.order_execution.utils import ( _convert_tick_str_to_int, _dataframe_append, _get_common_infra, - _get_portfolio_and_indicator, _get_ticks_slice, + _get_portfolio_and_indicator, + _get_ticks_slice, _price_advantage, ) from qlib.rl.simulator import Simulator @@ -83,7 +84,7 @@ class SingleOrderStrategy(BaseStrategy): code=self._instrument, amount=self._order.amount, direction=Order.parse_dir(self._order.direction), - ) + ), ] return TradeDecisionWO(order_list, self, self._trade_range) @@ -126,7 +127,7 @@ class StateMaintainer: execute_result[0][0].start_time, execute_result[-1][0].start_time, method=None, - ) + ), ) trade_value = all_indicators["1min"].iloc[-num_step:]["value"].values @@ -153,8 +154,13 @@ class StateMaintainer: self.history_steps, [ self._collect_single_order_metric( - execute_order, execute_order.start_time, market_volume, market_price, exec_vol.sum(), exec_vol, - ) + execute_order, + execute_order.start_time, + market_volume, + market_price, + exec_vol.sum(), + exec_vol, + ), ], ) diff --git a/qlib/rl/order_execution/utils.py b/qlib/rl/order_execution/utils.py index ef22716b8..915e5fa69 100644 --- a/qlib/rl/order_execution/utils.py +++ b/qlib/rl/order_execution/utils.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Any, cast, List, Optional, Tuple +from typing import Any, List, Optional, Tuple, cast import numpy as np import pandas as pd @@ -10,7 +10,7 @@ from qlib.backtest.account import Account from qlib.backtest.decision import OrderDir from qlib.backtest.executor import BaseExecutor from qlib.rl.order_execution.from_neutrader.config import ExchangeConfig -from qlib.rl.order_execution.simulator_simple import _float_or_ndarray, ONE_SEC +from qlib.rl.order_execution.simulator_simple import ONE_SEC, _float_or_ndarray from qlib.utils.time import Freq