Skip to content
← All articles
Article

Inside BatchBacktesting: parallel runs, explicit assumptions and useful outputs

Listen to the audio story

Inside a batch backtesting engine · 2:09 · AI-written script, synthetic voices

Transcript

Ava: Say you have a trading idea and fifty stocks to try it on. Running them one at a time would be slow, so how do you test them all and still compare the results fairly?

Andrew: I'm guessing that's what BatchBacktesting does?

Ava: It is. Antoine read through the Python engine from the AlgoETS group and wrote up how it works. His framing is nice: a batch backtest is a small data pipeline. You choose instruments, get prices, clean them, run a strategy, and save results you can compare.

Andrew: So where does it start?

Ava: With a single instrument. A function called process_instrument picks a price source for a stock or a crypto, cleans the data, and builds a backtest. Then it stamps the instrument name and strategy name on the result so you always know which row is which.

Andrew: And the batch part is just doing that over and over?

Ava: Doing it in parallel. A thread pool runs several instruments at once, and the single-strategy runner defaults to four workers. Think of four cashiers serving a long line instead of one.

Andrew: What does a run assume about money?

Ava: It starts with a hundred thousand in cash, charges a commission of point two percent, and uses exclusive orders. Those settings sit in the constructor, so they're right there next to any return you compare.

Andrew: Any strategy details?

Ava: The EMA strategy computes three moving averages, over twenty, eighty and one hundred fifty periods. Entries compare the twenty and the eighty. When it buys, it closes the previous position and sets a stop at ninety percent of the price and a target at one hundred twenty-five percent.

Andrew: And what comes out?

Ava: A CSV for each instrument, an aggregate CSV for each strategy, and optional HTML charts. The README links a published example on Apple stock, from April 2018 to April 2023. For the aggregate, Antoine suggests picking a real row by return, so the drawdown and duration you quote belong to the same run.

Andrew: So the takeaway is that the engine keeps its assumptions visible and its outputs comparable.

Ava: Exactly. The full write-up has the flow diagram and links straight to the source files.

A previously published batch-output chart from the related indicator article
Table of contents

A batch backtest is a small data pipeline: choose instruments, obtain prices, clean the observations, run a strategy, and save comparable results. AlgoETS/BatchBacktesting makes those steps visible in Python rather than hiding them behind a dashboard.

This image is an existing article illustration, not a new benchmark run.

1. Follow a single instrument first

In src/BatchBacktesting.py[1], process_instrument selects a stock or crypto price adapter, cleans the data, and constructs a Backtest. It attaches the instrument and strategy names to the result before returning it.

flowchart TD
  I["Instrument list and strategy"] --> P["ThreadPoolExecutor"]
  P --> D["Fetch and clean historical data"]
  D --> B["Backtest per instrument"]
  B --> R["Result with Instrument and Strategy"]
  R --> C["Per-instrument CSV"]
  R --> A["Aggregate strategy CSV"]
  B --> H["Optional HTML chart"]

The single-strategy runner defaults to four workers. Plot generation is optional. Those are code defaults, not measured throughput.

2. The assumptions are in the constructor

The inspected runner uses 100,000 starting cash, 0.002 commission (0.2%), and exclusive orders. These settings belong beside any comparison of returns.

They still do not cover every market cost or data issue. Slippage, availability of short positions, delisted securities, and corporate actions need separate review.

3. An EMA detail worth noticing

strategies.py[2] computes 20-, 80-, and 150-period EMAs for the EMA class. Its entry decisions compare the 20 and 80 curves; the 150-period curve is calculated but not used in those next conditions.

The long-side rule closes the prior position and buys with a stop at 90% of the current price and a target at 125%. This is the implemented experiment, not a claim that those parameters are optimal.

4. Keep comparable rows together

The runner writes per-instrument CSVs, an aggregate CSV per strategy, and optional HTML charts. The README links a published AAPL EMA chart covering 2018-04-04 through 2023-04-03. Those are that example’s dates, not a fixed range for every run.

Open the published AAPL example[3].

One analysis trap appears in analyse.py[4]: groupby("Instrument").max() takes each column’s maximum independently. The resulting row can combine metrics from different runs. Select a real row by return before narrating its drawdown and duration.

5. Know the failure boundaries

A failed instrument returns None. If all instruments fail, the later concatenation has no frames. The multi-strategy helper also creates an outer pool around inner pools, so API rate limits and nested concurrency deserve attention.

These are observations from reading the source. I did not rerun financial simulations for this article or generate new return claims.

References

  1. AlgoETS. (). src/BatchBacktesting.py. [Source file or documentation] github.com.
  2. AlgoETS. (). strategies.py. [Source file or documentation] github.com.
  3. Open the published AAPL example. (). [Web page] algoets.github.io.
  4. AlgoETS. (). analyse.py. [Source file or documentation] github.com.
  5. AlgoETS. (). BatchBacktesting. [Software repository] github.com.

References use this article’s publication date.