Skip to content

backtest

The backtest.* commands create backtest payloads, inspect built-in strategies, preview factor weights, run strategy simulations, and tune parameter grids. Use this namespace when the user has explicit symbols, date ranges, and strategy assumptions that should be tested reproducibly.

All examples use --output json so results are stable to parse in terminals, scripts, and automation workflows.

Describe a backtest strategy and its parameters.

finance backtest.describe describes a backtest strategy and its parameters. It returns ok, data, error, and warnings in JSON output. The result payload includes name, summary, parameters, engine.

Use this command before backtest.run when you need to know what a built-in strategy does and which parameters it accepts.

Do not present backtests as live trading recommendations.

Terminal window
finance backtest.describe STRATEGY [--output json]
ArgumentRequiredDefaultAccepted valuesDescription
strategyYesNoneStringBuilt-in strategy key, such as sma_cross, or custom when using strategy_file.
Terminal window
finance backtest.describe sma_cross --output json

This output was generated with finance backtest.describe sma_cross --output json.

{
"ok": true,
"data": {
"name": "sma_cross",
"summary": "Long when a fast moving average crosses above a slow moving average.",
"parameters": {
"fast": {
"default": 20,
"type": "integer"
},
"slow": {
"default": 100,
"type": "integer"
}
},
"engine": "vectorbt"
},
"error": null,
"warnings": []
}
FieldTypeDescription
okbooleanWhether the command completed successfully.
dataobject or nullCommand-specific result payload. It is null when ok is false.
errorstring or nullHuman-readable error message when ok is false; otherwise null.
warningsarrayNon-fatal warnings returned by the command.
data.enginestringBacktest engine used.
data.namestringStrategy or result display name.
data.parametersobjectStrategy parameters included in the payload.
data.summarystringShort human-readable summary.
data.parameters.fastobjectFast moving-average parameter or value.
data.parameters.slowobjectSlow moving-average parameter or value.
data.parameters.fast.defaultintegerDefault parameter value.
data.parameters.fast.typestringParameter type accepted by the strategy.
data.parameters.slow.defaultintegerDefault parameter value.
data.parameters.slow.typestringParameter type accepted by the strategy.

Build a normalized factor backtest payload.

finance backtest.factor.payload builds a normalized factor backtest payload. It returns ok, data, error, and warnings in JSON output. The result payload includes factor_name, symbols, start_date, end_date, timeframe, initial_cash, direction, top_pct.

Use this command when you want to construct a normalized factor-backtest request before running or saving it elsewhere.

Do not present backtests as live trading recommendations.

Terminal window
finance backtest.factor.payload FACTOR_NAME SYMBOLS START_DATE END_DATE [timeframe=1d top_pct=0.2 bottom_pct=0.2] [--output json]
ArgumentRequiredDefaultAccepted valuesDescription
factor_nameYesNoneStringFactor identifier used to label the payload or rebalance preview.
symbolsYesNoneStringTicker symbol or comma-separated ticker list, such as AAPL,MSFT,NVDA.
start_dateYesNoneYYYY-MM-DDStart date in YYYY-MM-DD format.
end_dateYesNoneYYYY-MM-DDEnd date in YYYY-MM-DD format.
bottom_pctNo0.2NumberFraction of symbols assigned to the short basket.
timeframeNo1dStringBar interval used by the factor backtest.
top_pctNo0.2NumberFraction of symbols assigned to the long basket.
Terminal window
finance backtest.factor.payload rsi_14 AAPL,MSFT,NVDA 2024-01-01 2024-12-31 --output json

This output was generated with finance backtest.factor.payload rsi_14 AAPL,MSFT,NVDA 2024-01-01 2024-12-31 --output json.

{
"ok": true,
"data": {
"factor_name": "rsi_14",
"symbols": [
"AAPL",
"MSFT",
"NVDA"
],
"start_date": "2024-01-01",
"end_date": "2024-12-31",
"timeframe": "1d",
"initial_cash": 100000.0,
"direction": "long_short",
"top_pct": 0.2,
"bottom_pct": 0.2,
"rebalance_freq": "monthly",
"fixed_fee": 2.0,
"fees_pct": 0.001
},
"error": null,
"warnings": []
}
FieldTypeDescription
okbooleanWhether the command completed successfully.
dataobject or nullCommand-specific result payload. It is null when ok is false.
errorstring or nullHuman-readable error message when ok is false; otherwise null.
warningsarrayNon-fatal warnings returned by the command.
data.bottom_pctnumberBottom quantile percentage for factor selection.
data.directionstringLong/short ranking direction.
data.end_datestringEnd date used by the command.
data.factor_namestringFactor identifier used in the request.
data.fees_pctnumberPercentage fee rate.
data.fixed_feenumberFixed fee per order.
data.initial_cashnumberStarting cash for the backtest.
data.rebalance_freqstringRebalance frequency.
data.start_datestringStart date used by the command.
data.symbolsarrayTicker symbols included in the request.
data.symbols[]stringTicker symbols included in the request.
data.timeframestringBar interval used by the backtest.
data.top_pctnumberTop quantile percentage for factor selection.

