1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-17 17:34:35 +08:00

add cash settlement mechanism

This commit is contained in:
Young
2021-07-26 17:05:33 +00:00
parent 4924717276
commit fcca242807
8 changed files with 170 additions and 120 deletions

View File

@@ -18,7 +18,12 @@ from qlib.backtest.utils import get_start_end_idx
class TWAPStrategy(BaseStrategy):
"""TWAP Strategy for trading"""
"""TWAP Strategy for trading
NOTE:
- This TWAP strategy will celling round when trading. This will make the TWAP trading strategy produce the order
ealier when the total trade unit of amount is less than the trading step
"""
def reset(self, outer_trade_decision: BaseTradeDecision = None, **kwargs):
"""
@@ -583,7 +588,11 @@ class FileOrderStrategy(BaseStrategy):
"""
def __init__(
self, file: Union[IO, str, Path], trade_range: Union[Tuple[int, int], TradeRange] = None, *args, **kwargs
self,
file: Union[IO, str, Path, pd.DataFrame],
trade_range: Union[Tuple[int, int], TradeRange] = None,
*args,
**kwargs,
):
"""
@@ -611,8 +620,11 @@ class FileOrderStrategy(BaseStrategy):
"""
super().__init__(*args, **kwargs)
with get_io_object(file) as f:
self.order_df = pd.read_csv(f, dtype={"datetime": np.str})
if isinstance(file, pd.DataFrame):
self.order_df = file
else:
with get_io_object(file) as f:
self.order_df = pd.read_csv(f, dtype={"datetime": np.str})
self.order_df["datetime"] = self.order_df["datetime"].apply(pd.Timestamp)
self.order_df = self.order_df.set_index(["datetime", "instrument"])