feat(orchestrator): example scripts for backtest and live mode
This commit is contained in:
parent
480f0299b0
commit
ce2e6d32cc
|
|
@ -0,0 +1,41 @@
|
|||
"""
|
||||
Example: Run orchestrator backtest for 宁德时代 (300750.SZ) over 2023.
|
||||
|
||||
Usage:
|
||||
cd /path/to/TradingAgents
|
||||
QUANT_BACKTEST_PATH=/path/to/quant_backtest python orchestrator/examples/run_backtest.py
|
||||
"""
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
# Add repo root to path
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
|
||||
from orchestrator.config import OrchestratorConfig
|
||||
from orchestrator.orchestrator import TradingOrchestrator
|
||||
from orchestrator.backtest_mode import BacktestMode
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s: %(message)s")
|
||||
|
||||
config = OrchestratorConfig(
|
||||
quant_backtest_path=os.environ.get("QUANT_BACKTEST_PATH", ""),
|
||||
cache_dir="orchestrator/cache",
|
||||
)
|
||||
|
||||
orchestrator = TradingOrchestrator(config)
|
||||
backtest = BacktestMode(orchestrator)
|
||||
|
||||
result = backtest.run(
|
||||
tickers=["300750.SZ"],
|
||||
start_date="2023-01-01",
|
||||
end_date="2023-12-31",
|
||||
)
|
||||
|
||||
print(f"\n=== Backtest Summary ===")
|
||||
print(json.dumps(result.summary, indent=2, ensure_ascii=False))
|
||||
print(f"\nTotal records: {len(result.records)}")
|
||||
if result.records:
|
||||
print(f"First record: {result.records[0]}")
|
||||
print(f"Last record: {result.records[-1]}")
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
"""
|
||||
Example: Run orchestrator live mode for a list of tickers.
|
||||
|
||||
Usage:
|
||||
cd /path/to/TradingAgents
|
||||
QUANT_BACKTEST_PATH=/path/to/quant_backtest python orchestrator/examples/run_live.py
|
||||
"""
|
||||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
from datetime import datetime, timezone
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
|
||||
from orchestrator.config import OrchestratorConfig
|
||||
from orchestrator.orchestrator import TradingOrchestrator
|
||||
from orchestrator.live_mode import LiveMode
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s: %(message)s")
|
||||
|
||||
TICKERS = ["300750.SZ", "603259.SS"]
|
||||
|
||||
config = OrchestratorConfig(
|
||||
quant_backtest_path=os.environ.get("QUANT_BACKTEST_PATH", ""),
|
||||
cache_dir="orchestrator/cache",
|
||||
)
|
||||
|
||||
orchestrator = TradingOrchestrator(config)
|
||||
live = LiveMode(orchestrator)
|
||||
|
||||
|
||||
async def main():
|
||||
today = datetime.now(timezone.utc).strftime("%Y-%m-%d")
|
||||
print(f"\n=== Live Signals for {today} ===")
|
||||
results = await live.run_once(TICKERS, date=today)
|
||||
print(json.dumps(results, indent=2, ensure_ascii=False))
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
Loading…
Reference in New Issue