Export to Python
A self-documenting file that carries your strategy — and its receipts.
The ↓ Python button on the Rules tab downloads a single .py file built for one purpose: letting you reproduce and extend your research away from this site, against the same open-source engine that ran your backtest. No account required to run it, no calls back to us.
What is in the file
- The rules in plain English — the same universe, entry, exit, and sizing sentences from the Rules tab, at the top of the docstring, so the file explains itself to anyone who opens it.
- Run instructions — the exact commands to reproduce the backtest locally, in the docstring.
- The complete spec —
STRATEGY_SPEC, a Python dict holding the strategy JSON verbatim, exactly as the lab ran it. The spec travels with the file; nothing is summarized or lossy. - The standard disclaimer — historical simulation for research and education, not financial advice.
Running the file directly does one small thing: it writes the spec out as JSON next to itself and prints the command to run it. It contains no trading logic of its own — the engine in the repo is the single implementation of the rules.
Running the backtest locally
Clone the engine
git clone https://github.com/kevincolbeck/schwab-backtest— the same engine this site runs, in the open.Install dependencies
pip install -r engine/requirements.txt(a recent Python 3 and the usual scientific stack).Set a data key
The engine fetches daily bars from Polygon.io: setPOLYGON_API_KEYin your environment. Fetched data is cached in a local SQLite file, so the first run does the downloading and later runs are fast.Emit the spec JSON
python golden-cross.pywritesgolden-cross.jsonnext to the file and prints the run command.Run it
python engine/run_backtest_cli.py golden-cross.json— add start and end dates as extra arguments to change the window (the default is 2016 to today). The CLI logs progress, prints the summary stats (return, CAGR, Sharpe, drawdown, win rate, and so on), and saves a JSON results summary underbacktest_runs/.
Reproducibility and versioning
The spec is the strategy. Same spec, same engine, same date window, same data — same results. Because the export embeds the spec verbatim, the file is a complete snapshot: editing the strategy in the lab later does not change the download you already have. If you iterate seriously, keep exports under version control like any other source file; diffing two exported specs shows you exactly what changed between versions of an idea. This is the same property the ledger leans on — deployed strategies are identified by a hash of this JSON.
Who this is for
Coders, mostly. If you want to run longer histories or custom date ranges, sweep parameters by editing the JSON and re-running, step through the engine to understand exactly how a trade was filled, or adapt the data layer to your own sources — everything is ordinary Python in the repo, and nothing about your strategy is locked to this site. If you never touch Python, you lose nothing: the same rules are available as Pine Script and as plain English.