mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-07-28 07:57:44 +00:00
String together the entire factor process
This commit is contained in:
@@ -25,5 +25,6 @@ class PropSetting(BaseSettings):
|
||||
evolving_n: int = 10
|
||||
|
||||
py_bin: str = "/usr/bin/python"
|
||||
local_qlib_folder: Path = Path("/home/rdagent/qlib")
|
||||
|
||||
PROP_SETTING = PropSetting()
|
||||
|
||||
@@ -25,6 +25,7 @@ hypothesis_gen: HypothesisGen = import_class(PROP_SETTING.qlib_factor_hypothesis
|
||||
hypothesis2experiment: Hypothesis2Experiment = import_class(PROP_SETTING.qlib_factor_hypothesis2experiment)()
|
||||
|
||||
qlib_factor_coder: TaskGenerator = import_class(PROP_SETTING.qlib_factor_coder)(scen)
|
||||
|
||||
qlib_factor_runner: TaskGenerator = import_class(PROP_SETTING.qlib_factor_runner)(scen)
|
||||
|
||||
qlib_factor_summarizer: HypothesisExperiment2Feedback = import_class(PROP_SETTING.qlib_factor_summarizer)(scen)
|
||||
@@ -38,21 +39,4 @@ for _ in range(PROP_SETTING.evolving_n):
|
||||
exp = qlib_factor_runner.generate(exp)
|
||||
feedback = qlib_factor_summarizer.generateFeedback(exp, hypothesis, trace)
|
||||
|
||||
trace.hist.append((hypothesis, exp, feedback))
|
||||
|
||||
|
||||
"""
|
||||
trace = Trace(scen=scen)
|
||||
# for _ in range(PROP_SETTING.evolving_n):
|
||||
for _ in range(1):
|
||||
hypothesis = hypothesis_gen.gen(trace)
|
||||
exp = hypothesis2experiment.convert(hypothesis, trace)
|
||||
# exp = qlib_factor_coder.generate(exp)
|
||||
import pickle
|
||||
file_path = '/home/finco/v-yuanteli/RD-Agent/git_ignore_folder/factor_data_output/exp_new.pkl'
|
||||
with open(file_path, 'rb') as file:
|
||||
exp = pickle.load(file)
|
||||
exp = qlib_factor_runner.generate(exp)
|
||||
feedback = qlib_factor_summarizer.generateFeedback(exp, hypothesis, trace)
|
||||
# trace.hist.append((hypothesis, exp, feedback))
|
||||
"""
|
||||
trace.hist.append((hypothesis, exp, feedback))
|
||||
@@ -149,7 +149,7 @@ class FactorEvolvingStrategy(MultiProcessEvolvingStrategy):
|
||||
queried_former_failed_knowledge=queried_former_failed_knowledge_to_render,
|
||||
)
|
||||
)
|
||||
session = APIBackend(use_chat_cache=True).build_chat_session(
|
||||
session = APIBackend(use_chat_cache=False).build_chat_session(
|
||||
session_system_prompt=system_prompt,
|
||||
)
|
||||
|
||||
@@ -249,7 +249,7 @@ class FactorEvolvingStrategyWithGraph(MultiProcessEvolvingStrategy):
|
||||
)
|
||||
)
|
||||
|
||||
session = APIBackend(use_chat_cache=True).build_chat_session(
|
||||
session = APIBackend(use_chat_cache=False).build_chat_session(
|
||||
session_system_prompt=system_prompt,
|
||||
)
|
||||
|
||||
@@ -276,7 +276,7 @@ class FactorEvolvingStrategyWithGraph(MultiProcessEvolvingStrategy):
|
||||
)
|
||||
.strip("\n")
|
||||
)
|
||||
session_summary = APIBackend(use_chat_cache=True).build_chat_session(
|
||||
session_summary = APIBackend(use_chat_cache=False).build_chat_session(
|
||||
session_system_prompt=error_summary_system_prompt,
|
||||
)
|
||||
for _ in range(10): # max attempt to reduce the length of error_summary_user_prompt
|
||||
|
||||
@@ -67,13 +67,13 @@ data_feedback_generation:
|
||||
}
|
||||
user: |-
|
||||
Target hypothesis:
|
||||
{{hypothesis}}
|
||||
{{ hypothesis_text }}
|
||||
Tasks and Factors:
|
||||
{{task_details}}
|
||||
{{ task_details }}
|
||||
Current Result:
|
||||
{{current_result}}
|
||||
{{ current_result }}
|
||||
SOTA Result:
|
||||
{{sota_result}}
|
||||
{{ sota_result }}
|
||||
Analyze the current result in the context of its ability to:
|
||||
1. Support or refute the hypothesis.
|
||||
2. Show improvement or deterioration compared to the last experiment.
|
||||
|
||||
@@ -24,6 +24,8 @@ logger = RDAgentLog()
|
||||
# de = DockerEnv()
|
||||
# de.run(local_path=self.ws_path, entry="qrun conf.yaml")
|
||||
|
||||
# TODO: supporting multiprocessing and keep previous results
|
||||
|
||||
class QlibFactorRunner(TaskGenerator[QlibFactorExperiment]):
|
||||
"""
|
||||
Docker run
|
||||
@@ -32,8 +34,6 @@ class QlibFactorRunner(TaskGenerator[QlibFactorExperiment]):
|
||||
- price-volume data dumper
|
||||
- `data.py` + Adaptor to Factor implementation
|
||||
- results in `mlflow`
|
||||
|
||||
- TODO: implement a qlib handler
|
||||
"""
|
||||
|
||||
def FetchAlpha158ResultFromDocker(self):
|
||||
@@ -86,8 +86,9 @@ class QlibFactorRunner(TaskGenerator[QlibFactorExperiment]):
|
||||
Generate the experiment by processing and combining factor data,
|
||||
then passing the combined data to Docker for backtest results.
|
||||
"""
|
||||
|
||||
SOTA_factor = self.process_factor_data(exp.based_experiments)
|
||||
SOTA_factor = None
|
||||
if exp.based_experiments.__len__() != 1:
|
||||
SOTA_factor = self.process_factor_data(exp.based_experiments)
|
||||
|
||||
if exp.based_experiments[-1].result is None:
|
||||
exp.based_experiments[-1].result = self.FetchAlpha158ResultFromDocker()
|
||||
@@ -133,6 +134,7 @@ class QlibFactorRunner(TaskGenerator[QlibFactorExperiment]):
|
||||
result = pickle.load(f)
|
||||
"""
|
||||
|
||||
# TODO: Implement the Docker run in the following way
|
||||
# Local run
|
||||
# Clean up any previous run artifacts by deleting the mlruns directory
|
||||
mlruns_path = DIRNAME_local / 'mlruns' / '1'
|
||||
@@ -147,7 +149,7 @@ class QlibFactorRunner(TaskGenerator[QlibFactorExperiment]):
|
||||
qle = LocalEnv(conf=local_conf)
|
||||
qle.prepare()
|
||||
conf_path = str(DIRNAME / "env_factor" / "conf_combined.yaml")
|
||||
qle.run(entry="qrun " + conf_path)
|
||||
qle.run(entry="qrun " + conf_path, local_path=PROP_SETTING.local_qlib_folder)
|
||||
|
||||
# Verify if the new folder is created
|
||||
mlrun_p = DIRNAME_local / 'mlruns' / '1'
|
||||
|
||||
@@ -39,20 +39,15 @@ class QlibFactorHypothesisExperiment2Feedback(HypothesisExperiment2Feedback):
|
||||
hypothesis_text = hypothesis.hypothesis
|
||||
current_result = exp.result
|
||||
tasks_factors = [task.get_factor_information() for task in exp.sub_tasks]
|
||||
|
||||
sota_result = exp.based_experiments[-1].result
|
||||
|
||||
# Generate the system prompt
|
||||
sys_prompt = Environment(undefined=StrictUndefined).from_string(feedback_prompts["data_feedback_generation"]["system"]).render(scenario=self.scen.get_scenario_all_desc())
|
||||
|
||||
|
||||
# Prepare task details
|
||||
task_details = "\n".join([f"Task: {factor_name}, Factor: {factor_description}" for factor_name, factor_description in tasks_factors])
|
||||
|
||||
# Generate the user prompt
|
||||
usr_prompt = Environment(undefined=StrictUndefined).from_string(feedback_prompts["data_feedback_generation"]["user"]).format(
|
||||
usr_prompt = Environment(undefined=StrictUndefined).from_string(feedback_prompts["data_feedback_generation"]["user"]).render(
|
||||
hypothesis_text=hypothesis_text,
|
||||
task_details=task_details,
|
||||
task_details=tasks_factors,
|
||||
current_result=current_result,
|
||||
sota_result=sota_result
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user