Preview quantile factor target weights.

finance backtest.factor.weights previews quantile factor target weights. It returns ok, data, error, and warnings in JSON output. The result payload includes run_type, config, equity_curve, events, factor_name, symbols, weights, gross_exposure.

Use this command when you have factor scores and want to preview long/short target weights without downloading market data or running a full backtest.

Do not present backtests as live trading recommendations.

Terminal window
finance backtest.factor.weights FACTOR_NAME scores='{"AAPL":1.2,"MSFT":0.4}' [top_pct=0.2 bottom_pct=0.2] [--output json]
ArgumentRequiredDefaultAccepted valuesDescription
factor_nameYesNoneStringFactor identifier used to label the payload or rebalance preview.
scoresYesNoneStringJSON object mapping symbols to factor scores, for example {"AAPL":1.1,"MSFT":0.3}.
bottom_pctNo0.2NumberFraction of symbols assigned to the short basket.
top_pctNo0.2NumberFraction of symbols assigned to the long basket.
Terminal window
finance backtest.factor.weights rsi_14 scores='{"AAPL":1.1,"MSFT":0.3,"NVDA":2.0}' --output json

This output was generated with finance backtest.factor.weights rsi_14 scores='{"AAPL":1.1,"MSFT":0.3,"NVDA":2.0}' --output json.

{
"ok": true,
"data": {
"run_type": "factor_rebalance_preview",
"config": {
"factor_name": "rsi_14",
"timestamp": "preview",
"direction": "long_short",
"top_pct": 0.2,
"bottom_pct": 0.2
},
"equity_curve": [],
"events": [
{
"event_time": "preview",
"event_type": "rebalance_long",
"symbol": null,
"side": "long",
"quantity": 1.0,
"price": null,
"value": 0.5,
"label": "LONG basket: NVDA",
"payload": {
"weights": {
"NVDA": 0.5
}
}
},
{
"event_time": "preview",
"event_type": "rebalance_short",
"symbol": null,
"side": "short",
"quantity": 1.0,
"price": null,
"value": -0.5,
"label": "SHORT basket: MSFT",
"payload": {
"weights": {
"MSFT": -0.5
}
}
}
],
"factor_name": "rsi_14",
"symbols": [
"AAPL",
"MSFT",
"NVDA"
],
"weights": {
"AAPL": 0.0,
"MSFT": -0.5,
"NVDA": 0.5
},
"gross_exposure": 1.0,
"net_exposure": 0.0,
"rebalance_snapshot": {
"timestamp": "preview",
"long": [
{
"symbol": "NVDA",
"weight": 0.5
}
],
"short": [
{
"symbol": "MSFT",
"weight": -0.5
}
],
"gross_exposure": 1.0,
"net_exposure": 0.0
}
},
"error": null,
"warnings": []
}
FieldTypeDescription
okbooleanWhether the command completed successfully.
dataobject or nullCommand-specific result payload. It is null when ok is false.
errorstring or nullHuman-readable error message when ok is false; otherwise null.
warningsarrayNon-fatal warnings returned by the command.
data.configobjectRun configuration used by the command.
data.equity_curvearrayEquity curve observations.
data.eventsarrayBacktest or factor preview events.
data.events[]objectBacktest or factor preview events.
data.factor_namestringFactor identifier used in the request.
data.gross_exposurenumberSum of absolute target weights.
data.net_exposurenumberNet long minus short exposure.
data.rebalance_snapshotobjectPoint-in-time factor rebalance preview.
data.run_typestringType of backtest or preview run.
data.symbolsarrayTicker symbols included in the request.
data.symbols[]stringTicker symbols included in the request.
data.weightsobjectSymbol-to-weight mapping.
data.config.bottom_pctnumberBottom quantile percentage for factor selection.
data.config.directionstringLong/short ranking direction.
data.config.factor_namestringFactor identifier used in the request.
data.config.timestampstringTimestamp for the record or calculation step.
data.config.top_pctnumberTop quantile percentage for factor selection.
data.events[].event_timestringTimestamp for the backtest or rebalance event.
data.events[].event_typestringBacktest event type.
data.events[].labelstringDisplay label for the event or row.
data.events[].payloadobjectMode-specific payload.
data.events[].pricenullPrice associated with the event, quote, summary row, or order.
data.events[].quantitynumberOrder or event quantity.
data.events[].sidestringLong/short side for the event.
data.events[].symbolstring or nullSymbol associated with the event when the event is symbol-specific.
data.events[].valuenumberEvent value, such as target exposure or trade value.
data.rebalance_snapshot.gross_exposurenumberSum of absolute target weights.
data.rebalance_snapshot.longarrayLong basket or long-side entries in the rebalance snapshot.
data.rebalance_snapshot.long[]objectLong basket or long-side entries in the rebalance snapshot.
data.rebalance_snapshot.net_exposurenumberNet long minus short exposure.
data.rebalance_snapshot.shortarrayShort label or short-side basket, depending on the enclosing object.
data.rebalance_snapshot.short[]objectShort label or short-side basket, depending on the enclosing object.
data.rebalance_snapshot.timestampstringTimestamp for the record or calculation step.
data.weights.AAPLnumberValue associated with AAPL in the symbol-keyed mapping.
data.weights.MSFTnumberValue associated with MSFT in the symbol-keyed mapping.
data.weights.NVDAnumberValue associated with NVDA in the symbol-keyed mapping.
data.events[].payload.weightsobjectSymbol-to-weight mapping.
data.rebalance_snapshot.long[].symbolstringSymbol in the long basket.
data.rebalance_snapshot.long[].weightnumberPortfolio weight for one symbol.
data.rebalance_snapshot.short[].symbolstringSymbol in the short basket.
data.rebalance_snapshot.short[].weightnumberPortfolio weight for one symbol.
data.events[].payload.weights.MSFTnumberValue associated with MSFT in the symbol-keyed mapping.
data.events[].payload.weights.NVDAnumberValue associated with NVDA in the symbol-keyed mapping.

