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

Add multi pass portfolio analysis record #1546

Merged
merged 10 commits into from
Aug 4, 2023

Conversation

chenditc
Copy link
Contributor

@chenditc chenditc commented Jun 10, 2023

Description

Add a new record to initialize position randomly and run backtest multiple times.

Motivation and Context

Signal based strategy's performance can be variant due to initial position setup. To better evalute the performance of each model, this recorder will:

  1. Randomly shuffle the prediction signal of first backtest date, so that initial position will be random.
  2. Run the backtest multiple times.
  3. Aggregate the portfolio performance and publish the metrics.

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.

Added an example benchmark config yaml, run with the example yaml.

$ qrun workflow_config_backward_alstm_Alpha158WithBenchDiff_full.yaml

Screenshots of Test Results (if appropriate):

  1. Pipeline test:
    image

  2. Your own tests:
    image

I also ran test on existing workflow file and confirmed the format of out is the same.

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 Jun 10, 2023
# Reset strategy so that pred df can be replaced in next generate
self.strategy_config = deepcopy_basic_type(self.original_strategy)

self.save(**{"pred.pkl": pred_df})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need to save the shuffled prediction?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

self.random_init()

# Not check for cache file list
super()._generate(**kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is generating files that is out of the scope of the class.
Would you think it is better to redefine  ACRecordTemp  _generate to def _generate(self, *args, **kwargs) -> Dict[str, obj]:
And save the return objects in  ACRecordTemp  generate?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Besides , this will make other code simpler

risk_analysis_df_map = {}

# Collect each frequency's analysis df as df list
for i in range(self.pass_num):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think adding tqdm would improve the UE.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@chenditc
Copy link
Contributor Author

The pipeline failure seems related to global python setup issue, not caused by my change.

@you-n-g
Copy link
Collaborator

you-n-g commented Jun 18, 2023

Yes. It is due to an error in data storage. We'll fix it later.

@you-n-g
Copy link
Collaborator

you-n-g commented Jul 11, 2023

@chenditc
The CI issue on the master branch has been fixed.
Please merge it to run the latest CI.

@chenditc
Copy link
Contributor Author

@chenditc The CI issue on the master branch has been fixed. Please merge it to run the latest CI.

@you-n-g CI has passed. Good to merge?

@Fivele-Li Fivele-Li added enhancement New feature or request and removed waiting for triage Cannot auto-triage, wait for triage. labels Aug 4, 2023
@Fivele-Li Fivele-Li merged commit 05d67b3 into microsoft:main Aug 4, 2023
23 checks passed
@Fivele-Li
Copy link
Contributor

Merged! Thanks a lot~

PaleNeutron pushed a commit to PaleNeutron/qlib that referenced this pull request Oct 11, 2023
* Add multi pass port ana record

* Add list function

* Add documentation and support <MODEL> tag

* Add drop in replacement example

* reformat

* Change according to comments

* update format

* Update record_temp.py

Fix type hint

* Update record_temp.py
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.

3 participants