Backtest notebook — Jupyter

Annotated notebook pattern for loading ticks, building signals and exporting trade logs for bot replay (ideal for Binder/Colab).

Backtest notebook — Jupyter

Jupyter

Category: Code Library  •  Tags: jupyter, backtest, pandas  •  Published: PUBLISH_DATE

Notebook snippet (pandas)

      Copyimport pandas as pd

df = pd.read_csv('ticks.csv', parse_dates=['time'])
df['mid'] = (df['bid'] + df['ask']) / 2
df['sma20'] = df['mid'].rolling(20).mean()
df['signal'] = (df['mid'] > df['sma20']).astype(int)

# simplified simulation...
trades = []
# export trades
pd.DataFrame(trades).to_csv('trades.csv', index=False)

Run online

Include a requirements.txt and a small sample dataset in the post attachments or site downloads for reproducible runs on Binder or Colab.

License: MIT

Back to Code Library

Don’t miss our blog post!

We don’t spam! Read our privacy policy for more info.

Leave a Reply

Your email address will not be published. Required fields are marked *