2024-07-25 16:18:00 +08:00
|
|
|
"""
|
|
|
|
|
Factor workflow with session control
|
|
|
|
|
"""
|
|
|
|
|
|
2024-07-26 14:29:19 +08:00
|
|
|
from typing import Any
|
|
|
|
|
|
2024-07-25 16:18:00 +08:00
|
|
|
import fire
|
|
|
|
|
|
|
|
|
|
from rdagent.app.qlib_rd_loop.conf import FACTOR_PROP_SETTING
|
|
|
|
|
from rdagent.components.workflow.rd_loop import RDLoop
|
|
|
|
|
from rdagent.core.exception import FactorEmptyError
|
2024-07-26 14:29:19 +08:00
|
|
|
from rdagent.log import rdagent_logger as logger
|
2024-09-20 16:05:59 +08:00
|
|
|
from rdagent.log.time import measure_time
|
2024-07-25 16:18:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class FactorRDLoop(RDLoop):
|
|
|
|
|
skip_loop_error = (FactorEmptyError,)
|
|
|
|
|
|
2024-09-20 16:05:59 +08:00
|
|
|
@measure_time
|
2024-07-29 18:02:17 +08:00
|
|
|
def running(self, prev_out: dict[str, Any]):
|
|
|
|
|
with logger.tag("ef"): # evaluate and feedback
|
|
|
|
|
exp = self.runner.develop(prev_out["coding"])
|
2024-07-26 14:29:19 +08:00
|
|
|
if exp is None:
|
|
|
|
|
logger.error(f"Factor extraction failed.")
|
|
|
|
|
raise FactorEmptyError("Factor extraction failed.")
|
2024-07-29 18:02:17 +08:00
|
|
|
logger.log_object(exp, tag="runner result")
|
2024-07-26 14:29:19 +08:00
|
|
|
return exp
|
|
|
|
|
|
2024-07-25 16:18:00 +08:00
|
|
|
|
|
|
|
|
def main(path=None, step_n=None):
|
|
|
|
|
"""
|
2024-08-08 17:10:37 +08:00
|
|
|
Auto R&D Evolving loop for fintech factors.
|
|
|
|
|
|
2024-07-25 16:18:00 +08:00
|
|
|
You can continue running session by
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
2024-08-08 17:10:37 +08:00
|
|
|
dotenv run -- python rdagent/app/qlib_rd_loop/factor.py $LOG_PATH/__session__/1/0_propose --step_n 1 # `step_n` is a optional paramter
|
2024-07-25 16:18:00 +08:00
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
if path is None:
|
|
|
|
|
model_loop = FactorRDLoop(FACTOR_PROP_SETTING)
|
|
|
|
|
else:
|
|
|
|
|
model_loop = FactorRDLoop.load(path)
|
|
|
|
|
model_loop.run(step_n=step_n)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2024-07-26 12:12:16 +08:00
|
|
|
fire.Fire(main)
|