From 19747d02aec7e776b73c82e74a1248effc104d60 Mon Sep 17 00:00:00 2001 From: booksword Date: Sat, 5 Nov 2022 09:01:03 +0800 Subject: [PATCH 1/6] add missing parameters to doc string in order_generate --- qlib/contrib/strategy/order_generator.py | 48 ++++++++++++++++-------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/qlib/contrib/strategy/order_generator.py b/qlib/contrib/strategy/order_generator.py index 9e84d50466..fe0d048bfd 100644 --- a/qlib/contrib/strategy/order_generator.py +++ b/qlib/contrib/strategy/order_generator.py @@ -33,10 +33,14 @@ def generate_order_list_from_target_weight_position( :type target_weight_position: dict :param risk_degree: :type risk_degree: float - :param pred_date: the date the score is predicted - :type pred_date: pd.Timestamp - :param trade_date: the date the stock is traded - :type trade_date: pd.Timestamp + :param pred_start_time: + :type pred_start_time: pd.Timestamp + :param pred_end_time: + :type pred_end_time: pd.Timestamp + :param trade_start_time: + :type trade_start_time: pd.Timestamp + :param trade_end_time: + :type trade_end_time: pd.Timestamp :rtype: list """ @@ -72,10 +76,14 @@ def generate_order_list_from_target_weight_position( :type target_weight_position: dict :param risk_degree: :type risk_degree: float - :param pred_date: - :type pred_date: pd.Timestamp - :param trade_date: - :type trade_date: pd.Timestamp + :param pred_start_time: + :type pred_start_time: pd.Timestamp + :param pred_end_time: + :type pred_end_time: pd.Timestamp + :param trade_start_time: + :type trade_start_time: pd.Timestamp + :param trade_end_time: + :type trade_end_time: pd.Timestamp :rtype: list """ @@ -147,9 +155,12 @@ def generate_order_list_from_target_weight_position( ) -> list: """generate_order_list_from_target_weight_position - generate order list directly not using the information (e.g. whether can be traded, the accurate trade price) at trade date. - In target weight position, generating order list need to know the price of objective stock in trade date, but we cannot get that - value when do not interact with exchange, so we check the %close price at pred_date or price recorded in current position. + generate order list directly not using the information (e.g. whether can be traded, the accurate trade price) + at trade date. + In target weight position, generating order list need to know the price of objective stock in trade date, + but we cannot get that + value when do not interact with exchange, so we check the %close price at pred_date or price recorded + in current position. :param current: :type current: Position @@ -159,10 +170,14 @@ def generate_order_list_from_target_weight_position( :type target_weight_position: dict :param risk_degree: :type risk_degree: float - :param pred_date: - :type pred_date: pd.Timestamp - :param trade_date: - :type trade_date: pd.Timestamp + :param pred_start_time: + :type pred_start_time: pd.Timestamp + :param pred_end_time: + :type pred_end_time: pd.Timestamp + :param trade_start_time: + :type trade_start_time: pd.Timestamp + :param trade_end_time: + :type trade_end_time: pd.Timestamp :rtype: list of generated orders """ @@ -185,7 +200,8 @@ def generate_order_list_from_target_weight_position( * target_weight_position[stock_id] / trade_exchange.get_close(stock_id, start_time=pred_start_time, end_time=pred_end_time) ) - # TODO: Qlib use None to represent trading suspension. So last close price can't be the estimated trading price. + # TODO: Qlib use None to represent trading suspension. + # So last close price can't be the estimated trading price. # Maybe a close price with forward fill will be a better solution. elif stock_id in current_stock: amount_dict[stock_id] = ( From d13bd1d58ac484abe8529e13faba066ef0d19a34 Mon Sep 17 00:00:00 2001 From: booksword Date: Sat, 5 Nov 2022 10:29:52 +0800 Subject: [PATCH 2/6] fix some typos in doc strings --- examples/run_all_model.py | 2 +- qlib/backtest/__init__.py | 6 +++--- qlib/backtest/account.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/run_all_model.py b/examples/run_all_model.py index 71589049a2..3a1f9ecf6a 100644 --- a/examples/run_all_model.py +++ b/examples/run_all_model.py @@ -253,7 +253,7 @@ def run( default "" indicates that qlib_uri : str the uri to install qlib with pip - it could be url on the we or local path (NOTE: the local path must be a absolute path) + it could be url on the git or local path (NOTE: the local path must be an absolute path) exp_folder_name: str the name of the experiment folder wait_before_rm_env : bool diff --git a/qlib/backtest/__init__.py b/qlib/backtest/__init__.py index 81c6437d6d..bcca27b28a 100644 --- a/qlib/backtest/__init__.py +++ b/qlib/backtest/__init__.py @@ -244,7 +244,7 @@ def backtest( benchmark: str the benchmark for reporting. account : Union[float, int, Position] - information for describing how to creating the account + information for describing how to creat the account For `float` or `int`: Using Account with only initial cash For `Position`: @@ -341,9 +341,9 @@ def format_decisions( last_dec_idx = 0 for i, dec in enumerate(decisions[1:], 1): if dec.strategy.trade_calendar.get_freq() == cur_freq: - res[1].append((decisions[last_dec_idx], format_decisions(decisions[last_dec_idx + 1 : i]))) + res[1].append((decisions[last_dec_idx], format_decisions(decisions[last_dec_idx+1:i]))) last_dec_idx = i - res[1].append((decisions[last_dec_idx], format_decisions(decisions[last_dec_idx + 1 :]))) + res[1].append((decisions[last_dec_idx], format_decisions(decisions[last_dec_idx + 1:]))) return res diff --git a/qlib/backtest/account.py b/qlib/backtest/account.py index 6054ac638b..9d60ff0924 100644 --- a/qlib/backtest/account.py +++ b/qlib/backtest/account.py @@ -236,7 +236,7 @@ def update_current_position( if not self.current_position.skip_update(): stock_list = self.current_position.get_stock_list() for code in stock_list: - # if suspend, no new price to be updated, profit is 0 + # if suspended, no new price to be updated, profit is 0 if trade_exchange.check_stock_suspended(code, trade_start_time, trade_end_time): continue bar_close = cast(float, trade_exchange.get_close(code, trade_start_time, trade_end_time)) From b061842715f9a6bf2c81bd92090fb5b7b51d05d4 Mon Sep 17 00:00:00 2001 From: booksword Date: Sat, 5 Nov 2022 10:36:08 +0800 Subject: [PATCH 3/6] reformat base on code style standard --- qlib/backtest/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qlib/backtest/__init__.py b/qlib/backtest/__init__.py index bcca27b28a..7870912387 100644 --- a/qlib/backtest/__init__.py +++ b/qlib/backtest/__init__.py @@ -341,9 +341,9 @@ def format_decisions( last_dec_idx = 0 for i, dec in enumerate(decisions[1:], 1): if dec.strategy.trade_calendar.get_freq() == cur_freq: - res[1].append((decisions[last_dec_idx], format_decisions(decisions[last_dec_idx+1:i]))) + res[1].append((decisions[last_dec_idx], format_decisions(decisions[last_dec_idx + 1 : i]))) last_dec_idx = i - res[1].append((decisions[last_dec_idx], format_decisions(decisions[last_dec_idx + 1:]))) + res[1].append((decisions[last_dec_idx], format_decisions(decisions[last_dec_idx + 1 :]))) return res From 857aeccc22b1da0ecb802af4d348f9424c2e79ec Mon Sep 17 00:00:00 2001 From: you-n-g Date: Mon, 7 Nov 2022 23:35:35 +0800 Subject: [PATCH 4/6] Update qlib/backtest/__init__.py --- qlib/backtest/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qlib/backtest/__init__.py b/qlib/backtest/__init__.py index 7870912387..aca45f4e1e 100644 --- a/qlib/backtest/__init__.py +++ b/qlib/backtest/__init__.py @@ -244,7 +244,7 @@ def backtest( benchmark: str the benchmark for reporting. account : Union[float, int, Position] - information for describing how to creat the account + information for describing how to create the account For `float` or `int`: Using Account with only initial cash For `Position`: From 4aa382dce81f98279e7715cd43b3225bca3089a2 Mon Sep 17 00:00:00 2001 From: you-n-g Date: Mon, 7 Nov 2022 23:36:36 +0800 Subject: [PATCH 5/6] Update examples/run_all_model.py --- examples/run_all_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/run_all_model.py b/examples/run_all_model.py index 3a1f9ecf6a..275ddb2155 100644 --- a/examples/run_all_model.py +++ b/examples/run_all_model.py @@ -253,7 +253,7 @@ def run( default "" indicates that qlib_uri : str the uri to install qlib with pip - it could be url on the git or local path (NOTE: the local path must be an absolute path) + it could be url on the remote or local path (NOTE: the local path must be an absolute path) exp_folder_name: str the name of the experiment folder wait_before_rm_env : bool From 3517a8f195cc74482df59bc75ed5c8aae204e829 Mon Sep 17 00:00:00 2001 From: you-n-g Date: Mon, 7 Nov 2022 23:37:00 +0800 Subject: [PATCH 6/6] Update examples/run_all_model.py --- examples/run_all_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/run_all_model.py b/examples/run_all_model.py index 275ddb2155..dda3b98f62 100644 --- a/examples/run_all_model.py +++ b/examples/run_all_model.py @@ -253,7 +253,7 @@ def run( default "" indicates that qlib_uri : str the uri to install qlib with pip - it could be url on the remote or local path (NOTE: the local path must be an absolute path) + it could be URI on the remote or local path (NOTE: the local path must be an absolute path) exp_folder_name: str the name of the experiment folder wait_before_rm_env : bool