Run a VectorBT strategy backtest.

finance backtest.run runs a VectorBT strategy backtest. It returns ok, data, error, and warnings in JSON output. The result payload includes run_type, engine, config, metrics, data, equity_curve, trades, orders.

Use when the user asks to run a named strategy over explicit symbols and dates.

Do not use this command as proof a strategy will work in live trading.

Terminal window
finance backtest.run STRATEGY SYMBOLS START_DATE END_DATE [params='{}' strategy_file=./rule.py] [--output json]
ArgumentRequiredDefaultAccepted valuesDescription
strategyYesNoneStringBuilt-in strategy key, such as sma_cross, or custom when using strategy_file.
symbolsYesNoneStringTicker symbol or comma-separated ticker list, such as AAPL,MSFT,NVDA.
start_dateYesNoneYYYY-MM-DDStart date in YYYY-MM-DD format.
end_dateYesNoneYYYY-MM-DDEnd date in YYYY-MM-DD format.
paramsNo{}JSON object or key-value parametersStrategy parameters. You can pass JSON or key-value pairs such as fast=20 slow=100.
strategy_fileNo./rule.pyStringLocal Python strategy file used only with custom strategies.
Terminal window
finance backtest.run sma_cross AAPL 2020-01-01 2024-12-31 fast=20 slow=100 --output json

This output was generated with finance backtest.run sma_cross AAPL 2020-01-01 2024-12-31 fast=20 slow=100 --output json.

