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

add default executor config & update bug in indicator

This commit is contained in:
bxdd
2021-06-24 13:59:10 +00:00
parent ab97e82484
commit 1517a9eb91
8 changed files with 123 additions and 91 deletions

View File

@@ -84,29 +84,33 @@ def indicator_analysis(df, method="mean"):
index: Index(datetime)
method : str, optional
statistics method, by default "mean"
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 'value_weighted', count the value weighted mean statistical value of each trade indicator
Note: statistics method of pos is always "mean"
Returns
-------
pd.DataFrame
statistical value of each trade indicator
statistical value of each trade indicators
"""
indicators_df = df[["pa", "pos", "ffr"]]
if method == "mean":
res = indicators_df.mean()
elif method == "amount_weighted":
weights = df["amount"].abs()
res = indicators_df.mul(weights, axis=0).sum() / weights.sum()
elif method == "value_weighted":
weights = df["value"].abs()
res = indicators_df.mul(weights, axis=0).sum() / weights.sum()
else:
weights_dict = {
"mean": df["count"],
"amount_weighted": df["amount"].abs(),
"value_weighted": df["value"].abs(),
}
if method not in weights_dict:
raise ValueError(f"indicator_analysis method {method} is not supported!")
# statistic pa/ffr indicator
indicators_df = df[["ffr", "pa"]]
weights = weights_dict.get(method)
res = indicators_df.mul(weights, axis=0).sum() / weights.sum()
# statistic pos
weights = weights_dict.get("mean")
res.loc["pos"] = df["pos"].mul(weights).sum() / weights.sum()
res = res.to_frame("value")
return res

View File

@@ -414,12 +414,12 @@ class SBBStrategyEMA(SBBStrategyBase):
# if EMA signal > 0, return long trend
elif _sample_signal.iloc[0] > 0:
return self.TREND_LONG
# if EMA signal > 0, return short trend
# if EMA signal < 0, return short trend
else:
return self.TREND_SHORT
class VAStrategy(BaseStrategy):
class ACStrategy(BaseStrategy):
def __init__(
self,
lamb: float = 1e-6,
@@ -451,7 +451,7 @@ class VAStrategy(BaseStrategy):
if isinstance(instruments, str):
self.instruments = D.instruments(instruments)
self.freq = freq
super(VAStrategy, self).__init__(outer_trade_decision, level_infra, common_infra, **kwargs)
super(ACStrategy, self).__init__(outer_trade_decision, level_infra, common_infra, **kwargs)
if trade_exchange is not None:
self.trade_exchange = trade_exchange
@@ -483,7 +483,7 @@ class VAStrategy(BaseStrategy):
- It should include `trade_account`, used to get position
- It should include `trade_exchange`, used to provide market info
"""
super(VAStrategy, self).reset_common_infra(common_infra)
super(ACStrategy, self).reset_common_infra(common_infra)
if common_infra.has("trade_exchange"):
self.trade_exchange = common_infra.get("trade_exchange")
@@ -508,7 +508,7 @@ class VAStrategy(BaseStrategy):
----------
outer_trade_decision : List[Order], optional
"""
super(VAStrategy, self).reset(outer_trade_decision=outer_trade_decision, **kwargs)
super(ACStrategy, self).reset(outer_trade_decision=outer_trade_decision, **kwargs)
if outer_trade_decision is not None:
self.trade_amount = {}
# init the trade amount of order and predicted trade trend