Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] allow sell in limit-up case and allow buy in limit-down case in topk strategy #1407

Merged
merged 7 commits into from Jan 10, 2023

Conversation

qianyun210603
Copy link
Contributor

Description

Allow sell in limit-up case and allow buy in limit-down case
Also fixed some typo/typehints.

Motivation and Context

To be consistent with real world, in which we can buy at limit-down (跌停) and sell at limit up (涨停).

How Has This Been Tested?

  • Pass the test by running: pytest qlib/tests/test_all_pipeline.py under upper directory of qlib.
  • If you are adding a new feature, test on your own test scripts.

Screenshots of Test Results (if appropriate):

  1. Pipeline test:
    image
  2. Your own tests:

Types of changes

  • Fix bugs
  • Add new feature
  • Update documentation

@github-actions github-actions bot added the waiting for triage Cannot auto-triage, wait for triage. label Jan 3, 2023
Believe it's just some arbitrary number.
The excess return is expected to change when trading logic changes.
@@ -216,7 +217,7 @@ def filter_stock(li):
buy = today[: len(sell) + self.topk - len(last)]
for code in current_stock_list:
if not self.trade_exchange.is_stock_tradable(
stock_id=code, start_time=trade_start_time, end_time=trade_end_time
stock_id=code, start_time=trade_start_time, end_time=trade_end_time, direction=OrderDir.SELL
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for your contribution. @qianyun210603
Not selling limit-up stocks and buying limit-down could be considered as a part of the strategy in A-stock.
Although current implementation seems a little weird, but it is a reasonable results.

Your version is better. But if we merge it currently, all the previous results should be updated to make the code and results consistent (it will take a long time to update all the results).

Would it be better if we add it as a feature (a parameter in the init method) and keep the previous version as the default behavior?
(Besides, TODOs to switch to your version should be added in the docs/docstrings)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a flag in TopkDropoutStrategy defaults to True to keep previous behaviour as suggested.

@you-n-g you-n-g merged commit d876466 into microsoft:main Jan 10, 2023
@you-n-g
Copy link
Collaborator

you-n-g commented Jan 10, 2023

Thanks! It looks great now!

@you-n-g you-n-g added enhancement New feature or request and removed waiting for triage Cannot auto-triage, wait for triage. labels Jan 10, 2023
qianyun210603 added a commit to qianyun210603/qlib that referenced this pull request Mar 23, 2023
… in topk strategy (microsoft#1407)

* 1) check limit_up/down should consider direction; 2) fix some typo, typehint etc

* fix error

* Update test_all_pipeline.py

Believe it's just some arbitrary number.
The excess return is expected to change when trading logic changes.

* add flag forbid_all_trade_at_limit to keep previous behivour for backward compatibility
qianyun210603 added a commit to qianyun210603/qlib that referenced this pull request Mar 23, 2023
… in topk strategy (microsoft#1407)

* 1) check limit_up/down should consider direction; 2) fix some typo, typehint etc

* fix error

* Update test_all_pipeline.py

Believe it's just some arbitrary number.
The excess return is expected to change when trading logic changes.

* add flag forbid_all_trade_at_limit to keep previous behivour for backward compatibility
qianyun210603 added a commit to qianyun210603/qlib that referenced this pull request Mar 23, 2023
… in topk strategy (microsoft#1407)

* 1) check limit_up/down should consider direction; 2) fix some typo, typehint etc

* fix error

* Update test_all_pipeline.py

Believe it's just some arbitrary number.
The excess return is expected to change when trading logic changes.

* add flag forbid_all_trade_at_limit to keep previous behivour for backward compatibility
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants