1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-11 14:56:55 +08:00

add InfPosition

This commit is contained in:
Young
2021-06-25 14:00:21 +00:00
committed by you-n-g
parent 4f384d37ce
commit b68294da93
11 changed files with 408 additions and 72 deletions

View File

@@ -1,5 +1,8 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""
This strategy is not well maintained
"""
from .order_generator import OrderGenWInteract

View File

@@ -1,4 +1,5 @@
import copy
from qlib.backtest.position import Position
import warnings
import numpy as np
import pandas as pd
@@ -328,6 +329,8 @@ class WeightStrategyBase(ModelStrategy):
if pred_score is None:
return []
current_temp = copy.deepcopy(self.trade_position)
assert(isinstance(current_temp, Position)) # Avoid InfPosition
target_weight_position = self.generate_target_weight_position(
score=pred_score, current=current_temp, trade_start_time=trade_start_time, trade_end_time=trade_end_time
)

View File

@@ -76,8 +76,6 @@ class TWAPStrategy(BaseStrategy):
trade_step = self.trade_calendar.get_trade_step()
# get the total count of trading step
trade_len = self.trade_calendar.get_trade_len()
# update outer trade decision
self.outer_trade_decision.update(trade_step, trade_len)
# update the order amount
if execute_result is not None:
@@ -204,8 +202,6 @@ class SBBStrategyBase(BaseStrategy):
trade_step = self.trade_calendar.get_trade_step()
# get the total count of trading step
trade_len = self.trade_calendar.get_trade_len()
# update outer trade decision
self.outer_trade_decision.update(trade_step, trade_len)
# update the order amount
if execute_result is not None:
@@ -527,7 +523,7 @@ class ACStrategy(BaseStrategy):
# get the total count of trading step
trade_len = self.trade_calendar.get_trade_len()
# update outer trade decision
self.outer_trade_decision.update(trade_step, trade_len)
self.outer_trade_decision.update(self.trade_calendar)
# update the order amount
if execute_result is not None:
@@ -602,7 +598,7 @@ class ACStrategy(BaseStrategy):
class RandomOrderStrategy(BaseStrategy):
def __init__(self,
time_range: Tuple = ("9:30", "15:00"), # left closed and right closed.
time_range: Tuple = ("9:30", "15:00"), # The range is closed on both left and right.
sample_ratio: float = 1.,
volume_ratio: float = 0.01,
market: str = "all",
@@ -614,6 +610,7 @@ class RandomOrderStrategy(BaseStrategy):
time_range : Tuple
the intra day time range of the orders
the left and right is closed.
# TODO: this is a time_range level limitation. We'll implement a more detailed limitation later.
sample_ratio : float
the ratio of all orders are sampled
volume_ratio : float
@@ -632,6 +629,4 @@ class RandomOrderStrategy(BaseStrategy):
self.volume = D.features(D.instruments("market"), ["Mean($volume, 10)"], start_time=exch.start_time, end_time=exch.end_time)
def generate_trade_decision(self, execute_result=None):
return super().generate_trade_decision(execute_result=execute_result)