{
"ok": true,
"data": {
"run_type": "vectorbt_backtest",
"engine": "vectorbt",
"config": {
"strategy": "sma_cross",
"symbols": [
"AAPL"
],
"start_date": "2020-01-01",
"end_date": "2024-12-31",
"timeframe": "1d",
"initial_cash": 100000.0,
"fees": 0.001,
"fixed_fees": 0.0,
"slippage": 0.0,
"provider": "auto",
"params": {
"fast": 20,
"slow": 100
},
"strategy_file": null,
"plot_path": null,
"engine": "vectorbt"
},
"metrics": {
"start_value": 100000.0,
"end_value": 100000.0,
"total_return_pct": 0.0,
"benchmark_return_pct": 235.874802,
"max_drawdown_pct": null,
"total_trades": 0,
"win_rate_pct": null,
"profit_factor": null,
"expectancy": null,
"sharpe_ratio": null,
"calmar_ratio": null,
"omega_ratio": null,
"sortino_ratio": null,
"total_fees_paid": 0.0,
"total_return_decimal": 0.0
},
"data": {
"symbols": [
"AAPL"
],
"rows": 1257,
"start": "2020-01-02T05:00:00",
"end": "2024-12-30T05:00:00",
"sources": {
"AAPL": "yfinance"
}
},
"equity_curve": [
{
"date": "2020-01-02T05:00:00",
"value": 100000.0
},
{
"date": "2020-02-07T05:00:00",
"value": 100000.0
},
{
"date": "2020-03-16T04:00:00",
"value": 100000.0
},
{
"date": "2020-04-21T04:00:00",
"value": 100000.0
},
{
"date": "2020-05-27T04:00:00",
"value": 100000.0
},
{
"date": "2020-07-01T04:00:00",
"value": 100000.0
},
{
"date": "2020-08-06T04:00:00",
"value": 100000.0
},
{
"date": "2020-09-11T04:00:00",
"value": 100000.0
},
{
"date": "2020-10-16T04:00:00",
"value": 100000.0
},
{
"date": "2020-11-20T05:00:00",
"value": 100000.0
},
{
"date": "2020-12-29T05:00:00",
"value": 100000.0
},
{
"date": "2021-02-04T05:00:00",
"value": 100000.0
},
{
"date": "2021-03-12T05:00:00",
"value": 100000.0
},
{
"date": "2021-04-19T04:00:00",
"value": 100000.0
},
{
"date": "2021-05-24T04:00:00",
"value": 100000.0
},
{
"date": "2021-06-29T04:00:00",
"value": 100000.0
},
{
"date": "2021-08-04T04:00:00",
"value": 100000.0
},
{
"date": "2021-09-09T04:00:00",
"value": 100000.0
},
{
"date": "2021-10-14T04:00:00",
"value": 100000.0
},
{
"date": "2021-11-18T05:00:00",
"value": 100000.0
},
{
"date": "2021-12-27T05:00:00",
"value": 100000.0
},
{
"date": "2022-02-01T05:00:00",
"value": 100000.0
},
{
"date": "2022-03-09T05:00:00",
"value": 100000.0
},
{
"date": "2022-04-13T04:00:00",
"value": 100000.0
},
{
"date": "2022-05-19T04:00:00",
"value": 100000.0
},
{
"date": "2022-06-27T04:00:00",
"value": 100000.0
},
{
"date": "2022-08-02T04:00:00",
"value": 100000.0
},
{
"date": "2022-09-07T04:00:00",
"value": 100000.0
},
{
"date": "2022-10-12T04:00:00",
"value": 100000.0
},
{
"date": "2022-11-16T05:00:00",
"value": 100000.0
},
{
"date": "2022-12-22T05:00:00",
"value": 100000.0
},
{
"date": "2023-01-31T05:00:00",
"value": 100000.0
},
{
"date": "2023-03-08T05:00:00",
"value": 100000.0
},
{
"date": "2023-04-13T04:00:00",
"value": 100000.0
},
{
"date": "2023-05-18T04:00:00",
"value": 100000.0
},
{
"date": "2023-06-26T04:00:00",
"value": 100000.0
},
{
"date": "2023-08-01T04:00:00",
"value": 100000.0
},
{
"date": "2023-09-06T04:00:00",
"value": 100000.0
},
{
"date": "2023-10-11T04:00:00",
"value": 100000.0
},
{
"date": "2023-11-15T05:00:00",
"value": 100000.0
},
{
"date": "2023-12-21T05:00:00",
"value": 100000.0
},
{
"date": "2024-01-30T05:00:00",
"value": 100000.0
},
{
"date": "2024-03-06T05:00:00",
"value": 100000.0
},
{
"date": "2024-04-11T04:00:00",
"value": 100000.0
},
{
"date": "2024-05-16T04:00:00",
"value": 100000.0
},
{
"date": "2024-06-24T04:00:00",
"value": 100000.0
},
{
"date": "2024-07-30T04:00:00",
"value": 100000.0
},
{
"date": "2024-09-04T04:00:00",
"value": 100000.0
},
{
"date": "2024-10-09T04:00:00",
"value": 100000.0
},
{
"date": "2024-11-13T05:00:00",
"value": 100000.0
},
{
"date": "2024-12-19T05:00:00",
"value": 100000.0
}
],
"trades": [],
"orders": [],
"target_weights": [],
"warnings": []
},
"error": null,
"warnings": []
}
FieldTypeDescription
okbooleanWhether the command completed successfully.
dataobject or nullCommand-specific result payload. It is null when ok is false.
errorstring or nullHuman-readable error message when ok is false; otherwise null.
warningsarrayNon-fatal warnings returned by the command.
data.configobjectRun configuration used by the command.
data.dataobjectDownloaded market-data summary used by the backtest.
data.enginestringBacktest engine used.
data.equity_curvearrayEquity curve observations.
data.equity_curve[]objectEquity curve observations.
data.metricsobjectMetrics requested by the caller.
data.ordersarrayGenerated order records.
data.run_typestringType of backtest or preview run.
data.target_weightsarrayTarget portfolio weights.
data.tradesarrayExecuted trade records.
data.warningsarrayNon-fatal warnings returned by the command.
data.config.end_datestringEnd date used by the command.
data.config.enginestringBacktest engine used.
data.config.feesnumberFee amount for an order or trade.
data.config.fixed_feesnumberFixed fee amount used by the backtest engine.
data.config.initial_cashnumberStarting cash for the backtest.
data.config.paramsobjectStrategy parameters supplied by the caller.
data.config.plot_pathnullPath to a generated plot when requested.
data.config.providerstringProvider identifier.
data.config.slippagenumberSlippage assumption used by the backtest engine.
data.config.start_datestringStart date used by the command.
data.config.strategystringStrategy key requested by the command.
data.config.strategy_filenullCustom strategy file path when a custom strategy is used.
data.config.symbolsarrayTicker symbols included in the request.
data.config.symbols[]stringTicker symbols included in the request.
data.config.timeframestringBar interval used by the backtest.
data.data.endstringEnd timestamp in the downloaded backtest data.
data.data.rowsintegerStructured rows returned by the command.
data.data.sourcesobjectProvider/source handles used in the result.
data.data.startstringStart timestamp in the downloaded backtest data.
data.data.symbolsarrayTicker symbols included in the request.
data.data.symbols[]stringTicker symbols included in the request.
data.equity_curve[].datestringEvent, bar, filing, or publication date.
data.equity_curve[].valuenumberPortfolio equity value at that date.
data.metrics.benchmark_return_pctnumberBenchmark return percentage.
data.metrics.calmar_rationullCalmar ratio.
data.metrics.end_valuenumberPortfolio value at the end of the run.
data.metrics.expectancynullAverage expected trade result.
data.metrics.max_drawdown_pctnullMaximum drawdown percentage.
data.metrics.omega_rationullOmega ratio.
data.metrics.profit_factornullGross profit divided by gross loss.
data.metrics.sharpe_rationullSharpe ratio.
data.metrics.sortino_rationullSortino ratio.
data.metrics.start_valuenumberPortfolio value at the start of the run.
data.metrics.total_fees_paidnumberTotal fees paid in the run.
data.metrics.total_return_decimalnumberTotal return as a decimal.
data.metrics.total_return_pctnumberTotal return percentage.
data.metrics.total_tradesintegerNumber of trades.
data.metrics.win_rate_pctnullWinning trade percentage.
data.config.params.fastintegerFast moving-average parameter or value.
data.config.params.slowintegerSlow moving-average parameter or value.
data.data.sources.AAPLstringValue associated with AAPL in the symbol-keyed mapping.

