| name | notebook-to-strategy |
| description | Transfer code from a backtesting Jupyter notebook to a Trade Executor strategy module |
Notebook to strategy module skill
Transfer code from a backtesting Jupyter notebook to a Trade Executor strategy module.
Inputs
- Backtesting notebook: A Jupyter notebook file (
.ipynb) containing the strategy backtest
- Strategy module: A Python file (
.py) that will be created or updated
Both of these follow similar, but not same, structure as defined in .claude/skills/notebook-to-strategy/strategy-module-description.md.
How it works
The skill maps notebook sections to strategy module sections as defined in strategy-module-description.md.
Process
- Read and parse the notebook and existing strategy module (if any)
- Extract code from notebook cells, mapping to the appropriate sections
- Consolidate imports from all notebook cells to the top of the module
- Transfer functions, constants and comments:
Parameters class
create_trading_universe() function
decide_trades() function
- Indicator functions decorated with
@indicators.define()
create_indicators() wrapper function
- Chart functions and
create_charts() function
- Module-level constants (CHAIN_ID, VAULTS, EXCHANGES, etc.)
- MAke sure
required_live_history parameter matches the indicators used in in the decide_trades(), so that live indicator calculations will have enough data + margin
- Don't delete line comments from the input, like on Parameters class
- Preserve metadata if updating an existing module, or create placeholder metadata for new modules
- Format the output with proper section comments
- Verify by running a backtest command
Check for inconsistencies
- There cannot be supporting pairs that are in wrong chain: for example Hyperliquid vault strategy running on HyperEVM cannot cross-reference to pairs on Arbitrum for supporting pairs. Use Ask user tool to resolve these.
Verification
After 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.
- Either fix errors yourself
- Or if you do not understand the error, ask the user for help
Display results to the user
After running the backtest, the CLI command outputs three generated files like:
- Notebook: /Users/moo/code/trade-executor/state/master-vault-backtest.ipynb
HTML: /Users/moo/code/trade-executor/state/master-vault-backtest.html
- CSV: /Users/moo/code/trade-executor/state/master-vault-daily-returns.csv
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.
Update strategy module with results
Get the top 15 row results from the step above.
In the doc string header comment of the strategy module, includethe
- The results displayed as a restructured text table for Python comment
- Date the backtest was run
Notes
- The skill will preserve any existing metadata in the strategy module
- Imports are deduplicated and sorted
- Notebook-specific code (like
client = Client.create_jupyter_client()) is excluded
- Backtest execution code (
run_backtest_inline()) is excluded from the strategy module
- Chart rendering setup code specific to notebooks is excluded
- The
trading_strategy_engine_version constant is preserved or set appropriately.
Use the default "0.5"
Example functions and signatures for strategy module
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,
)
def create_charts(
timestamp: datetime.datetime | None,
parameters: StrategyParameters,
strategy_universe: TradingStrategyUniverse,
execution_context: ExecutionContext,
) -> ChartRegistry:
pass