Commit Graph

31 Commits

Author SHA1 Message Date
TPTBusiness 0651faed92 feat: unified backtest engine, LLM error handling, strategy refactor
- Add vbt_backtest.py as single source of truth for all metric formulas
  (Sharpe, drawdown, IC, transaction costs) — backtest_engine.py and
  strategy_orchestrator.py now delegate to it
- Add LLMUnavailableError to exception.py; rd_loop.py catches it at the
  proposal stage and raises LoopResumeError to avoid corrupting trace
  history with None hypotheses
- Guard record() against None exp/hypothesis so loop resets leave
  trace.hist in a consistent state
- Refactor strategy_orchestrator and optuna_optimizer to use unified
  backtest path; remove duplicate metric calculation code
- Add predix_rebacktest_unified.py script for offline re-evaluation
- Update tests and README

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-17 22:52:07 +02:00
TPTBusiness c78ecd3b6a feat: add daily log rotation, llama health wait, factor auto-fixer, and README updates
- Add rdagent/log/daily_log.py: daily-rotating structured logs per command
  (fin_quant, strategies, evaluate, parallel) with loguru; all.log combined sink
- predix.py: route TeeWriter output to logs/YYYY-MM-DD/ instead of root dir;
  wrap quant() and evaluate() in daily_log.session() for start/stop/duration tracking
- rdagent/app/cli.py: fin_quant_cli waits for llama.cpp /health endpoint before
  starting pipeline (up to 300 s); daily_log integration for fin_quant,
  generate_strategies, eval_all, parallel commands
- scripts/predix_gen_strategies_real_bt.py: daily_log integration with
  per-strategy ACCEPTED/REJECTED entries and summary on completion
- rdagent/components/coder/factor_coder/auto_fixer.py: new module that patches
  common LLM-generated factor issues (min_periods, inf/NaN, groupby.transform,
  MultiIndex corrections)
- rdagent/components/coder/factor_coder/prompts.yaml: add critical rules for
  EURUSD 1-min intraday factors (min_periods, inf handling, groupby, date range)
- README.md: document --reasoning off and --n-gpu-layers 28 for llama-server;
  explain VRAM constraints when Ollama is running alongside llama.cpp
- .bandit.yml: suppress B615 (HuggingFace unsafe download) for RL benchmark files

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-16 07:20:08 +02:00
TPTBusiness df61b90464 feat(strategy): Continuous optimization with Optuna parameter injection
- Optuna now runs for ALL strategies (accepted AND rejected)
- Fix critical bug: Optuna parameters are now injected into LLM-generated
  code via regex patching (entry_thresh, exit_thresh, window, signal_window)
  Previously all 30 trials executed identical code producing the same Sharpe
- Add continuous optimization loop (--max-iterations) for repeated
  strategy generation and optimization cycles
- Improve prompt v5 with better IC-inversion examples and realistic
  code templates
- Expand Optuna search space: zscore_window, signal_bias, max_hold_bars
- CLI: add --continuous, --max-iterations, --optuna-trials flags
- Show best strategy with optimized parameters in summary output
2026-04-12 20:06:13 +02:00
TPTBusiness d6c41c096d fix(strategy): Fix template variables, APIBackend import, and JSON extraction
- Fix {{ ic_values }} template variable not being replaced in prompts
- Fix APIBackend abstract class import (use factory from llm_utils)
- Add robust JSON extraction with python code block fallback
- Add response_format json_object to LLM payload
- Add detailed debug logging for LLM responses
- Simplify prompt variable replacement for readability

Files:
  rdagent/components/coder/strategy_orchestrator.py
  rdagent/components/prompt_loader.py
  rdagent/app/cli.py
  prompts/strategy_generation_v4.yaml
2026-04-12 14:47:25 +02:00
TPTBusiness 9d058e131f feat: Add beautiful CLI welcome screen for GitHub README
Added 'rdagent predix' command showing:
- System status (factors, strategies, security)
- Available commands table
- Quick start guide
- Version and release info

Perfect for GitHub README screenshots.

Also fixed release tag to use today's date (2026.04.10).
2026-04-10 12:10:38 +02:00
TPTBusiness 2baa99e337 feat: Add 6 new CLI commands - all scripts integrated with local LLM
New CLI commands:
- rdagent parallel: Run parallel factor experiments (-n 10 -k 2)
- rdagent eval_all: Evaluate factors with full data (--top 500 -p 8)
- rdagent batch_backtest: Batch backtest factors (--all -p 4)
- rdagent simple_eval: Direct IC/Sharpe computation (--top 100 -p 4)
- rdagent rebacktest: Re-backtest existing strategies
- rdagent report: Generate PDF performance reports