List VectorBT-backed strategy presets.

finance backtest.strategies lists VectorBT-backed strategy presets. It returns ok, data, error, and warnings in JSON output. The result payload includes engine, strategies.

Use this command when you need to see which built-in strategy keys are available before describing, running, or tuning one.

Do not present backtests as live trading recommendations.

Terminal window
finance backtest.strategies [--output json]

No arguments.

Terminal window
finance backtest.strategies --output json

This output was generated with finance backtest.strategies --output json.

{
"ok": true,
"data": {
"engine": "vectorbt",
"strategies": [
{
"name": "buy_hold",
"summary": "Equal-weight buy and hold across all symbols.",
"parameters": {}
},
{
"name": "sma_cross",
"summary": "Long when a fast moving average crosses above a slow moving average.",
"parameters": {
"fast": {
"default": 20,
"type": "integer"
},
"slow": {
"default": 100,
"type": "integer"
}
}
},
{
"name": "rsi_reversion",
"summary": "Long when RSI is below lower threshold; exit above upper threshold.",
"parameters": {
"window": {
"default": 14,
"type": "integer"
},
"lower": {
"default": 30,
"type": "number"
},
"upper": {
"default": 55,
"type": "number"
}
}
},
{
"name": "momentum_top_n",
"summary": "Rebalance into the top N symbols by trailing return.",
"parameters": {
"lookback": {
"default": 63,
"type": "integer"
},
"top_n": {
"default": 3,
"type": "integer"
},
"rebalance": {
"default": "M",
"type": "string",
"allowed": [
"D",
"W",
"M"
]
}
}
}
]
},
"error": null,
"warnings": []
}
FieldTypeDescription
okbooleanWhether the command completed successfully.
dataobject or nullCommand-specific result payload. It is null when ok is false.
errorstring or nullHuman-readable error message when ok is false; otherwise null.
warningsarrayNon-fatal warnings returned by the command.
data.enginestringBacktest engine used.
data.strategiesarrayBuilt-in strategy definitions.
data.strategies[]objectBuilt-in strategy definitions.
data.strategies[].namestringStrategy or result display name.
data.strategies[].parametersobjectParameter definitions accepted by this strategy.
data.strategies[].summarystringShort human-readable summary.
data.strategies[].parameters.fastobjectFast moving-average parameter or value.
data.strategies[].parameters.lookbackobjectCalendar lookback window requested by the command.
data.strategies[].parameters.lowerobjectLower threshold parameter for the strategy.
data.strategies[].parameters.rebalanceobjectRebalance parameter definition.
data.strategies[].parameters.slowobjectSlow moving-average parameter or value.
data.strategies[].parameters.top_nobjectTop-N selection parameter for the strategy.
data.strategies[].parameters.upperobjectUpper threshold parameter for the strategy.
data.strategies[].parameters.windowobjectWindow size used for the calculation.
data.strategies[].parameters.fast.defaultintegerDefault parameter value.
data.strategies[].parameters.fast.typestringParameter type accepted by the strategy.
data.strategies[].parameters.lookback.defaultintegerDefault parameter value.
data.strategies[].parameters.lookback.typestringParameter type accepted by the strategy.
data.strategies[].parameters.lower.defaultintegerDefault parameter value.
data.strategies[].parameters.lower.typestringParameter type accepted by the strategy.
data.strategies[].parameters.rebalance.allowedarrayWhether a screen field or value is allowed by the provider.
data.strategies[].parameters.rebalance.allowed[]stringWhether a screen field or value is allowed by the provider.
data.strategies[].parameters.rebalance.defaultstringDefault parameter value.
data.strategies[].parameters.rebalance.typestringParameter type accepted by the strategy.
data.strategies[].parameters.slow.defaultintegerDefault parameter value.
data.strategies[].parameters.slow.typestringParameter type accepted by the strategy.
data.strategies[].parameters.top_n.defaultintegerDefault parameter value.
data.strategies[].parameters.top_n.typestringParameter type accepted by the strategy.
data.strategies[].parameters.upper.defaultintegerDefault parameter value.
data.strategies[].parameters.upper.typestringParameter type accepted by the strategy.
data.strategies[].parameters.window.defaultintegerDefault parameter value.
data.strategies[].parameters.window.typestringParameter type accepted by the strategy.

