mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-11 14:56:55 +08:00
Merge branch 'nested_decision_exe' of https://github.com/microsoft/qlib into rl-dummy
This commit is contained in:
@@ -73,20 +73,20 @@ def indicator_analysis(df, method="mean"):
|
||||
Parameters
|
||||
----------
|
||||
df : pandas.DataFrame
|
||||
columns: like ['pa', 'pos', 'ffr', 'amount', 'value'].
|
||||
columns: like ['pa', 'pos', 'ffr', 'deal_amount', 'value'].
|
||||
Necessary fields:
|
||||
- 'pa' is the price advantage in trade indicators
|
||||
- 'pos' is the positive rate in trade indicators
|
||||
- 'ffr' is the fulfill rate in trade indicators
|
||||
Optional fields:
|
||||
- 'amount' is the total deal amount, only necessary when method is 'amount_weighted'
|
||||
- 'deal_amount' is the total deal deal_amount, only necessary when method is 'amount_weighted'
|
||||
- 'value' is the total trade value, only necessary when method is 'value_weighted'
|
||||
|
||||
index: Index(datetime)
|
||||
method : str, optional
|
||||
statistics method of pa/ffr, by default "mean"
|
||||
- if method is 'mean', count the mean statistical value of each trade indicator
|
||||
- if method is 'amount_weighted', count the amount weighted mean statistical value of each trade indicator
|
||||
- if method is 'amount_weighted', count the deal_amount weighted mean statistical value of each trade indicator
|
||||
- if method is 'value_weighted', count the value weighted mean statistical value of each trade indicator
|
||||
Note: statistics method of pos is always "mean"
|
||||
|
||||
@@ -97,7 +97,7 @@ def indicator_analysis(df, method="mean"):
|
||||
"""
|
||||
weights_dict = {
|
||||
"mean": df["count"],
|
||||
"amount_weighted": df["amount"].abs(),
|
||||
"amount_weighted": df["deal_amount"].abs(),
|
||||
"value_weighted": df["value"].abs(),
|
||||
}
|
||||
if method not in weights_dict:
|
||||
|
||||
@@ -194,7 +194,6 @@ class TopkDropoutStrategy(ModelStrategy):
|
||||
start_time=trade_start_time,
|
||||
end_time=trade_end_time,
|
||||
direction=Order.SELL, # 0 for sell, 1 for buy
|
||||
factor=factor,
|
||||
)
|
||||
# is order executable
|
||||
if self.trade_exchange.check_order(sell_order):
|
||||
@@ -231,7 +230,6 @@ class TopkDropoutStrategy(ModelStrategy):
|
||||
start_time=trade_start_time,
|
||||
end_time=trade_end_time,
|
||||
direction=Order.BUY, # 1 for buy
|
||||
factor=factor,
|
||||
)
|
||||
buy_order_list.append(buy_order)
|
||||
return TradeDecisionWO(sell_order_list + buy_order_list, self)
|
||||
|
||||
@@ -63,7 +63,9 @@ class TWAPStrategy(BaseStrategy):
|
||||
stock_id=order.stock_id, start_time=trade_start_time, end_time=trade_end_time
|
||||
):
|
||||
continue
|
||||
_amount_trade_unit = self.trade_exchange.get_amount_of_trade_unit(order.factor)
|
||||
_amount_trade_unit = self.trade_exchange.get_amount_of_trade_unit(stock_id=order.stock_id,
|
||||
start_time=order.start_time,
|
||||
end_time=order.end_time)
|
||||
_order_amount = None
|
||||
# considering trade unit
|
||||
if _amount_trade_unit is None:
|
||||
@@ -99,7 +101,6 @@ class TWAPStrategy(BaseStrategy):
|
||||
start_time=trade_start_time,
|
||||
end_time=trade_end_time,
|
||||
direction=order.direction, # 1 for buy
|
||||
factor=order.factor,
|
||||
)
|
||||
order_list.append(_order)
|
||||
return TradeDecisionWO(order_list=order_list, strategy=self)
|
||||
@@ -168,7 +169,9 @@ class SBBStrategyBase(BaseStrategy):
|
||||
self.trade_trend[order.stock_id] = _pred_trend
|
||||
continue
|
||||
# get amount of one trade unit
|
||||
_amount_trade_unit = self.trade_exchange.get_amount_of_trade_unit(order.factor)
|
||||
_amount_trade_unit = self.trade_exchange.get_amount_of_trade_unit(stock_id=order.stock_id,
|
||||
start_time=order.start_time,
|
||||
end_time=order.end_time)
|
||||
if _pred_trend == self.TREND_MID:
|
||||
_order_amount = None
|
||||
# considering trade unit
|
||||
@@ -201,7 +204,6 @@ class SBBStrategyBase(BaseStrategy):
|
||||
start_time=trade_start_time,
|
||||
end_time=trade_end_time,
|
||||
direction=order.direction,
|
||||
factor=order.factor,
|
||||
)
|
||||
order_list.append(_order)
|
||||
|
||||
@@ -248,7 +250,6 @@ class SBBStrategyBase(BaseStrategy):
|
||||
start_time=trade_start_time,
|
||||
end_time=trade_end_time,
|
||||
direction=order.direction, # 1 for buy
|
||||
factor=order.factor,
|
||||
)
|
||||
order_list.append(_order)
|
||||
else:
|
||||
@@ -267,7 +268,6 @@ class SBBStrategyBase(BaseStrategy):
|
||||
start_time=trade_start_time,
|
||||
end_time=trade_end_time,
|
||||
direction=order.direction, # 1 for buy
|
||||
factor=order.factor,
|
||||
)
|
||||
order_list.append(_order)
|
||||
|
||||
@@ -471,7 +471,9 @@ class ACStrategy(BaseStrategy):
|
||||
|
||||
if sig_sam is None or np.isnan(sig_sam):
|
||||
# no signal, TWAP
|
||||
_amount_trade_unit = self.trade_exchange.get_amount_of_trade_unit(order.factor)
|
||||
_amount_trade_unit = self.trade_exchange.get_amount_of_trade_unit(stock_id=order.stock_id,
|
||||
start_time=order.start_time,
|
||||
end_time=order.end_time)
|
||||
if _amount_trade_unit is None:
|
||||
# divide the order into equal parts, and trade one part
|
||||
_order_amount = self.trade_amount[order.stock_id] / (trade_len - trade_step)
|
||||
@@ -492,7 +494,10 @@ class ACStrategy(BaseStrategy):
|
||||
np.sinh(kappa * (trade_len - trade_step)) - np.sinh(kappa * (trade_len - trade_step - 1))
|
||||
) / np.sinh(kappa * trade_len)
|
||||
_order_amount = order.amount * amount_ratio
|
||||
_order_amount = self.trade_exchange.round_amount_by_trade_unit(_order_amount, order.factor)
|
||||
_order_amount = self.trade_exchange.round_amount_by_trade_unit(_order_amount,
|
||||
stock_id=order.stock_id,
|
||||
start_time=order.start_time,
|
||||
end_time=order.end_time)
|
||||
|
||||
if order.direction == order.SELL:
|
||||
# sell all amount at last
|
||||
|
||||
Reference in New Issue
Block a user