All commands:
- Default to local llama.cpp (no cloud models)
- Have proper --help documentation
- Support parallel workers for speed
- Handle Ctrl+C gracefully

Updated CLI help with complete command list.
2026-04-09 15:47:46 +02:00
TPTBusiness 01d1f31367 docs: Add comprehensive CLI help and update README with quick start
Added to CLI help (rdagent --help):
- Complete list of all commands with examples
- Categorized by function (Trading, Strategy, Server, RL, Utils)
- Usage examples for each command
- Quick start examples

Updated README.md Quick Start section:
- Step 1: Start LLM Server (rdagent start_llama)
- Step 2: Run Trading Loop (rdagent fin_quant)
- Step 3: Start Strategy Generator Loop (rdagent start_loop)
- Step 4: Monitor Results (rdagent server_ui)
- Step 5: Generate Strategies Manually

All commands now have proper documentation in:
- CLI --help text
- README.md Quick Start
- Individual command --help
2026-04-09 15:09:44 +02:00
TPTBusiness 02bf326767 feat: Add start_llama and start_loop CLI commands
Added to rdagent CLI:
- rdagent start_llama: Start llama.cpp server (replaces start_llama.sh)
- rdagent start_loop: Start strategy generator loop (replaces start_strategy_loop.sh)

Features:
- start_llama: --model, --port, --gpu-layers, --ctx-size, --reasoning options
- start_loop: --target, --max-wait options with auto-restart on crash
- Both commands have full help (--help) and examples

Moved .sh scripts to scripts/:
- start_llama.sh → scripts/ (kept as reference)
- start_strategy_loop.sh → scripts/ (kept as reference)

Usage:
  rdagent start_llama                    # Start LLM server
  rdagent start_llama --gpu-layers 40    # Custom GPU layers
  rdagent start_loop                     # Start strategy loop
  rdagent start_loop --target 5          # Generate 5 strategies per run
2026-04-09 14:49:00 +02:00
TPTBusiness ab3748fbfe feat: Strategy Generator working with local LLM (P0-P4)
Integrated strategy generation into fin_quant loop:
- Fixed LLM code extraction from JSON responses
- Fixed factor loading (MultiIndex parquet handling)
- Fixed return calculation (realistic proxy)
- Fixed max drawdown (NaN/inf handling)
- Added llama.cpp --reasoning off support
- Strategy orchestrator with LLM + evaluation
- Optuna optimizer integration

100% acceptance rate on test run (2/2 strategies).
Total changes: +2006 lines, -129 lines across 8 files.

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-04-09 12:55:04 +02:00
TPTBusiness a91702631e feat: Add CLI model selection (local vs OpenRouter)
- Add --model/-m flag to select LLM backend
  * local: llama.cpp on localhost (default)
  * openrouter: Cloud models via OpenRouter API
- Create predix.py as new CLI entry point with model selection
- Add OPENROUTER_API_KEY and OPENROUTER_MODEL to .env
- Add health and status commands to CLI
- Update rdagent/app/cli.py with model selection logic

Usage:
  predix quant                    # Local (default)
  predix quant -m openrouter      # OpenRouter cloud
  predix quant -m local -d        # Local + dashboard

Tests: 93 passed
2026-04-04 08:26:48 +02:00
TPTBusiness 2136741eaa feat: Full system integration - RL + Protections + Backtesting + CLI
Connect all Predix components into unified trading system:

INTEGRATION (ALL 295 TESTS PASS):
- RL Trading connected with Protection Manager
- RL Trading connected with Backtesting Engine
- CLI command 'rdagent rl_trading' added (train/backtest/live modes)
- Graceful fallback for users without stable-baselines3

OPEN SOURCE COMPATIBILITY:
- System works WITHOUT stable-baselines3 (momentum fallback)
- System works WITHOUT local models/prompts (uses standard)
- Clear warning messages when optional deps missing
- GitHub users get FULLY WORKING system

CLOSED SOURCE PROTECTION:
- models/local/, prompts/local/, .env stay local only
- .gitignore properly configured
- Our alpha (best models/prompts) remains private

DOCUMENTATION:
- QWEN.md: Open/closed source strategy
- QWEN.md: Development guidelines for AI assistant
- QWEN.md: Open source compatibility principle
- README.md: RL Trading CLI commands and examples
- requirements/rl.txt: Optional RL dependencies