Build a normalized strategy backtest payload.

finance backtest.strategy.payload builds a normalized strategy backtest payload. It returns ok, data, error, and warnings in JSON output. The result payload includes strategy_id, start_date, end_date, initial_cash, parameters, fee_mode, fixed_fee, fees_pct.

Use this command when you need a normalized strategy payload but do not want to run the backtest yet.

Do not present backtests as live trading recommendations.

Terminal window
finance backtest.strategy.payload STRATEGY_ID START_DATE END_DATE [initial_cash=100000 parameters='{}'] [--output json]
ArgumentRequiredDefaultAccepted valuesDescription
start_dateYesNoneYYYY-MM-DDStart date in YYYY-MM-DD format.
end_dateYesNoneYYYY-MM-DDEnd date in YYYY-MM-DD format.
strategy_idYesNoneStringStrategy identifier to place in the payload.
initial_cashNo100000IntegerStarting cash used by the payload or backtest.
parametersNo{}JSON object or key-value parametersStrategy parameter object to include in the payload.
Terminal window
finance backtest.strategy.payload mean_reversion 2024-01-01 2024-12-31 --output json

This output was generated with finance backtest.strategy.payload mean_reversion 2024-01-01 2024-12-31 --output json.

{
"ok": true,
"data": {
"strategy_id": "mean_reversion",
"start_date": "2024-01-01",
"end_date": "2024-12-31",
"initial_cash": 100000.0,
"parameters": {},
"fee_mode": "mixed",
"fixed_fee": 2.0,
"fees_pct": 0.001
},
"error": null,
"warnings": []
}
FieldTypeDescription
okbooleanWhether the command completed successfully.
dataobject or nullCommand-specific result payload. It is null when ok is false.
errorstring or nullHuman-readable error message when ok is false; otherwise null.
warningsarrayNon-fatal warnings returned by the command.
data.end_datestringEnd date used by the command.
data.fee_modestringFee calculation mode.
data.fees_pctnumberPercentage fee rate.
data.fixed_feenumberFixed fee per order.
data.initial_cashnumberStarting cash for the backtest.
data.parametersobjectStrategy parameters included in the payload.
data.start_datestringStart date used by the command.
data.strategy_idstringStrategy identifier in the payload.

