Files
NexQuant/prompts
TPTBusiness fceee44967 feat: Improved LLM prompt + Optuna integration (Step 3+5)
Step 3 - LLM Prompt verbessert:
- Created prompts/strategy_generation_v2.yaml
- IC-guided factor selection instructions
- |IC| > 0.10: PRIORITIZE, |IC| > 0.05: USE, |IC| < 0.05: AVOID
- IC-weighted factor combinations
- Better examples with IC weights
- Added 'close' Series to available scope

Step 5 - Optuna-Optimierung aktiviert:
- Added use_optuna=True, optuna_trials=20 to __init__
- Integrated OptunaOptimizer in _generate_and_evaluate_single
- Added _prepare_factor_values method for Optuna
- Auto-optimizes accepted strategies with 20 trials
- Updates results if Optuna improves Sharpe

Test results (MomentumDivergenceZScore with forward-fill):
- Status: accepted
- Sharpe: 6.04
- Max DD: -1.57%
- Win Rate: 49.19%
- Ann Return: 21.88%
- Periods: 823,450 (2.27 years)

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-04-09 14:06:15 +02:00
..

Predix Prompts

This directory contains all LLM prompts for the Predix trading agent.


📁 Directory Structure

prompts/
├── standard_prompts.yaml    # Default prompts (committed to Git)
├── local/                   # YOUR IMPROVED PROMPTS (not in Git!)
│   ├── factor_discovery_v2.yaml
│   ├── optimized_prompts.yaml
│   └── best_performing.yaml
└── README.md                # This file

🎯 How It Works

Prompt Loading Priority:

  1. prompts/local/*.yaml ← Your improved prompts (loaded first!)
  2. prompts/standard_prompts.yaml ← Default prompts (fallback)

Example:

from rdagent.components.loader import load_prompt

# Load factor discovery prompt
# If prompts/local/factor_discovery.yaml exists → loads that
# Otherwise → loads from standard_prompts.yaml
prompt = load_prompt("factor_discovery")

# Load specific section
system_prompt = load_prompt("factor_discovery", section="system")
user_prompt = load_prompt("factor_discovery", section="user")

# Force local only (raise error if not found)
prompt = load_prompt("factor_discovery", local_only=True)

📝 Available Standard Prompts

Prompt Name Description Used By
factor_discovery Generate new trading factor hypotheses Hypothesis Agent
factor_evolution Improve existing factors Evolution Agent
model_coder Generate ML model code Model Coder Agent
trading_strategy Design complete trading strategies Strategy Agent

🚀 Creating Your Improved Prompts

Step 1: Create Local Prompt File

# Create local directory (if not exists)
mkdir -p prompts/local

# Copy standard prompt as template
cp prompts/standard_prompts.yaml prompts/local/factor_discovery_v2.yaml

Step 2: Edit Your Prompt

# prompts/local/factor_discovery_v2.yaml

factor_discovery:
  system: |-
    YOUR IMPROVED SYSTEM PROMPT HERE
    
    Add your proprietary insights:
    - Specific EURUSD patterns you've discovered
    - Your unique factor formulas
    - Custom session filters
    - Proprietary risk management rules
    
  user: |-
    YOUR IMPROVED USER PROMPT HERE

Step 3: Test Your Prompt

# Test prompt loading
python rdagent/components/loader.py

# Should show:
# ✓ Loading prompt 'factor_discovery' from local: prompts/local/factor_discovery_v2.yaml

Step 4: Use in Trading

Your improved prompts are automatically used when running:

rdagent fin_quant

The loader checks prompts/local/ first, so your improved prompts take precedence!


🔐 Security

What to keep in prompts/local/:

Your proprietary factor discovery logic Optimized prompt templates Best-performing configurations Custom evolution strategies Trade secrets & alpha-generating logic

What NOT to commit to Git:

Anything in prompts/local/ (already in .gitignore) Files with .local.yaml suffix Files with _private.yaml suffix


📊 Best Practices

1. Version Your Prompts

# Good naming:
prompts/local/factor_discovery_v2.yaml
prompts/local/factor_discovery_v3_optimized.yaml
prompts/local/model_coder_xgboost_v1.yaml

2. Document Changes

# Add metadata to your prompts
# prompts/local/factor_discovery_v2.yaml

# Version: 2.0
# Author: Your Name
# Date: 2026-04-02
# Changes:
#   - Added session-specific filters
#   - Improved spread cost modeling
#   - Target ARR: 12% (up from 9.62%)

factor_discovery:
  system: |-
    ...

3. Test Performance

# Compare prompt versions
from rdagent.components.loader import load_prompt

# Load different versions
prompt_v1 = load_yaml_file("prompts/standard_prompts.yaml")
prompt_v2 = load_yaml_file("prompts/local/factor_discovery_v2.yaml")

# Run backtests and compare
# ...

4. Backup Your Prompts

# Backup to private repo
cd ~/Predix
git archive --format=tar prompts/local/ | gzip > ~/backups/prompts_local_$(date +%Y%m%d).tar.gz

# Or sync to private GitHub repo
git clone git@github.com:TPTBusiness/predix-prompts-private.git
cp -r prompts/local/* predix-prompts-private/
cd predix-prompts-private && git push

🔧 Advanced Usage

Load All Prompts

from rdagent.components.loader import load_all_prompts

all_prompts = load_all_prompts()
print(all_prompts['standard'])  # Standard prompts
print(all_prompts['local'])     # Your improved prompts

List Available Prompts

from rdagent.components.loader import list_available_prompts

available = list_available_prompts()
print(f"Standard: {available['standard']}")
print(f"Local: {available['local']}")

Custom Prompt Path

from rdagent.components.loader import load_yaml_file

# Load from custom location
custom_prompt = load_yaml_file("/path/to/my/prompts.yaml")

📈 Performance Tips

1. Be Specific

Bad:

system: "Generate a good trading factor."

Good:

system: |
  Generate a EURUSD mean-reversion factor for the London session.
  Target: 8-12% ARR, <15% max drawdown.
  Use 5-minute lookback with RSI filter.

2. Include Domain Knowledge

system: |
  EURUSD domain knowledge:
  - London session (08:00-16:00 UTC): highest volume
  - Spread cost: 1.5 bps
  - Mean-reverting on <1h windows
  - Trending on >4h windows

3. Specify Output Format

system: |
  Your response must be in JSON format:
  {
    "hypothesis": "...",
    "reason": "...",
    "target_session": "london/ny/asian/all",
    "expected_arr_range": "8-12%"
  }

4. Provide Examples

user: |
  Example of a good factor:
  
  Name: Momentum_8Bar_London
  Logic: Long if 8-bar return > 0 and is_london=True
  Filter: ADX > 1.2 (trending regime)
  Expected ARR: 9.5%
  
  Now generate a NEW factor with different logic.

🎯 Next Steps

  1. Review standard prompts: cat prompts/standard_prompts.yaml
  2. Create your improved version: mkdir -p prompts/local
  3. Test: python rdagent/components/loader.py
  4. Run trading: rdagent fin_quant

Your improved prompts in prompts/local/ are your competitive edge! 🚀