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 util function to help automatically get horizon #1509

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

chenditc
Copy link
Contributor

@chenditc chenditc commented May 10, 2023

Add util function to help automatically get horizon

Description

Add util function to help automatically get horizon

Motivation and Context

In some code like TRA and DDG-DA, horizon is manually passed into the model. Which is not convenient to automate the workflow. Add a util function to help guess the horizon by label.

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:
    image

qrun workflow_config_tra_Alpha158.yaml and remove the "horizon" field in the yaml config

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 May 10, 2023
# Try to guess horizon
if isinstance(handler, dict):
handler = init_instance_by_config(handler)
elif isinstance(handler, str): # pickled handler
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we write it like this?
if isinstance(handler, (dict, str))

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

# Unlikely the label doesn't use future information
if max_horizon < 2:
return 0
return max_horizon + 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it return max_horizon+1 here instead of return max_horizon or return max_horizon-min_horizon?

Copy link
Contributor Author

@chenditc chenditc May 18, 2023

Choose a reason for hiding this comment

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

This is consistent with exisiting deinition of "horizon" in other code like DDG-DA and TRA. There is no official documentation, TRA workflow config use max_horizon to truncate and DDG-DA use max_horizon + 1. I use max_horizon + 1 here just to make things safe.

Any suggestion from qlib team?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for triage Cannot auto-triage, wait for triage.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants