logo
0
0
WeChat Login

WorldQuant Brain Toolbox

An integrated desktop toolbox that includes:

  • Datasets: Browse and search dataset fields (including Gemini AI semantic search) and import selected fields
  • Backtests: View backtest results and import data
  • Strategy Generator: Generate strategy code using fields and templates, then export or send to Simulation
  • Simulation: Batch simulations interacting with the WorldQuant Brain API, with progress tracking and result export

This app is built with PySide6 for the GUI and supports macOS.


Project Structure Overview

brain_viewer/ app.py # Integrated entry (four tabs) dataset_viewer.py # Dataset browsing and search (with Gemini) backtest_viewer.py # Backtest data viewer (pairs with data/) generator.py # Strategy templates/parameters and export simulation.py # Simulation widget (integrated into Simulation tab in app.py) datasets/ # Datasets containing *_fields_formatted.csv data/ # Backtest or simulation outputs (CSV/LOG) alphas/ # Strategy files generated by the strategy generator templates/ # Strategy templates (.json)

Prerequisites

  • Python 3.10+ (3.11 or later recommended)
  • OS: macOS (Windows/Linux also possible; install corresponding dependencies yourself)

Required packages (install with pip):

pip install PySide6 pandas matplotlib python-dotenv google-generativeai requests

Quick Start

  1. Create a virtual environment and install dependencies
python3 -m venv .venv source .venv/bin/activate pip install -U pip pip install PySide6 pandas matplotlib python-dotenv google-generativeai requests
  1. Configure Gemini API (optional but recommended; used for AI Search)
  • Create a .env file at the project root:
cat > .env << 'EOF' GEMINI_API_KEY=your_api_key EOF
  • dataset_viewer.py automatically reads .env and initializes Gemini:
    • If successful, you can switch the search mode at the top-right to "AI Search"
    • If the key is missing/invalid, it will show "AI Search (API key required)" and disable the feature
  1. Launch the integrated application
python app.py

Modules and Operations

  • Datasets

    • The left panel lists *_fields_formatted.csv files under the datasets/ directory
    • The right panel shows a table to browse fields, filter, sort, and visualize distributions
    • After selecting fields, click "Import Selected Fields to Generator" to send them to the Strategy Generator
    • Search modes: Normal (keyword) / AI (Gemini semantic search)
  • Backtests

    • Reads backtest data under data/ (per your existing data format/process)
    • Can import results to Simulation or Generator (follow the UI prompts)
  • Strategy Generator

    • After importing fields from Datasets, combine with templates to build a list of strategies
    • Use "Preview" to review output; or generate files into alphas/
    • "Import to Simulation" sends the selected strategies to the Simulation tab
  • Simulation

    • Run batch simulations for strategies imported from the Generator, with progress display and row-by-row highlight
    • Outputs CSV and LOG files under the data/ directory (filenames include timestamps)
    • Requires WorldQuant Brain login credentials (see the next section)

Gemini API Setup (AI Search)

  1. Obtain an API Key:

    • Request a Gemini API Key in Google AI Studio
  2. Save the key into .env:

echo "GEMINI_API_KEY=your_api_key" >> .env
  1. Ensure packages are installed:
pip install google-generativeai python-dotenv
  1. After launching the app, switch to "AI Search" in the top-right of the Datasets tab. Enter a natural-language description of what you are looking for (e.g., "indicators related to earnings momentum"). The system will perform semantic matching to suggest relevant fields.

Common issues:

  • If the status bar indicates an invalid API key or the feature is disabled, ensure .env exists, the content is correct, and the terminal process has permission to read it.

Add a New Dataset

Location: datasets/

Filename rule: Must match *_fields_formatted.csv, for example: custom_demo_fields_formatted.csv

Required columns (case-sensitive):

  • Field (string, field name)
  • Description (text description)
  • Type (recommended categories such as Vector/Matrix/Scalar)
  • Coverage (coverage; recommended as a percentage string like 95%. If numeric, the app will append % automatically)
  • Users (integer)
  • Alphas (integer)

Minimal viable example (CSV content):

Field,Description,Type,Coverage,Users,Alphas demo_close,Daily close price,Vector,95%,120,300 demo_volume,Daily volume,Vector,92%,110,280 demo_return_5d,5-day return,Vector,88%,90,250 demo_beta,Market beta estimate,Scalar,80%,60,180 demo_inst_density,Institutional density,Matrix,75%,40,120

Save the above as datasets/custom_demo_fields_formatted.csv, then return to the app and click it in the left list to load. The app will automatically create a corresponding .db (SQLite) in the same directory to accelerate browsing and sorting.


WorldQuant Brain Credentials (for Simulation)

The Simulation tab interacts with the WorldQuant Brain API. Create a credentials.json in the project root:

{ "email": "your_email@example.com", "password": "your_password" }

Notes:

  • On first use or when required by risk controls, the API may return a URL for biometric verification (persona). Open the link per the UI prompt to complete verification.
  • If credentials are expired/invalid, the UI will notify you and stop subsequent simulations.

How to Run

  • Integrated app (recommended):
python app.py
  • Run individually (for debugging or split work only):
    • Datasets: python dataset_viewer.py
    • Strategy Generator: python generator.py
    • Backtests: python backtest_viewer.py (requires readable data under data/)

simulation.py is integrated as a widget within app.py; running it standalone is not recommended.


FAQ

  • macOS display issues?
    • This project enforces a light color palette. If the appearance looks abnormal, please update PySide6 and matplotlib.

Versions and Outputs

  • Generated strategy files: alphas/alpha_custom_YYYYmmdd_HHMMSS.py
  • Simulation outputs: data/YYYYmmdd_HHMMSS.csv and the corresponding .log

About

fork自 https://github.com/justinhuang0208/brain_viewer

Language
Python100%