mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-15 08:46:56 +08:00
Format code
This commit is contained in:
@@ -8,7 +8,7 @@ from datetime import time
|
|||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
|
|
||||||
# try to fix circular imports when enabling type hints
|
# try to fix circular imports when enabling type hints
|
||||||
from typing import Generic, List, TYPE_CHECKING, Any, ClassVar, Optional, Tuple, TypeVar, Union, cast
|
from typing import TYPE_CHECKING, Any, ClassVar, Generic, List, Optional, Tuple, TypeVar, Union, cast
|
||||||
|
|
||||||
from qlib.backtest.utils import TradeCalendarManager
|
from qlib.backtest.utils import TradeCalendarManager
|
||||||
from qlib.data.data import Cal
|
from qlib.data.data import Cal
|
||||||
@@ -24,7 +24,6 @@ from dataclasses import dataclass
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
|
|
||||||
DecisionType = TypeVar("DecisionType")
|
DecisionType = TypeVar("DecisionType")
|
||||||
|
|
||||||
|
|
||||||
@@ -537,7 +536,10 @@ class TradeDecisionWO(BaseTradeDecision[Order]):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, order_list: List[Order], strategy: BaseStrategy, trade_range: Union[Tuple[int, int], TradeRange] = None,
|
self,
|
||||||
|
order_list: List[Order],
|
||||||
|
strategy: BaseStrategy,
|
||||||
|
trade_range: Union[Tuple[int, int], TradeRange] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
super().__init__(strategy, trade_range=trade_range)
|
super().__init__(strategy, trade_range=trade_range)
|
||||||
self.order_list = cast(List[Order], order_list)
|
self.order_list = cast(List[Order], order_list)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ from __future__ import annotations
|
|||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Optional, Sequence, cast
|
from typing import List, Sequence, cast
|
||||||
|
|
||||||
import cachetools
|
import cachetools
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"""Placeholder for qlib-based simulator."""
|
"""Placeholder for qlib-based simulator."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Callable, cast, Generator, List, Optional, Tuple
|
from typing import Callable, Generator, List, Optional, Tuple, cast
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any, cast, List, Optional, Tuple
|
from typing import Any, List, Tuple, cast
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
@@ -13,7 +13,7 @@ from qlib.backtest.account import Account
|
|||||||
from qlib.backtest.decision import OrderDir
|
from qlib.backtest.decision import OrderDir
|
||||||
from qlib.backtest.executor import BaseExecutor
|
from qlib.backtest.executor import BaseExecutor
|
||||||
from qlib.rl.from_neutrader.config import ExchangeConfig
|
from qlib.rl.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
|
from qlib.utils.time import Freq
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,17 +3,17 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Callable, Sequence, cast, Any
|
from typing import Any, Callable, Sequence, cast
|
||||||
|
|
||||||
from tianshou.policy import BasePolicy
|
from tianshou.policy import BasePolicy
|
||||||
|
|
||||||
from qlib.rl.simulator import InitialStateType, Simulator
|
from qlib.rl.interpreter import ActionInterpreter, StateInterpreter
|
||||||
from qlib.rl.interpreter import StateInterpreter, ActionInterpreter
|
|
||||||
from qlib.rl.reward import Reward
|
from qlib.rl.reward import Reward
|
||||||
|
from qlib.rl.simulator import InitialStateType, Simulator
|
||||||
from qlib.rl.utils import FiniteEnvType, LogWriter
|
from qlib.rl.utils import FiniteEnvType, LogWriter
|
||||||
|
|
||||||
from .vessel import TrainingVessel
|
|
||||||
from .trainer import Trainer
|
from .trainer import Trainer
|
||||||
|
from .vessel import TrainingVessel
|
||||||
|
|
||||||
|
|
||||||
def train(
|
def train(
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import shutil
|
|||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, TYPE_CHECKING
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import torch
|
import torch
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ from __future__ import annotations
|
|||||||
import copy
|
import copy
|
||||||
from contextlib import AbstractContextManager, contextmanager
|
from contextlib import AbstractContextManager, contextmanager
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Iterable, TypeVar, Sequence, cast
|
from typing import Any, Iterable, Sequence, TypeVar, cast
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
from qlib.rl.simulator import InitialStateType
|
|
||||||
from qlib.rl.utils import EnvWrapper, FiniteEnvType, LogCollector, LogWriter, LogBuffer, vectorize_env, LogLevel
|
|
||||||
from qlib.log import get_module_logger
|
from qlib.log import get_module_logger
|
||||||
|
from qlib.rl.simulator import InitialStateType
|
||||||
|
from qlib.rl.utils import EnvWrapper, FiniteEnvType, LogBuffer, LogCollector, LogLevel, LogWriter, vectorize_env
|
||||||
from qlib.rl.utils.finite_env import FiniteVectorEnv
|
from qlib.rl.utils.finite_env import FiniteVectorEnv
|
||||||
from qlib.typehint import Literal
|
from qlib.typehint import Literal
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import weakref
|
import weakref
|
||||||
from typing import Callable, ContextManager, Generic, Iterable, TYPE_CHECKING, Sequence, Any, TypeVar, cast, Dict
|
from typing import TYPE_CHECKING, Any, Callable, ContextManager, Dict, Generic, Iterable, Sequence, TypeVar, cast
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from tianshou.data import Collector, VectorReplayBuffer
|
from tianshou.data import Collector, VectorReplayBuffer
|
||||||
@@ -12,12 +12,11 @@ from tianshou.env import BaseVectorEnv
|
|||||||
from tianshou.policy import BasePolicy
|
from tianshou.policy import BasePolicy
|
||||||
|
|
||||||
from qlib.constant import INF
|
from qlib.constant import INF
|
||||||
from qlib.rl.interpreter import StateType, ActType, ObsType, PolicyActType
|
|
||||||
from qlib.rl.simulator import InitialStateType, Simulator
|
|
||||||
from qlib.rl.interpreter import StateInterpreter, ActionInterpreter
|
|
||||||
from qlib.rl.reward import Reward
|
|
||||||
from qlib.rl.utils import DataQueue
|
|
||||||
from qlib.log import get_module_logger
|
from qlib.log import get_module_logger
|
||||||
|
from qlib.rl.interpreter import ActionInterpreter, ActType, ObsType, PolicyActType, StateInterpreter, StateType
|
||||||
|
from qlib.rl.reward import Reward
|
||||||
|
from qlib.rl.simulator import InitialStateType, Simulator
|
||||||
|
from qlib.rl.utils import DataQueue
|
||||||
from qlib.rl.utils.finite_env import FiniteVectorEnv
|
from qlib.rl.utils.finite_env import FiniteVectorEnv
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@@ -209,6 +208,9 @@ class TrainingVessel(TrainingVesselBase):
|
|||||||
order = np.random.permutation(len(collection))
|
order = np.random.permutation(len(collection))
|
||||||
res = [collection[o] for o in order[:size]]
|
res = [collection[o] for o in order[:size]]
|
||||||
_logger.info(
|
_logger.info(
|
||||||
"Fast running in development mode. Cut %s initial states from %d to %d.", name, len(collection), len(res)
|
"Fast running in development mode. Cut %s initial states from %d to %d.",
|
||||||
|
name,
|
||||||
|
len(collection),
|
||||||
|
len(res),
|
||||||
)
|
)
|
||||||
return res
|
return res
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ class DataQueue(Generic[T]):
|
|||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Need to call activate() to launch a daemon worker "
|
"Need to call activate() to launch a daemon worker "
|
||||||
"to produce data into data queue before using it. "
|
"to produce data into data queue before using it. "
|
||||||
"You probably have forgotten to use the DataQueue in a with block."
|
"You probably have forgotten to use the DataQueue in a with block.",
|
||||||
)
|
)
|
||||||
return self._consumer()
|
return self._consumer()
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import logging
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Callable, Dict, Generic, List, Sequence, Set, TYPE_CHECKING, Tuple, TypeVar
|
from typing import TYPE_CHECKING, Any, Callable, Dict, Generic, List, Sequence, Set, Tuple, TypeVar
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|||||||
Reference in New Issue
Block a user