Download scripts/run_llm_strategy.py from lucky-loster/quant_test: direct link, hf CLI and curl.
- Browser
- Download file 2.17 kB
-
https://huggingface.co/lucky-loster/quant_test/resolve/main/scripts/run_llm_strategy.py
- Command line
-
hf download hf://lucky-loster/quant_test/scripts/run_llm_strategy.py
-
curl -L -o run_llm_strategy.py https://huggingface.co/lucky-loster/quant_test/resolve/main/scripts/run_llm_strategy.py
2.17 kB
| #!/usr/bin/env python3 | |
| """Use QuantaAlpha-compatible LLM API to propose and run a strategy.""" | |
| import argparse | |
| import json | |
| import sys | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| if str(ROOT) not in sys.path: | |
| sys.path.insert(0, str(ROOT)) | |
| from config.settings import load_settings | |
| from integrations.quantaalpha.llm_strategy import build_llm_strategy_plan, save_strategy_plan | |
| from strategies.runner import run_strategy_backtest, save_backtest_result | |
| def main(): | |
| parser = argparse.ArgumentParser(description="LLM-driven strategy planning + backtest (QuantaAlpha API)") | |
| parser.add_argument("--library", type=str, default=None, help="QuantaAlpha factor library JSON") | |
| parser.add_argument("--factor-panel", type=str, default=None, help="Pre-mined factor panel parquet/csv") | |
| parser.add_argument("--market-context", type=str, default=None) | |
| parser.add_argument("--dry-run", action="store_true", help="Only generate LLM plan, skip backtest") | |
| parser.add_argument("--start", type=str, default=None) | |
| parser.add_argument("--end", type=str, default=None) | |
| parser.add_argument("--output-dir", type=str, default=None) | |
| args = parser.parse_args() | |
| plan = build_llm_strategy_plan( | |
| library_path=args.library, | |
| factor_panel_path=args.factor_panel, | |
| market_context=args.market_context, | |
| ) | |
| settings = load_settings() | |
| plan_dir = settings.output_root / "strategies" / "llm_plans" | |
| plan_path = save_strategy_plan(plan, plan_dir / "latest_plan.json") | |
| print(f"LLM plan saved: {plan_path}") | |
| print(json.dumps(plan["llm_plan"], ensure_ascii=False, indent=2)) | |
| if args.dry_run: | |
| return | |
| result = run_strategy_backtest( | |
| strategy_name=plan["strategy"]["name"], | |
| signal_source=plan["signal_source"], | |
| strategy_kwargs=plan["strategy"].get("kwargs"), | |
| start_time=args.start, | |
| end_time=args.end, | |
| ) | |
| out_dir = Path(args.output_dir) if args.output_dir else settings.output_root / "backtest" / "llm_strategy" | |
| save_backtest_result(result, out_dir) | |
| print(f"Backtest complete: {out_dir}") | |
| if __name__ == "__main__": | |
| main() | |