mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-10 22:36:55 +08:00
Merge branch 'nested_decision_exe' of https://github.com/microsoft/qlib into rl-dummy
This commit is contained in:
@@ -524,4 +524,4 @@ class TradeDecisionWO(BaseTradeDecision):
|
|||||||
return self.order_list
|
return self.order_list
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return f"strategy: {self.strategy}; trade_range: {self.trade_range}; order_list[{len(self.order_list)}]"
|
return f"class: {self.__class__.__name__}; strategy: {self.strategy}; trade_range: {self.trade_range}; order_list[{len(self.order_list)}]"
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ class TradeCalendarManager:
|
|||||||
return clip(left), clip(right)
|
return clip(left), clip(right)
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return f"{self.start_time}[{self.start_index}]~{self.end_time}[{self.end_index}]: [{self.trade_step}/{self.trade_len}]"
|
return f"class: {self.__class__.__name__}; {self.start_time}[{self.start_index}]~{self.end_time}[{self.end_index}]: [{self.trade_step}/{self.trade_len}]"
|
||||||
|
|
||||||
|
|
||||||
class BaseInfrastructure:
|
class BaseInfrastructure:
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
# Licensed under the MIT License.
|
# Licensed under the MIT License.
|
||||||
from qlib.backtest.exchange import Exchange
|
from qlib.backtest.exchange import Exchange
|
||||||
from qlib.backtest.position import BasePosition
|
from qlib.backtest.position import BasePosition
|
||||||
from typing import List, Union
|
from typing import List, Tuple, Union
|
||||||
|
|
||||||
from ..model.base import BaseModel
|
from ..model.base import BaseModel
|
||||||
from ..data.dataset import DatasetH
|
from ..data.dataset import DatasetH
|
||||||
@@ -158,6 +158,36 @@ class BaseStrategy:
|
|||||||
# NOTE: normally, user should do something to the strategy due to the change of outer decision
|
# NOTE: normally, user should do something to the strategy due to the change of outer decision
|
||||||
raise NotImplementedError(f"Please implement the `alter_outer_trade_decision` method")
|
raise NotImplementedError(f"Please implement the `alter_outer_trade_decision` method")
|
||||||
|
|
||||||
|
# helper methods: not necessary but for convenience
|
||||||
|
def get_data_cal_avail_range(self, rtype: str = "full") -> Tuple[int, int]:
|
||||||
|
"""
|
||||||
|
return data calendar's available decision range for `self` strategy
|
||||||
|
the range consider following factors
|
||||||
|
- data calendar in the charge of `self` strategy
|
||||||
|
- trading range limitation from the decision of outer strategy
|
||||||
|
|
||||||
|
|
||||||
|
related methods
|
||||||
|
- TradeCalendarManager.get_data_cal_range
|
||||||
|
- BaseTradeDecision.get_data_cal_range_limit
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
rtype: str
|
||||||
|
- "full": return the available data index range of the strategy from `start_time` to `end_time`
|
||||||
|
- "step": return the available data index range of the strategy of current step
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
Tuple[int, int]:
|
||||||
|
the available range both sides are closed
|
||||||
|
"""
|
||||||
|
cal_range = self.trade_calendar.get_data_cal_range(rtype=rtype)
|
||||||
|
if self.outer_trade_decision is None:
|
||||||
|
raise ValueError(f"There is not limitation for strategy {self}")
|
||||||
|
range_limit = self.outer_trade_decision.get_data_cal_range_limit(rtype=rtype)
|
||||||
|
return max(cal_range[0], range_limit[0]), min(cal_range[1], range_limit[1])
|
||||||
|
|
||||||
|
|
||||||
class ModelStrategy(BaseStrategy):
|
class ModelStrategy(BaseStrategy):
|
||||||
"""Model-based trading strategy, use model to make predictions for trading"""
|
"""Model-based trading strategy, use model to make predictions for trading"""
|
||||||
|
|||||||
Reference in New Issue
Block a user