Agentic Trading Lab
Talk to agents, and test trading ideas. Try AI trading agents on real market data with no code required.
AI translation
The 10-line CTA: a trend-following strategy in ten lines of code, and four refinements measured in Sharpe ratio, kurtosis and trading costs
FinancePython · MakefileGitHub @tschmOnlineOwner unconfirmed
Have you tried it? One tap is enough. No sign-in needed.
The maker's introduction consists of the line above. Read the repository README for more details. Repository README ↗
Loading the full README.
Read the full README ↗Challenged by a young CEO, I wrote a terse CTA (Commodity Trading Advisor) investment strategy in just 10 lines of code. This project discusses the somewhat quirky background of this code fragment and explores how Convex Programming opens the door to deeper insights into the strategy.
🪟 Windows users: The
maketargets are written for a POSIX shell and rely on tools likemkdir -p,printf,curl, and[ … ]. They will not run undercmd.exeor PowerShell — you'll see errors such asprocess_begin: CreateProcess(NULL, # Ensure the … folder exists, …) failed.Run the commands below from WSL (recommended) or , both of which provide a POSIX shell.
# Clone the repository
git clone https://github.com/tschm/cs.git
cd cs
# Install dependencies
make install
# Build the Jupyter Book
make book
Developer notes live under docs/development/:
optimize.py reuses the notebook signals (the
notebooks-are-the-source-of-truth contract).src/ tree) and the repo-local gate that enforces it.make targets.Each ExperimentN.py notebook is a self-contained CTA strategy. To search its
parameter space for the configuration that maximizes the portfolio Sharpe ratio,
run the Optuna driver in book/marimo/notebooks/optimize.py:
# Optimize a single experiment (1–5) with an explicit trial budget
python book/marimo/notebooks/optimize.py --experiment 3 --trials 200
# Optimize all five, each with its per-experiment default budget
python book/marimo/notebooks/optimize.py --experiment all
# Reproducible run with Optuna's per-trial logging (short flags)
python book/marimo/notebooks/optimize.py -e 1 -n 50 --seed 7 --verbose
Each run prints the baseline Sharpe (notebook defaults), the best Sharpe found, the winning parameters, and the improvement. The driver never re-implements a strategy — it imports each notebook's live signal function, so the notebooks stay the single source of truth. See OPTIMIZATION.md for the full contract.
The headline Sharpe of every experiment is pinned in
tests/expected_sharpe.py and checked to a tight
1e-6 tolerance by both the notebook and optimizer regression tests. A
dependency bump that legitimately shifts the numbers will fail those tests; the
assertion message prints the expected pin next to the freshly computed value:
# See old vs. new values for every experiment
uv run pytest tests/test_notebook_sharpe.py tests/test_optimize.py -v
Eyeball the deltas, and only if they are acceptable copy the new values into
EXPECTED_SHARPE_RATIOS, then re-run the suite so both test modules agree. The
full review checklist (and when not to re-pin) is in
SHARPE_PINS.md.
# Start Marimo
make marimo
We do not guarantee or take responsibility for the accuracy, completeness, reliability and usefulness of any information.
Dr. Thomas Schmelzer created all material in his personal capacity. The views stated are his own and do not necessarily represent the views of neither ADIA nor Stanford University. The opinion expressed is based on the prevailing market trends and is subject to change.
This project relies on the Rhiza system for its underlying infrastructure and tooling.
This project is licensed under the MIT License - see the LICENSE file for details.