From 94e420f755f534650e23366af3f6bea0eb98b63b Mon Sep 17 00:00:00 2001 From: qianyun210603 Date: Mon, 7 Nov 2022 23:37:18 +0800 Subject: [PATCH] Correct errors and typos in doc strings (#1338) * add missing parameters to doc string in order_generate * fix some typos in doc strings * reformat base on code style standard * Update qlib/backtest/__init__.py * Update examples/run_all_model.py * Update examples/run_all_model.py Co-authored-by: you-n-g --- examples/run_all_model.py | 2 +- qlib/backtest/__init__.py | 2 +- qlib/backtest/account.py | 2 +- qlib/contrib/strategy/order_generator.py | 48 ++++++++++++++++-------- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/examples/run_all_model.py b/examples/run_all_model.py index 71589049a2..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 we or local path (NOTE: the local path must be a 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 diff --git a/qlib/backtest/__init__.py b/qlib/backtest/__init__.py index 81c6437d6d..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 creating the account + information for describing how to create the account For `float` or `int`: Using Account with only initial cash For `Position`: 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)) 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] = (