AI Trading is invite only. Check your Moby inbox for a code, or DM us on X for access. DM us on X →

Moby Agent Marketplace Connect Moby MCP Get the app

Backtesting.py

by @kerncCOMMUNITY· v0.6.6· Updated Nov 2, 2026

kernc/backtesting.py★ 9,251

Backtesting.py tests an entry and exit rule on any OHLCV, including the Solana candles your agent pulls from Moby, with stats and a chart of every trade.

About

Backtesting.py is a small Python library. Give it a pandas table of OHLCV candles and a strategy class with entry and exit rules, and it returns the usual statistics (return, win rate, drawdown, Sharpe, exposure) and an interactive chart of every trade. It also has a parameter optimizer.

What it adds to Moby. A quick backtest on the exact data your Moby agent trades. It does not care where candles come from, so your agent can test a rule on a Solana token's own history, new launches included, once there is enough of it.

How to pair it. Turn a strategy idea (for example a breakout with Moby's default -30% stop and +100% take-profit) into a Backtesting.py strategy, run it on a few tokens from get_token_ohlcv, and show the stats before you save it as a Moby strategy. Moby returns candles newest-first; reverse them before you feed them in.

What it does not do. It tests one instrument at a time with a simple fill model, so slippage on thin Solana pools is understated; add a generous commission. It does not trade. Its license is AGPL-3.0, which matters only if you ship it inside a product.

What's inside this repo

  • Backtest and Strategy classes: write init() and next() with self.buy() and self.sell()
  • Any instrument with OHLC(V) candles in a pandas DataFrame
  • Stats: return, Sharpe, Sortino, Calmar, max drawdown, win rate, profit factor, SQN, Kelly
  • Interactive plot of the equity curve and every trade (bt.plot())
  • Built-in optimizer (SAMBO) with heatmaps of parameter results
  • backtesting.lib: crossover() helper and composable base strategies
  • Commission and exclusive_orders options; trade list and equity curve as pandas objects

Install steps

Third-party code: Moby does not audit or control it. Read the source before you run it.

  1. pip install backtesting
  2. Read the quick-start: https://kernc.github.io/backtesting.py/
  3. Ask: Pull 30 days of hourly candles for <token> with get_token_ohlcv, put them oldest-first, and backtest a breakout rule with a -30% stop and +100% take-profit in Backtesting.py. Include 1% commission.

Permissions

Reads
OHLCV candles your agent fetches from Moby (get_token_ohlcv) or any other source
Writes
Local result files and HTML charts
Tools
Python library `backtesting`
Trade
Never trades

Review

Reviewed Nov 1, 2026. Source matches repo at commit ca2e261

On GitHub

kernc/backtesting.py

Stars
9,251
Forks
1,585

How it works with Moby

Backtesting.py works on its own. With Moby your agent can also trade on what it finds.

  1. Set up AI Trading

    In the Moby app: create your agent and fund its Solana wallet.

    Get the app
  2. Connect Moby MCP

    Whale, KOL and smart-money data, plus buy, sell, SL and TP from the agent wallet.

    View Moby MCP
  3. Install Backtesting.py

    Your agent runs it alongside Moby's onchain data and trades inside your Guardrails.

    Install

Reviewed Nov 1, 2026 · Report this item

Install Backtesting.py