Modified files:
- rdagent/app/cli.py: Added rl_trading command
- rdagent/components/backtesting/backtest_engine.py: RL backtest support
- rdagent/components/coder/rl/costeer.py: Protection Manager integration
- rdagent/components/coder/rl/__init__.py: Conditional imports + fallback
- rdagent/components/coder/rl/fallback.py: NEW - Simple momentum fallback
- requirements.txt: Optional RL deps commented
- requirements/rl.txt: NEW - Full RL dependencies
- test/integration/test_all_features.py: 7 new integration tests
- QWEN.md: Open source strategy + development guidelines
- README.md: RL Trading documentation

295 tests pass: 67 integration + 89 RL + 139 backtesting
2026-04-03 13:53:32 +02:00
TPTBusiness 2c07c15a33 feat: Beautiful CLI dashboard + corrected start command
New features:

1. CLI Dashboard (rdagent/log/ui/predix_dashboard.py)
   - Beautiful terminal UI with Rich library
   - Live progress bar for Loop/Step
   - Live Macro Data (EURUSD, DXY, Volatility)
   - Session info with recommendation
   - Statistics (Win-Rate, PnL, Success/Fail)
   - Recent factors list
   - Auto-refresh every 5 seconds

   Start: rdagent fin_quant --cli-dashboard

2. CLI extension (rdagent/app/cli.py)
   --with-dashboard/-d: Web Dashboard
   --cli-dashboard/-c: CLI Dashboard
   Both combinable: rdagent fin_quant -d -c

3. Start scripts updated:
   - start_trading.sh: Interactive with dashboard selection
   - start_loop.sh: Endless loop with auto-restart

   Corrected start command for endless loop:
   cd ~/Predix && conda activate rdagent && ./start_loop.sh

4. Dashboard URLs:
   - Web: http://localhost:5000/dashboard.html
   - CLI: rdagent fin_quant -c

All modules tested and integrated!
2026-04-02 19:21:08 +02:00
TPTBusiness cf8904e896 feat: Auto-start dashboard for fin_quant
Add automatic dashboard launch options for trading loop:

1. CLI extension (rdagent/app/cli.py)
   --with-dashboard/-d: Automatically starts dashboard
   --dashboard-port: Dashboard port (default: 5000)

   Usage:
   rdagent fin_quant --with-dashboard
   rdagent fin_quant -d --dashboard-port 5001

2. Start script (start_trading.sh)
   - Activates Conda environment
   - Starts dashboard in background
   - Starts fin_quant
   - Cleanup on exit

   Usage:
   ./start_trading.sh

