Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/run_all_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion qlib/backtest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create

For `float` or `int`:
Using Account with only initial cash
For `Position`:
Expand Down
2 changes: 1 addition & 1 deletion qlib/backtest/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
48 changes: 32 additions & 16 deletions qlib/contrib/strategy/order_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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
"""
Expand Down Expand Up @@ -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
Expand All @@ -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
"""
Expand All @@ -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] = (
Expand Down