This project is a collection of scripts that generate and submit alphas to the WorldQuant platform.
__ __ .__ .___ __ .__
/ \ / \___________| | __| _/________ _______ _____/ |_ _____ |__| ____ ___________
\ \/\/ / _ \_ __ \ | / __ |/ ____/ | \__ \ / \ __\ / \| |/ \_/ __ \_ __ \
\ ( <_> ) | \/ |__/ /_/ < <_| | | // __ \| | \ | | Y Y \ | | \ ___/| | \/
\__/\ / \____/|__| |____/\____ |\__ |____/(____ /___| /__| |__|_| /__|___| /\___ >__|
\/ \/ |__| \/ \/ \/ \/ \/
Discord: https://discord.gg/K8X5xu2e
Usage Tutorial(WIP) on the web version: https://www.youtube.com/watch?v=xwr9atsulSA
This is a Rust implementation of the alpha generator.
cargo build --release
cargo run --release
This is a Python implementation of the alpha generator.
- Pre-Consultant has maximum 5 concurrent simulations
- Pre-Consultant has fewer operators and data fields options
This is basically a closed loop system where it starts with alpha_generator.py, which generates alpha ideas with Kimi AI. Then it dumps promising alpha to a local log file, which promising_alpha_miner.py will mine for better results, and dumps refined alpha to a local log file, which you can run successful_alpha_submitter.py to submit to the WorldQuant platform. These script can run concurrently.
While alpha_expression_miner.py is more of a utility script to mine alpha expressions from a given expression manually but not within the aforementioned closed loop system.
alpha_101_testing is currently under development.
alpha_polisher.py is currently under development.
pip install -r requirements.txt
The pre-consultant Python alpha generator uses Kimi AI to generate alpha expressions. Notice this may get you some alpha ideas as long as you are fine with the cost.
Human in the loop control is the future development direction of this script.
python alpha_generator.py
This script is used to mine alpha expressions from a given expression.
python alpha_expression_miner.py --expression "expression"
PS ~> python .\alpha_expression_miner.py --expression "cashflow_stability = ts_mean(cashflow_op, 252) / (debt_lt + 0.01);
>> stability_z = zscore(cashflow_stability);
>> debt_ratio = debt_lt / (assets + 0.01);
>> combined_score = stability_z - zscore(debt_ratio);
>> -rank(combined_score)"
2025-05-04 01:37:50,111 - INFO - Starting alpha expression mining with parameters:
2025-05-04 01:37:50,111 - INFO - Expression: cashflow_stability = ts_mean(cashflow_op, 252) / (debt_lt + 0.01);
stability_z = zscore(cashflow_stability);
debt_ratio = debt_lt / (assets + 0.01);
combined_score = stability_z - zscore(debt_ratio);
-rank(combined_score)
2025-05-04 01:37:50,111 - INFO - Output file: mined_expressions.json
2025-05-04 01:37:50,112 - INFO - Initializing AlphaExpressionMiner
2025-05-04 01:37:50,112 - INFO - Loading credentials from ./credential.txt
2025-05-04 01:37:50,112 - INFO - Authenticating with WorldQuant Brain...
2025-05-04 01:37:51,303 - INFO - Authentication response status: 201
2025-05-04 01:37:51,303 - INFO - Authentication successful
2025-05-04 01:37:51,303 - INFO - Parsing expression: cashflow_stability = ts_mean(cashflow_op, 252) / (debt_lt + 0.01);
stability_z = zscore(cashflow_stability);
debt_ratio = debt_lt / (assets + 0.01);
combined_score = stability_z - zscore(debt_ratio);
-rank(combined_score)
2025-05-04 01:37:51,303 - INFO - Found 3 parameters to vary
Found the following parameters in the expression:
1. Value: 252.0 | Context: ...s_mean(cashflow_op, 252) / (debt_lt + 0.01)...
2. Value: 0.01 | Context: ..., 252) / (debt_lt + 0.01);
stability_z = zsc...
3. Value: 0.01 | Context: ...debt_lt / (assets + 0.01);
combined_score = ...
Enter the numbers of parameters to vary (comma-separated, or 'all'): all
Parameter: 252.0 | Context: ...s_mean(cashflow_op, 252) / (debt_lt + 0.01)...
Enter range (e.g., '10' for ±10, or '5,15' for 5 to 15): 25
Enter step size: 1
Parameter: 0.01 | Context: ..., 252) / (debt_lt + 0.01);
stability_z = zsc...
Enter range (e.g., '10' for ±10, or '5,15' for 5 to 15): -0.05,0.05
Enter step size: 0.01
Parameter: 0.01 | Context: ...debt_lt / (assets + 0.01);
combined_score = ...
Enter range (e.g., '10' for ±10, or '5,15' for 5 to 15): -0.05,0.05
Enter step size: 0.01
2025-05-04 01:38:18,371 - INFO - Generating variations based on selected parameters
2025-05-04 01:38:18,375 - INFO - Generated 5100 total variations
2025-05-04 01:38:18,376 - INFO - Testing variation 1/5100: cashflow_stability = ts_mean(cashflow_op, 227) / (debt_lt + -0.05);
stability_z = zscore(cashflow_stability);
debt_ratio = debt_lt / (assets + -0.05);
combined_score = stability_z - zscore(debt_ratio);
-rank(combined_score)
2025-05-04 01:38:18,376 - INFO - Testing alpha: cashflow_stability = ts_mean(cashflow_op, 227) / (debt_lt + -0.05);
stability_z = zscore(cashflow_stability);
debt_ratio = debt_lt / (assets + -0.05);
combined_score = stability_z - zscore(debt_ratio);
-rank(combined_score)
2025-05-04 01:38:18,754 - INFO - Simulation creation response: 201
This script is used to clean up the logs.
python clean_up_logs.py
This script is used to submit successful alphas to the WorldQuant platform. It's not recommended to use this script as of now because it submits alphas in one batch instead of once per day.
python successful_alpha_submitter.py
The machine_lib.py
module provides core functionality for alpha generation and testing through the WorldQuant platform. Here are the key components:
The main class that handles interactions with WorldQuant's API and alpha generation logic:
- Authentication and session management with WorldQuant platform
- Fetching and processing data fields (matrix and vector types)
- Generating alpha expressions using operators and data fields
- Running simulations to test alpha performance
- Processing and analyzing simulation results
- Automated alpha generation using combinations of:
- Data fields (matrix and vector types)
- Mathematical operators (+, -, *, /, etc.)
- Ranking and scoring functions
- Time series operations
- Simulation capabilities:
- Single alpha testing
- Batch simulation support
- Performance metrics calculation
- Result processing:
- Filtering based on performance thresholds
- Storing successful alphas
- Error handling and logging
- Data field categorization (matrix vs vector)
- Expression validation
- Performance metric calculations:
- Information Ratio (IR)
- Returns
- Turnover
- Correlation analysis
The library serves as the foundation for automated alpha mining and testing, providing the necessary tools to interact with WorldQuant's platform programmatically.
python machine_miner.py --username your_worldquant_username --password your_worldquant_password
Just like the pre-consultant non ai but without workaround like single simulation and skip for inaccessible data fields and operators.
pip install -r requirements.txt
python machine_miner.py --username your_worldquant_username --password your_worldquant_password
- Integrate more templates
- Integrate more datafields
- Integrate more operators
- Integrate more regions
- Integrate more universes
- Integrate more alphas
- An interim solution to manage WorldQuant Alpha Generator with python GUI
- An interim solution to manage agent networks with python GUI
- Key Points
- A free(as of now because it is not done jajaja) user-friendly interface to create agent networks to work with the WorldQuant Alpha Generator
- Open source and frontend only database interactions so you can see that the website does not save your WorldQuant credentials but only your email will be used to identify you
- You would need to first verify with WorldQuant via API then verify with the site
- No WorldQuant credentials are saved on the server side but your email will be used to identify you
- Login required for managing agent networks
- Free tier available
- Leverage vector databases to store agent memories
- Features
- Chat with agents
- Create agent networks
- Manage agent networks
- Delete agent networks
- View agent networks
- View agent memories
- Alpha Polisher - Polish existing alphas or generate new ideas using AI
- Key Points
- Implementation of Agent-to-Agent (A2A) protocol for automated financial research
- Prescriptive agent architecture mimicking real-world financial analyst workflows
- Integration with existing WorldQuant Alpha Generator components
- Automated alpha mining pipeline with specialized agents
graph TD
subgraph Data Collection
WC[Web Crawler] -->|Financial News| DP[Data Processor]
FPE[PDF Extractor] -->|Research Papers| DP
DP -->|Structured Data| DB[(Knowledge Base)]
end
subgraph Alpha Research
AIG[Alpha Idea Generator] -->|New Ideas| AIS[Alpha Idea Simulator]
AIS -->|Validated Ideas| ACS[Alpha Config Setter]
ACS -->|Optimized Configs| MAB[Multi-Arm Bandit]
end
subgraph Execution
MAB -->|Best Actions| EX[Executor]
EX -->|Results| DB
end
subgraph Feedback Loop
DB -->|Historical Data| AIG
DB -->|Performance Metrics| MAB
end
style WC fill:#3b82f6,stroke:#1d4ed8,color:#fff
style FPE fill:#3b82f6,stroke:#1d4ed8,color:#fff
style DP fill:#3b82f6,stroke:#1d4ed8,color:#fff
style AIG fill:#10b981,stroke:#047857,color:#fff
style AIS fill:#10b981,stroke:#047857,color:#fff
style ACS fill:#10b981,stroke:#047857,color:#fff
style MAB fill:#f59e0b,stroke:#b45309,color:#fff
style EX fill:#f59e0b,stroke:#b45309,color:#fff
style DB fill:#6366f1,stroke:#4f46e5,color:#fff
-
Data Collection Agents
- Web Crawler Agent: Automated financial news and market data collection
- PDF Extractor Agent: Research paper processing and information extraction
- Data Processor Agent: Data transformation and knowledge base management
-
Alpha Research Agents
- Alpha Idea Generator Agent: Pattern recognition and idea generation
- Alpha Idea Simulator Agent: Validation and testing of alpha ideas
- Alpha Config Setter Agent: Parameter optimization and configuration
-
Execution Agents
- Multi-Arm Bandit Agent: Reinforcement learning for action selection
- Executor Agent: Implementation and monitoring of selected actions
sequenceDiagram
participant WC as Web Crawler
participant FPE as PDF Extractor
participant DP as Data Processor
participant AIG as Alpha Idea Generator
participant AIS as Alpha Idea Simulator
participant ACS as Alpha Config Setter
participant MAB as Multi-Arm Bandit
participant EX as Executor
participant DB as Knowledge Base
WC->>DP: Financial News
FPE->>DP: Research Papers
DP->>DB: Structured Data
DB->>AIG: Historical Data
AIG->>AIS: New Alpha Ideas
AIS->>ACS: Validated Ideas
ACS->>MAB: Optimized Configs
MAB->>EX: Best Actions
EX->>DB: Results
DB->>MAB: Performance Metrics
- Automated research workflow orchestration
- Structured data exchange between agents
- Performance feedback loops
- Knowledge base integration
- Real-time progress tracking
- Priority-based task scheduling
- Vector database integration for agent memories
- API integration with WorldQuant platform
- Web interface for monitoring and control
- Automated alpha submission pipeline
- Advanced natural language processing for research paper analysis
- Machine learning models for pattern recognition
- Automated hypothesis generation and testing
- Real-time market data integration
- Performance optimization and scaling
- Enhanced error handling and recovery mechanisms
We welcome contributions from the community! Here's how you can help:
- Fork the repository
- Create a new branch (
git checkout -b feature/improvement
) - Make your changes
- Run tests to ensure nothing is broken
- Commit your changes (
git commit -am 'Add new feature'
) - Push to the branch (
git push origin feature/improvement
) - Create a Pull Request
- Use the GitHub issue tracker to report bugs
- Clearly describe the issue including steps to reproduce
- Make feature requests through GitHub issues
- Tag issues appropriately
- Help improve documentation
- Add code comments where needed
- Update the README with new features
- Write tutorials and examples
- Follow existing code style and conventions
- Write clear commit messages
- Add tests for new features
- Update documentation for changes
- Be respectful to other contributors
- Join our community chat
- Ask questions in GitHub issues
- Read existing documentation
- Check closed issues for solutions
We appreciate all contributions that help make this project better!
This project integrates components from Dify (agent-dify-api and agent-dify-web) for enhanced alpha mining capabilities. These components are used under the Apache License 2.0.
The Dify components (agent-dify-api and agent-dify-web) are licensed under the Apache License 2.0. This means:
- You may use, reproduce, and distribute the Dify components
- You may modify and create derivative works
- You must include the original copyright notice
- You must state significant changes made to the original software
- You must include a copy of the Apache License 2.0
For the complete terms and conditions, please refer to the Apache License 2.0.
The Dify components are integrated into this project to enhance alpha mining capabilities:
- agent-dify-api: Provides API endpoints for alpha generation and mining
- agent-dify-web: Offers a web interface for alpha mining operations
The Dify components are used to:
- Generate and validate alpha expressions
- Process and analyze market data
- Provide a user-friendly interface for alpha mining
- Enable automated alpha generation and submission
This project uses components from Dify, which are licensed under the Apache License 2.0. The original copyright notices and license information are preserved in the respective component directories.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
- Docker and Docker Compose installed
- Python 3.8 or higher
- Node.js 16 or higher (for web interface)
- Start the Dify Services
# Start the Dify API and Web services
docker-compose -f docker-compose.middleware.yaml up -d
- Verify Services
# Check if services are running
docker ps
-
Access the Web Interface
- Open your browser and navigate to
http://localhost:3000
- Log in with your credentials
- Open your browser and navigate to
-
Creating Alpha Mining Tasks
- Click on "New Task" in the web interface
- Select "Alpha Mining" as the task type
- Configure your mining parameters:
- Data fields to use
- Time period
- Universe selection
- Mining strategy
-
Monitoring Mining Progress
- View real-time mining progress in the dashboard
- Check generated alphas in the "Results" section
- Export successful alphas for submission
- API Authentication
import requests
API_URL = "http://localhost:8000"
headers = {
"Authorization": "Bearer your_api_key"
}
- Creating Mining Tasks
# Create a new mining task
response = requests.post(
f"{API_URL}/api/v1/mining/tasks",
headers=headers,
json={
"name": "My Mining Task",
"data_fields": ["close", "volume", "high", "low"],
"time_period": "1Y",
"universe": "US",
"strategy": "correlation"
}
)
- Checking Task Status
# Get task status
task_id = response.json()["task_id"]
status = requests.get(
f"{API_URL}/api/v1/mining/tasks/{task_id}",
headers=headers
)
- Retrieving Results
# Get mining results
results = requests.get(
f"{API_URL}/api/v1/mining/tasks/{task_id}/results",
headers=headers
)
-
Resource Management
- Monitor system resources during mining
- Adjust mining parameters based on available resources
- Use appropriate timeouts for long-running tasks
-
Error Handling
- Implement proper error handling in your API calls
- Check task status regularly
- Save intermediate results
-
Performance Optimization
- Use appropriate batch sizes
- Implement caching where possible
- Monitor and adjust mining parameters
-
Service Issues
- Check Docker container logs:
docker logs <container_id>
- Verify service health:
docker-compose ps
- Restart services if needed:
docker-compose restart
- Check Docker container logs:
-
API Issues
- Verify API endpoint availability
- Check authentication tokens
- Monitor API rate limits
-
Mining Issues
- Verify data field availability
- Check universe configuration
- Monitor memory usage
For more detailed information about specific features and configurations, refer to the Dify Documentation.