Dashboard is now accessible at http://localhost:5000/dashboard.html
once fin_quant is running.
2026-04-02 19:19:15 +02:00
XianBW 14395488b9 feat: add a web UI server (#1345)
* update rdagent cmd

* fix log error message

* use multiProcessing.Process instead of subprocess.Popen

* add traces to gitignore

* add user interactor in RDLoop (finance scenarios)

* add interactor (feedback, hypothesis) for quant scens

* fix the test_end in qlib conf

* add features init config, general instruction to qlib scenarios

* set base features for based exp

* fix bug when combine factors

* move traces folder to git_ignore_folder

* fix bug in features init

* fix quant interact bug

* fix logger warning error

* bug fixes

* modify rdagent logger, now it can set file output

* adjust cli functions and fix logger bug

* fix server port transport problem

* update server_ui in cli

* add web code

* fix CI problem

* black fix

* update web ui README

* update README

* update readme
2026-03-18 14:04:52 +08:00
Xu Yang 6e09dc6d69 feat: add user interaction in data science scenario (#1251)
* feat: add interactor classes and user interaction handling for experiments

* update code

* use fragment retry mechanism instead of rerun()

* fix a bug

* integrate user instructions into proposal and coder

* fix CI

* fix CI

* feat: add approval option for user instructions submission

* feat: enhance user instructions handling in Task and DSExperiment classes

* fix CI

* add user instructions into hypothesis rewrite

* add interface to command line

---------

Co-authored-by: Bowen Xian <xianbowen@outlook.com>
2025-09-18 11:10:12 +08:00
XianBW bbb008c95e fix cli command type checker (#1114) 2025-07-23 19:43:25 +08:00
Linlang 81d0ac7185 docs: update data science docs (#1015)
* update data science docs part1

* update data science docs part2

* update data science docs part3

* update data science docs part4

* update data science docs part5

* format with isort

* update data science docs part6

* add check environment scripts

* format with isort

* format with isort

* merge env_check to health_check

* format with isort

* format with black

* optimize code

* use boolean cli options

* replace fire with typer

* replace fire with typer

* optimizing parameter and variable naming
2025-07-19 18:35:24 +08:00
XianBW f6a9c68e01 add data science ui & grade_summary to rdagent cli (#1057) 2025-07-11 15:30:24 +08:00
Linlang 32a29a7479 fix: main bug (#938)
* feat: parameterize cache paths with USER to avoid conflicts

* guide for missing training_hyperparameters

* guidance for  KeyError: 'concise_reason'

* fixed three bugs in the test

* fix general_model task bug

* fixed some bugs in the med_model scenario

* delete comments

* format with black

* fix mypy error

* fix ruff error

* fix isort error

* sync code

* revert cache_path code

* revert cache_path code

* delete data mining scenario

* fix factor report loop

* fix LiteLLMAPIBackend log_llm_chat_content setting

* refine fin factor report scenario

* remove unused LogColors

* fix UI

* remove medical scenario docs

* change **kaggle** to **data_science**

* remove default dataset_path in create_debug_data

* remove KAGGLE_SETTINGS in kaggle_crawler

* limit litellm versions

* reformat with black

* change README

* fix_data_science_docs

* make hypothesis observations string

* Hiding old versions of kaggle docs

* hidding kaggle agent docs

---------

Co-authored-by: Young <afe.young@gmail.com>
Co-authored-by: Bowen Xian <xianbowen@outlook.com>
Co-authored-by: yuanteli <1957922024@qq.com>
2025-06-18 14:35:45 +08:00
Linlang c8f1c5364a chore: add a rdagent server with UI & logger storage refinement(#553)
* change_log_object

* lint code

* delete comments

* change_log_object

* change_log_object

* fix import test error

* update code

* update code

* fix bugs

* skip mypy error

* skip mypy error

* skip mypy error

* Start the flask server before running the demo.

* achieve front and back interaction

* fix github-advanced-security comments

* fix github-advanced-security comments

* tmp ignore

* fix CI

* move some logic

* change format

* adjust logic

* log2json changes

* tmp

* fix

* fix bug

* refine log2json between 5 scenarios

* fix

* refine codes

* fix logic

* use localhost

* add loop & all_duration param for old scenario startup

* merge control logic

* add README for server ui api

* update README

* reuse code in logger

* add loop_n and all_duration param

* fix upload

* ui server now use port in setting

* fix port setting

* fix port setting

* fix mypy check

* refine logger and log storage

* fix ruff error

* fix CI

* refine logger, loop, storage

* bind one FileStorage with one logger

* not truncate log storage

* refine LoopBase.load(), use `checkout` instead of `output_path` and `do_truncate`

* clear session folder when loading loop to run

* move component info init step to ExpGen Class

* Update rdagent/utils/workflow.py

* move truncate_session function to LoopBase class

* add checkout param for other scenarios

* fix bug

* move WebStorage to UI

* change web_storage name

* add randomname to requirements

* add typer

* fix requirements

---------

Co-authored-by: WinstonLiyte <1957922024@qq.com>
Co-authored-by: Bowen Xian <xianbowen@outlook.com>
Co-authored-by: you-n-g <you-n-g@users.noreply.github.com>
2025-06-06 18:52:19 +08:00
Yuante Li d1019cb568 feat: add RD-Agent-Quant scenario (#838)
* fix model input shape bug and costeer_model bug

* fix a bug

* fix a bug in docker result extraction

* a system-level optimization

* add a filter of stdout

* update

* add stdout to model

* model training_hyperparameters update

* quant scenario

* update some quant settings

* llm choose action

* Thompson Sampling Bandit for action choosing

* refine both scens

* add trace messages for quant scen

* fix some bugs

* fix some bugs

* update

* update

* update

* fix

* fix

* fix

* update for merge

* fix ci

* fix some bugs

* fix ci

* fix ci

* fix ci

* fix ci

* refactor

* default qlib4rdagent local env downloading

* fix ci

* fix ci

* fix a bug

* fix ci

* fix: align all prompts on template (#908)

* use template to render all prompts

* fix CI

---------

Co-authored-by: Xu Yang <xuyang1@microsoft.com>

* add fin_quant in cli

* fix a bug

* fix ci

* fix some bugs

* refactor

* remove the columns in hypothesis if no value generated in this column

* fix a bug

* fix ci

* fix conda env

* add qlib gitignore

* remove existed qlib folder & install torch in qlib conda

* fix workspace ui in feedback

* align model config in coder and runner in docker or conda

* fix CI

* fix CI

---------

Co-authored-by: Xu Yang <peteryang@vip.qq.com>
Co-authored-by: Xu Yang <xuyang1@microsoft.com>
2025-05-29 16:16:51 +08:00
Linlang 6d56061341 chore: modify kaggle docs & Adding ds_loop at program entry (#786)
* modify kaggle docs

* optimise code based on comments

* Update docs/scens/kaggle_agent.rst

* fix docs build error

---------

Co-authored-by: you-n-g <you-n-g@users.noreply.github.com>
2025-04-17 22:02:49 +08:00
you-n-g cade50de89 fix: handle division by zero in percentage calculations (#550)
* fix: Handle division by zero in percentage calculations

* lint
2025-02-05 10:21:53 +08:00
Linlang d4e7f9277e chore: fix PR template (#487)
* fix PR template

* subfolders of the log displayed on the web page

* fix code error

* add health check

* reformat with isort

* reformat with black

* update README

* fix bug && experience confusing

* reformat with black & update health check code

* reformat with isort

* reformat with black

* update README.md

* Removed duplicates in documentation and health_check && Upgraded code for filtering folders

* update docs

* reformat with black
2024-11-28 15:35:13 +08:00
Linlang 7672eaeaaa chore: remove package (#449)
* remove package

* reformat with black

* fix pytest error

* fix pytest error

* fix pytest error

* add packages

* change code
2024-10-24 20:38:13 +08:00
you-n-g fe2da1a68f feat: add kaggle command (#271)
* feat: add kaggle command

* lint
2024-09-18 16:48:54 +08:00
Linlang c8d0d59308 fix: fix_dotenv_error (#257)
* fix_dotenv_error

* format with isort

* Update rdagent/app/cli.py

---------

Co-authored-by: you-n-g <you-n-g@users.noreply.github.com>
2024-09-10 19:38:35 +08:00
Linlang 80d4f32c8f feat: add collect info (#233)
* add collect info

* fix isort error

* optimize code

* fix black error

* Update rdagent/app/cli.py

* Modify the code according to the comments

* fix isort error

* add docker info

* docs: update contributors (#230)

* fix: package dependency. (#234)

* fix package

* fix lint

* docs: Update development.rst (#235)

* feat: add cross validation for kaggle scenario (#236)

* update cross validation for kaggle scenario

* CI Issues

* delete useless file

* CI issues

* docs: Update README.md (#245)

* docs: refine the README (#244)

* init a scenario for kaggle feature engineering

* update the readme

* Delete rdagent/app/kaggle_feature/conf.py

* update some pictures

* Delete rdagent/app/kaggle_feature/model.py

* change a photo

* add pics to docs

* update the readme

* update the README

* for a try

* for another try

* change the style of the pictures in readme

* fix a small bug

* update the readme and the docs

* update the docs

* fix a typo

* change a website url

* change some styles

* fix a typo

* change the size of the logo

* change two urls

* Update README.md

* Update README.md

* Update README.md

* Update README.md

---------

Co-authored-by: Linlang <Lv.Linlang@hotmail.com>

* move the component to other files

* last container

* optimize rdagent info

* format with isort

* format with black

* format_with_black

* fix pip error

* format with isort

* change requirements

* fix pip error

* fix_pip_error

* fix pip error

* format with black

* fix pip error

---------

Co-authored-by: you-n-g <you-n-g@users.noreply.github.com>
Co-authored-by: Haotian Chen <113661982+Hytn@users.noreply.github.com>
Co-authored-by: Haoran Pan <167847254+TPLin22@users.noreply.github.com>
Co-authored-by: Way2Learn <118058822+Xisen-Wang@users.noreply.github.com>
Co-authored-by: WinstonLiyt <104308117+WinstonLiyt@users.noreply.github.com>
Co-authored-by: Young <afe.young@gmail.com>
2024-09-07 12:37:08 +08:00
XianBW 51d28db28b feat: Demo display effect and usage (#162)
Demo changes
2024-08-09 20:40:16 +08:00
XianBW 9da4a76b7e feat: change ui entry (#197)
change ui start cmd
2024-08-09 17:23:45 +08:00
you-n-g 5c061d452f feat: add entry for rdagent. (#187)
* Add entries

* update entry for rdagent

* lint

* fix typo
2024-08-08 17:10:37 +08:00