Annotated notebook pattern for loading ticks, building signals and exporting trade logs for bot replay (ideal for Binder/Colab).
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
