Skip to content

Jupyter Notebook Workflow

GlowBack’s Python bindings are designed to work cleanly in notebooks. Use the helpers below to explore results inline.

If you want a reproducible starting point before opening Jupyter, run the checked-in companion smoke path first:

./scripts/python_sdk_quickstart.sh

That command creates an isolated virtualenv, builds gb-python, and runs examples/python_sdk_quickstart.py so the notebook snippets below start from a known-good install.

Install Notebook Dependencies

pip install jupyter pandas matplotlib

Run a Backtest

import glowback

# One-liner helper
result = glowback.run_buy_and_hold(
    symbols=["AAPL", "MSFT"],
    start_date="2024-01-01T00:00:00Z",
    end_date="2024-12-31T23:59:59Z",
    initial_capital=100000.0,
)

# Or use the engine directly for more control
engine = glowback.BacktestEngine(
    symbols=["AAPL", "MSFT"],
    start_date="2024-01-01T00:00:00Z",
    end_date="2024-12-31T23:59:59Z",
    initial_capital=100000.0,
)
result = engine.run_buy_and_hold()

Explore Results Inline

# Equity curve as a DataFrame
curve = result.to_dataframe(index="timestamp")
curve.head()

# Metrics summary table
metrics = result.metrics_dataframe()
metrics

# Quick notebook summary (metrics + curve, optional plot)
summary = result.summary(plot=True, index="timestamp")

# Plot the equity curve
ax = result.plot_equity()

Companion example

  • Checked-in script: examples/python_sdk_quickstart.py
  • Smoke wrapper: scripts/python_sdk_quickstart.sh

Use the script when you want a copy-pasteable starting point outside Jupyter, then lift the same calls into a notebook cell.

Notes

  • BacktestEngine/BacktestResult are friendly aliases for PyBacktestEngine/PyBacktestResult.
  • to_dataframe() and metrics_dataframe() require pandas.
  • plot_equity() requires matplotlib.
  • For custom visualizations, you can also use result.equity_curve directly (list of dicts).