Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qlib simulator refinement #1244

Merged
merged 23 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Format code
  • Loading branch information
lihuoran committed Aug 3, 2022
commit 03472eff4429f9af4e02371d5ddb978d0091909d
2 changes: 1 addition & 1 deletion qlib/rl/aux_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from __future__ import annotations

from typing import Optional, TYPE_CHECKING, Generic, TypeVar
from typing import TYPE_CHECKING, Generic, Optional, TypeVar

from qlib.typehint import final

Expand Down
1 change: 1 addition & 0 deletions qlib/rl/data/exchange_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pandas as pd

from qlib.backtest import Exchange, Order

from .pickle_styled import IntradayBacktestData


Expand Down
2 changes: 1 addition & 1 deletion qlib/rl/integration/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Licensed under the MIT License.

you-n-g marked this conversation as resolved.
Show resolved Hide resolved
import collections
from typing import List, Optional
from typing import List

import pandas as pd

Expand Down
3 changes: 1 addition & 2 deletions qlib/rl/order_execution/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
from qlib.constant import EPS
from qlib.rl.data import pickle_styled
from qlib.rl.interpreter import ActionInterpreter, StateInterpreter
from qlib.typehint import TypedDict

from qlib.rl.order_execution.state import SAOEState
from qlib.typehint import TypedDict

__all__ = [
"FullHistoryStateInterpreter",
Expand Down
3 changes: 1 addition & 2 deletions qlib/rl/order_execution/reward.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

import numpy as np

from qlib.rl.reward import Reward

from qlib.rl.order_execution.state import SAOEMetrics, SAOEState
from qlib.rl.reward import Reward

__all__ = ["PAPenaltyReward"]

Expand Down
5 changes: 2 additions & 3 deletions qlib/rl/order_execution/simulator_qlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
from typing import Generator, Optional

import pandas as pd

from qlib.backtest import get_strategy_executor
from qlib.backtest.decision import Order
from qlib.backtest.executor import NestedExecutor
from qlib.rl.data.exchange_wrapper import QlibIntradayBacktestData
from qlib.rl.integration.feature import init_qlib
from qlib.rl.order_execution.state import SAOEState
from qlib.rl.order_execution.utils import (
get_ticks_slice,
)
from qlib.rl.order_execution.utils import get_ticks_slice
from qlib.rl.simulator import Simulator
from qlib.rl.strategy.saoe import SAOEStrategy

Expand Down
2 changes: 1 addition & 1 deletion qlib/rl/order_execution/simulator_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from qlib.backtest.decision import Order, OrderDir
from qlib.constant import EPS
from qlib.rl.data.pickle_styled import DealPriceType, load_simple_intraday_backtest_data
from qlib.rl.order_execution.objects import float_or_ndarray, ONE_SEC
from qlib.rl.order_execution.objects import ONE_SEC, float_or_ndarray
from qlib.rl.order_execution.state import SAOEMetrics, SAOEState
from qlib.rl.simulator import Simulator
from qlib.rl.utils import LogLevel
Expand Down
13 changes: 6 additions & 7 deletions qlib/rl/order_execution/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@

from __future__ import annotations

from typing import cast, NamedTuple, Optional

from qlib.rl.data.pickle_styled import IntradayBacktestData
from typing_extensions import TypedDict
from typing import NamedTuple, Optional, cast

import numpy as np
import pandas as pd
from typing_extensions import TypedDict

from qlib.backtest import Order
from qlib.backtest.executor import BaseExecutor
from qlib.backtest.utils import TradeCalendarManager
from qlib.constant import EPS
from qlib.rl.data.exchange_wrapper import QlibIntradayBacktestData
from qlib.rl.order_execution.utils import dataframe_append, get_simulator_executor, get_ticks_slice, price_advantage
from qlib.rl.data.pickle_styled import IntradayBacktestData
from qlib.rl.order_execution.utils import dataframe_append, get_simulator_executor, price_advantage


class SAOEStateMaintainer:
lihuoran marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -304,4 +303,4 @@ class SAOEState(NamedTuple):
ticks_index: pd.DatetimeIndex
"""Trading ticks in all day, NOT sliced by order (defined in data). e.g., [9:30, 9:31, ..., 14:59]."""
ticks_for_order: pd.DatetimeIndex
"""Trading ticks sliced by order, e.g., [9:45, 9:46, ..., 14:44]."""
"""Trading ticks sliced by order, e.g., [9:45, 9:46, ..., 14:44]."""
4 changes: 2 additions & 2 deletions qlib/rl/order_execution/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

from __future__ import annotations

from typing import Any, cast, Tuple
from typing import Any, cast

import numpy as np
import pandas as pd

from qlib.backtest.decision import OrderDir
from qlib.backtest.executor import BaseExecutor, NestedExecutor, SimulatorExecutor
from qlib.rl.order_execution.objects import float_or_ndarray, ONE_SEC
from qlib.rl.order_execution.objects import ONE_SEC, float_or_ndarray


def get_ticks_slice(
Expand Down
1 change: 1 addition & 0 deletions qlib/rl/strategy/saoe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Optional

import pandas as pd

from qlib.backtest.decision import BaseTradeDecision, Order
from qlib.backtest.executor import BaseExecutor
from qlib.backtest.utils import CommonInfrastructure, LevelInfrastructure
Expand Down
3 changes: 2 additions & 1 deletion qlib/rl/utils/finite_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
import copy
import warnings
from contextlib import contextmanager
from typing import Any, Callable, cast, Dict, Generator, List, Optional, Set, Tuple, Type, Union
from typing import Any, Callable, Dict, Generator, List, Optional, Set, Tuple, Type, Union, cast

import gym
import numpy as np
from tianshou.env import BaseVectorEnv, DummyVectorEnv, ShmemVectorEnv, SubprocVectorEnv

from qlib.typehint import Literal

from .log import LogWriter

__all__ = [
Expand Down