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 backtest and backforward task #1568

Merged

Conversation

Fivele-Li
Copy link
Contributor

  • add TrainTask & BacktestTask;
  • add BackForwardTask;
  • adjust prompt_template.yaml which default config failed to backtest;
  • run workflow in loop
  • add update method to prompt_template.py

Description

Motivation and Context

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:
  2. Your own tests:

Types of changes

  • Fix bugs
  • Add new feature
  • Update documentation

* add BackForwardTask;
* adjust prompt_template.yaml which default config failed to backtest;
* run workflow in loop
* add update method to prompt_template.py
@github-actions github-actions bot added the waiting for triage Cannot auto-triage, wait for triage. label Jun 25, 2023
@@ -193,6 +193,13 @@ SummarizeTask_user : |-
Here is my information: '{{information}}'
My intention is: {{user_prompt}}. Please provide me with a summary and recommendation based on my intention and the information I have provided. There are some figures which absolute path are: {{figure_path}}, You must display these images in markdown using the appropriate image format.

BackForwardTask_system : |-
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will it be clearer if we use the following format?

BackForwardTask:
     system:
     user: 


with R.start(experiment_name="finCo", resume=True):
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't have to use start.
We can just get the recorder and update it.

self._context_manager.set_context("model", model)
self._context_manager.set_context("dataset", dataset)

return [RecorderTask()]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not return a CMDTask with qrun XXX.yaml?

return [BackTestTask()]


class BackTestTask(Task):
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 backtest is done in qrun in CMDTask.
What we need to do is to analysis it further.

@@ -648,3 +702,38 @@ def get_figure_path(self):
def save_markdown(self, content: str):
with open(Path(self.workspace).joinpath(self.__DEFAULT_REPORT_NAME), "w") as f:
f.write(content)


class BackForwardTask(Task):
Copy link
Collaborator

Choose a reason for hiding this comment

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

When we fine-tune the prompt, we don't have to define it as an instance of Task.

The prompt fine-tuning is supposed to be a learning workflow at an upper level. So, they do not necessarily share the same concepts.

@@ -15,6 +15,7 @@ class WorkflowContextManager:

def __init__(self) -> None:
self.context = {}
self.epoch = 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

If there is a learning workflow outside, WorkflowContextManager is not necessarily aware of the learning process.

task_list = res + task_list

# todo: add early stop condition
for i in range(10):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think the learning process should be coupled with Workflow Manager.

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 learnManager

* add LearnManager class & use LearnManager to update system prompt;
* use qrun to replace recorder for training and backtesting;
self._context_manager.set_context("dataset", dataset)
self._context_manager.set_context("recorder", recorder)
command = f"qrun {workflow_path}"
self._output = subprocess.check_output(command, shell=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please set cwd to make sure the mlflow results are generated in the workspace.

Otherwise you can use CMDTask

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 cwd to check_output.

dataset=self._context_manager.get_context("dataset"),
recorder=self._context_manager.get_context("recorder"),
workspace=workspace,
model=model,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think SignalRecord is one of Analysor.
Please refer to SignalAnalyzer.__name__: SignalRecord,
Thus model and dataset is not necessary paramters

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Analyser is independent of Recorder now

model=self._context_manager.get_context("model"),
dataset=self._context_manager.get_context("dataset"),
recorder=self._context_manager.get_context("recorder"),
workspace=workspace,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is workspace necessary if we already passed the recorder?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed workspace to output_dir

* analyser independent of recorder;
* rename analyser's workspace attribution;
* analyser load variable by recorder.
@Fivele-Li Fivele-Li added enhancement New feature or request and removed waiting for triage Cannot auto-triage, wait for triage. labels Jun 30, 2023
@Fivele-Li Fivele-Li merged commit 7e84f3a into microsoft:finco Jun 30, 2023
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