with one click
notebook-to-strategy
// Transfer code from a backtesting Jupyter notebook to a Trade Executor strategy module
// Transfer code from a backtesting Jupyter notebook to a Trade Executor strategy module
| name | notebook-to-strategy |
| description | Transfer code from a backtesting Jupyter notebook to a Trade Executor strategy module |
Transfer code from a backtesting Jupyter notebook to a Trade Executor strategy module.
.ipynb) containing the strategy backtest.py) that will be created or updatedBoth of these follow similar, but not same, structure as defined in .claude/skills/notebook-to-strategy/strategy-module-description.md.
The skill maps notebook sections to strategy module sections as defined in strategy-module-description.md.
Parameters classcreate_trading_universe() functiondecide_trades() function@indicators.define()create_indicators() wrapper functioncreate_charts() functionrequired_live_history parameter matches the indicators used in in the decide_trades(), so that live indicator calculations will have enough data + marginAfter updating the strategy module, run a backtest to verify it works:
source .local-test.env && poetry run trade-executor \
backtest \
--render=charts \
--strategy-file <strategy_module_path>
Unless the script prints "All ok" at the end of it, it is a failure.
After running the backtest, the CLI command outputs three generated files like:
From the HTML file, extract Performance and risk metrics¶ table, format is so that you can display it inline in the chat, and print back test results of top 15 rows.
Get the top 15 row results from the step above.
In the doc string header comment of the strategy module, includethe
client = Client.create_jupyter_client()) is excludedrun_backtest_inline()) is excluded from the strategy moduletrading_strategy_engine_version constant is preserved or set appropriately.
Use the default "0.5"Some example functions how to implement functions in the trading strategy module.
def create_indicators(
timestamp: datetime.datetime,
parameters: StrategyParameters,
strategy_universe: TradingStrategyUniverse,
execution_context: ExecutionContext
):
return indicators.create_indicators(
timestamp=timestamp,
parameters=parameters,
strategy_universe=strategy_universe,
execution_context=execution_context,
)
# Define charts we use in backtesting and live trading
def create_charts(
timestamp: datetime.datetime | None,
parameters: StrategyParameters,
strategy_universe: TradingStrategyUniverse,
execution_context: ExecutionContext,
) -> ChartRegistry:
# Code from notebook goes here
pass