1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-16 01:06:56 +08:00

Merge branch 'nested_decision_exe' of https://github.com/microsoft/qlib into rl-dummy

This commit is contained in:
v-mingzhehan
2021-06-22 07:07:07 +00:00
4 changed files with 28 additions and 13 deletions

View File

@@ -20,7 +20,7 @@ class NestedDecisonExecutionWorkflow:
benchmark = "SH000300" benchmark = "SH000300"
data_handler_config = { data_handler_config = {
"start_time": "2008-01-01", "start_time": "2008-01-01",
"end_time": "2021-05-28", "end_time": "2020-12-31",
"fit_start_time": "2008-01-01", "fit_start_time": "2008-01-01",
"fit_end_time": "2014-12-31", "fit_end_time": "2014-12-31",
"instruments": market, "instruments": market,
@@ -54,7 +54,7 @@ class NestedDecisonExecutionWorkflow:
"segments": { "segments": {
"train": ("2007-01-01", "2014-12-31"), "train": ("2007-01-01", "2014-12-31"),
"valid": ("2015-01-01", "2016-12-31"), "valid": ("2015-01-01", "2016-12-31"),
"test": ("2020-09-01", "2021-05-28"), "test": ("2020-01-01", "2020-12-31"),
}, },
}, },
}, },
@@ -79,12 +79,8 @@ class NestedDecisonExecutionWorkflow:
}, },
}, },
"inner_strategy": { "inner_strategy": {
"class": "SBBStrategyEMA", "class": "TWAPStrategy",
"module_path": "qlib.contrib.strategy.rule_strategy", "module_path": "qlib.contrib.strategy.rule_strategy",
"kwargs": {
"freq": "day",
"instruments": market,
},
}, },
"track_data": True, "track_data": True,
"generate_report": True, "generate_report": True,
@@ -94,8 +90,8 @@ class NestedDecisonExecutionWorkflow:
}, },
}, },
"backtest": { "backtest": {
"start_time": "2020-09-20", "start_time": "2020-01-01",
"end_time": "2021-05-28", "end_time": "2020-12-31",
"account": 100000000, "account": 100000000,
"benchmark": benchmark, "benchmark": benchmark,
"exchange_kwargs": { "exchange_kwargs": {

View File

@@ -1,14 +1,21 @@
# Copyright (c) Microsoft Corporation. # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License. # Licensed under the MIT License.
import copy
from .account import Account from .account import Account
from .exchange import Exchange from .exchange import Exchange
from .executor import BaseExecutor from .executor import BaseExecutor
from .backtest import backtest_loop from .backtest import backtest_loop
from .backtest import collect_data_loop from .backtest import collect_data_loop
<<<<<<< HEAD
from .order import Order from .order import Order
from .utils import CommonInfrastructure, TradeCalendarManager from .utils import CommonInfrastructure, TradeCalendarManager
=======
from .utils import CommonInfrastructure
from .order import Order
>>>>>>> ab97e8248443789ce1e0f90a9b5596e5fee60566
from ..strategy.base import BaseStrategy from ..strategy.base import BaseStrategy
from ..utils import init_instance_by_config from ..utils import init_instance_by_config
from ..log import get_module_logger from ..log import get_module_logger
@@ -101,10 +108,15 @@ def get_strategy_executor(
"end_time": end_time, "end_time": end_time,
}, },
) )
exchange_kwargs = copy.copy(exchange_kwargs)
if "start_time" not in exchange_kwargs:
exchange_kwargs["start_time"] = start_time
if "end_time" not in exchange_kwargs:
exchange_kwargs["end_time"] = end_time
trade_exchange = get_exchange(**exchange_kwargs) trade_exchange = get_exchange(**exchange_kwargs)
common_infra = CommonInfrastructure(trade_account=trade_account, trade_exchange=trade_exchange) common_infra = CommonInfrastructure(trade_account=trade_account, trade_exchange=trade_exchange)
trade_strategy = init_instance_by_config(strategy, accept_types=BaseStrategy, common_infra=common_infra) trade_strategy = init_instance_by_config(strategy, accept_types=BaseStrategy, common_infra=common_infra)
trade_executor = init_instance_by_config(executor, accept_types=BaseExecutor, common_infra=common_infra) trade_executor = init_instance_by_config(executor, accept_types=BaseExecutor, common_infra=common_infra)

View File

@@ -174,8 +174,8 @@ class Exchange:
self.quote = quote_dict self.quote = quote_dict
def _update_limit(self, buy_limit, sell_limit): def _update_limit(self, buy_limit, sell_limit):
self.quote["limit_buy"] = ~self.quote["$change"].lt(buy_limit) self.quote["limit_buy"] = self.quote["$change"].ge(buy_limit)
self.quote["limit_sell"] = ~self.quote["$change"].gt(-sell_limit) self.quote["limit_sell"] = self.quote["$change"].le(-sell_limit)
def check_stock_limit(self, stock_id, start_time, end_time, direction=None): def check_stock_limit(self, stock_id, start_time, end_time, direction=None):
""" """

View File

@@ -7,6 +7,7 @@ import warnings
import pandas as pd import pandas as pd
from pathlib import Path from pathlib import Path
from pprint import pprint from pprint import pprint
from typing import Union, List
from ..contrib.evaluate import indicator_analysis, risk_analysis, indicator_analysis from ..contrib.evaluate import indicator_analysis, risk_analysis, indicator_analysis
from ..data.dataset import DatasetH from ..data.dataset import DatasetH
@@ -295,7 +296,13 @@ class PortAnaRecord(RecordTemp):
artifact_path = "portfolio_analysis" artifact_path = "portfolio_analysis"
def __init__( def __init__(
self, recorder, config, risk_analysis_freq, indicator_analysis_freq, indicator_analysis_method=None, **kwargs self,
recorder,
config,
risk_analysis_freq: Union[List, str] = [],
indicator_analysis_freq: Union[List, str] = [],
indicator_analysis_method=None,
**kwargs,
): ):
""" """
config["strategy"] : dict config["strategy"] : dict