WorldQuant BRAIN client — login (biometric Scan + auto re-login), simulation, batch run, and auto-keeping promising alphas
Project description
brain-login-and-sim
A Python client for WorldQuant BRAIN — handles login (including the biometric "Scan" step and automatic re-login), runs simulations, runs them in batches (up to 3 concurrently, matching the platform limit), and automatically keeps the alphas that pass your criteria.
Install
pip install brain-login-and-sim
Configure credentials
Create a .env file (see .env.example):
WQ_EMAIL=your-email@example.com
WQ_PASSWORD=your-password
# Send the Scan link to Telegram (optional, but recommended)
TELEGRAM_BOT_TOKEN=123456789:AAH...
TELEGRAM_CHAT_ID=123456789
Usage
from brain_login_and_sim import BrainClient, Simulator
# Log in — if a biometric Scan is required, the link is sent to Telegram
# and the client polls until you finish scanning on your phone.
client = BrainClient(notify_telegram=True).authenticate()
print(client.whoami()["id"])
sim = Simulator(client)
# Run a single simulation
r = sim.simulate("ts_rank(close, 5)")
print(r["simulation"]["status"], r["alpha"]["is"]["sharpe"])
# Run many alphas from a JSONL file and auto-keep the promising ones
sim.simulate_batch("alphas.jsonl", save_promising=True)
Features
- Login + biometric Scan — sends the scan link to Telegram/email and polls until it's done, so you don't have to watch the terminal.
- Auto re-login — when the session expires (WorldQuant allows ~4 hours), a
401triggers an automatic re-login and the request is retried once. - Promising-alpha filter — keeps alphas with
|Sharpe| >= 1and|Fitness| >= 0.9(absolute value, so it also catches "flip candidates" that become good when the expression is negated). - Batch — runs up to 3 simulations concurrently (the WorldQuant limit); a failure on one alpha does not abort the whole batch.
- Resume — checkpoints by
hash; re-running the same file skips already-processed alphas and continues where it left off (survives interruptions). - Flexible input — a list of expressions, a
.txtfile (one expression per line), or a.jsonlfile with anexpressionfield (and optionalhash).
JSONL input format
{"hash": "f7b3...", "expression": "rank(reverse(ts_delta(anl4_cfo_median, 10)))", "status": "generated"}
The client extracts expression to run, and if the alpha passes the criteria it stores
the originating source_hash in promising_alphas.jsonl so you can trace it back.
API at a glance
BrainClient: authenticate(on_biometric=None), whoami(), get(path), post(path),
auto_relogin
Simulator(client): simulate(...), simulate_batch(...), is_promising(...),
save_if_promising(...), load_promising(path), get_operators(),
get_data_fields(...), get_alpha(id)
Test
python tests/test_full_loop.py # mock API — no network or credentials needed
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file brain_login_and_sim-0.1.2.tar.gz.
File metadata
- Download URL: brain_login_and_sim-0.1.2.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac635b3e449eaac788ef50a392f0b5a54e104c77d190cdd035e49c1bc91fcfae
|
|
| MD5 |
0906f30f874f3b52f28f8bbf5ed9c6b3
|
|
| BLAKE2b-256 |
da0cbbeb194e71857c3308cc008467740e6a7607dd5bda80db0e36ca42e5c599
|
File details
Details for the file brain_login_and_sim-0.1.2-py3-none-any.whl.
File metadata
- Download URL: brain_login_and_sim-0.1.2-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70c88007c1e48b1c246341951b0392b67ced24c3c4920b2ff864bdece272bfef
|
|
| MD5 |
17f95f2f929b7cd97431588cafa1bf47
|
|
| BLAKE2b-256 |
1b22e92f7590d1225dfd894db2f8ad90d34b50373722c65ddd6a22e722cabe86
|