Run a bounded VectorBT parameter grid.

finance backtest.tune runs a bounded VectorBT parameter grid. It returns ok, data, error, and warnings in JSON output. The result payload includes run_type, engine, strategy, symbols, start_date, end_date, timeframe, metric.

Use this command when you have a bounded parameter grid and want Finance CLI to run each candidate combination against the same symbols and date range.

Do not present backtests as live trading recommendations.

Terminal window
finance backtest.tune STRATEGY SYMBOLS START_DATE END_DATE grid='{}' [metric=sharpe_ratio max_runs=100] [--output json]
ArgumentRequiredDefaultAccepted valuesDescription
strategyYesNoneStringBuilt-in strategy key, such as sma_cross, or custom when using strategy_file.
symbolsYesNoneStringTicker symbol or comma-separated ticker list, such as AAPL,MSFT,NVDA.
end_dateYesNoneYYYY-MM-DDEnd date in YYYY-MM-DD format.
gridYesNoneJSON object or key-value parametersParameter grid where each key maps to a list of candidate values.
start_dateYesNoneYYYY-MM-DDStart date in YYYY-MM-DD format.
max_runsNo100IntegerSafety cap on parameter combinations evaluated.
metricNosharpe_ratioStringMetric used to rank grid-search results.
Terminal window
finance backtest.tune sma_cross AAPL 2020-01-01 2024-12-31 grid='{"fast":[10,20],"slow":[50,100]}' --output json

This output was generated with finance backtest.tune sma_cross AAPL 2020-01-01 2024-12-31 grid='{"fast":[10,20],"slow":[50,100]}' --output json.

{
"ok": true,
"data": {
"run_type": "vectorbt_tune",
"engine": "vectorbt",
"strategy": "sma_cross",
"symbols": [
"AAPL"
],
"start_date": "2020-01-01",
"end_date": "2024-12-31",
"timeframe": "1d",
"metric": "sharpe_ratio",
"runs": 4,
"best": {
"params": {
"fast": 10,
"slow": 50
},
"metrics": {
"start_value": 100000.0,
"end_value": 100000.0,
"total_return_pct": 0.0,
"benchmark_return_pct": 235.874802,
"max_drawdown_pct": null,
"total_trades": 0,
"win_rate_pct": null,
"profit_factor": null,
"expectancy": null,
"sharpe_ratio": null,
"calmar_ratio": null,
"omega_ratio": null,
"sortino_ratio": null,
"total_fees_paid": 0.0,
"total_return_decimal": 0.0
},
"score": null
},
"results": [
{
"params": {
"fast": 10,
"slow": 50
},
"metrics": {
"start_value": 100000.0,
"end_value": 100000.0,
"total_return_pct": 0.0,
"benchmark_return_pct": 235.874802,
"max_drawdown_pct": null,
"total_trades": 0,
"win_rate_pct": null,
"profit_factor": null,
"expectancy": null,
"sharpe_ratio": null,
"calmar_ratio": null,
"omega_ratio": null,
"sortino_ratio": null,
"total_fees_paid": 0.0,
"total_return_decimal": 0.0
},
"score": null
},
{
"params": {
"fast": 10,
"slow": 100
},
"metrics": {
"start_value": 100000.0,
"end_value": 100000.0,
"total_return_pct": 0.0,
"benchmark_return_pct": 235.874802,
"max_drawdown_pct": null,
"total_trades": 0,
"win_rate_pct": null,
"profit_factor": null,
"expectancy": null,
"sharpe_ratio": null,
"calmar_ratio": null,
"omega_ratio": null,
"sortino_ratio": null,
"total_fees_paid": 0.0,
"total_return_decimal": 0.0
},
"score": null
},
{
"params": {
"fast": 20,
"slow": 50
},
"metrics": {
"start_value": 100000.0,
"end_value": 100000.0,
"total_return_pct": 0.0,
"benchmark_return_pct": 235.874802,
"max_drawdown_pct": null,
"total_trades": 0,
"win_rate_pct": null,
"profit_factor": null,
"expectancy": null,
"sharpe_ratio": null,
"calmar_ratio": null,
"omega_ratio": null,
"sortino_ratio": null,
"total_fees_paid": 0.0,
"total_return_decimal": 0.0
},
"score": null
},
{
"params": {
"fast": 20,
"slow": 100
},
"metrics": {
"start_value": 100000.0,
"end_value": 100000.0,
"total_return_pct": 0.0,
"benchmark_return_pct": 235.874802,
"max_drawdown_pct": null,
"total_trades": 0,
"win_rate_pct": null,
"profit_factor": null,
"expectancy": null,
"sharpe_ratio": null,
"calmar_ratio": null,
"omega_ratio": null,
"sortino_ratio": null,
"total_fees_paid": 0.0,
"total_return_decimal": 0.0
},
"score": null
}
],
"warnings": []
},
"error": null,
"warnings": []
}
FieldTypeDescription
okbooleanWhether the command completed successfully.
dataobject or nullCommand-specific result payload. It is null when ok is false.
errorstring or nullHuman-readable error message when ok is false; otherwise null.
warningsarrayNon-fatal warnings returned by the command.
data.bestobjectBest parameter set according to the requested metric.
data.end_datestringEnd date used by the command.
data.enginestringBacktest engine used.
data.metricstringMetric name.
data.resultsarrayPer-run or per-provider result records.
data.results[]objectPer-run or per-provider result records.
data.run_typestringType of backtest or preview run.
data.runsintegerParameter-grid runs executed.
data.start_datestringStart date used by the command.
data.strategystringStrategy key requested by the command.
data.symbolsarrayTicker symbols included in the request.
data.symbols[]stringTicker symbols included in the request.
data.timeframestringBar interval used by the backtest.
data.warningsarrayNon-fatal warnings returned by the command.
data.best.metricsobjectMetrics requested by the caller.
data.best.paramsobjectStrategy parameters supplied by the caller.
data.best.scorenullOptimization score for the run; null when the selected metric is unavailable.
data.results[].metricsobjectMetrics requested by the caller.
data.results[].paramsobjectStrategy parameters supplied by the caller.
data.results[].scorenullOptimization score for the run; null when the selected metric is unavailable.
data.best.metrics.benchmark_return_pctnumberBenchmark return percentage.
data.best.metrics.calmar_rationullCalmar ratio.
data.best.metrics.end_valuenumberPortfolio value at the end of the run.
data.best.metrics.expectancynullAverage expected trade result.
data.best.metrics.max_drawdown_pctnullMaximum drawdown percentage.
data.best.metrics.omega_rationullOmega ratio.
data.best.metrics.profit_factornullGross profit divided by gross loss.
data.best.metrics.sharpe_rationullSharpe ratio.
data.best.metrics.sortino_rationullSortino ratio.
data.best.metrics.start_valuenumberPortfolio value at the start of the run.
data.best.metrics.total_fees_paidnumberTotal fees paid in the run.
data.best.metrics.total_return_decimalnumberTotal return as a decimal.
data.best.metrics.total_return_pctnumberTotal return percentage.
data.best.metrics.total_tradesintegerNumber of trades.
data.best.metrics.win_rate_pctnullWinning trade percentage.
data.best.params.fastintegerFast moving-average parameter or value.
data.best.params.slowintegerSlow moving-average parameter or value.
data.results[].metrics.benchmark_return_pctnumberBenchmark return percentage.
data.results[].metrics.calmar_rationullCalmar ratio.
data.results[].metrics.end_valuenumberPortfolio value at the end of the run.
data.results[].metrics.expectancynullAverage expected trade result.
data.results[].metrics.max_drawdown_pctnullMaximum drawdown percentage.
data.results[].metrics.omega_rationullOmega ratio.
data.results[].metrics.profit_factornullGross profit divided by gross loss.
data.results[].metrics.sharpe_rationullSharpe ratio.
data.results[].metrics.sortino_rationullSortino ratio.
data.results[].metrics.start_valuenumberPortfolio value at the start of the run.
data.results[].metrics.total_fees_paidnumberTotal fees paid in the run.
data.results[].metrics.total_return_decimalnumberTotal return as a decimal.
data.results[].metrics.total_return_pctnumberTotal return percentage.
data.results[].metrics.total_tradesintegerNumber of trades.
data.results[].metrics.win_rate_pctnullWinning trade percentage.
data.results[].params.fastintegerFast moving-average parameter or value.
data.results[].params.slowintegerSlow moving-average parameter or value.