quantbrasil backtests run
Executa e salva um backtest para o usuário autenticado
Sintaxe
quantbrasil backtests run <strategy-id> <ticker>Esta é uma operação de alteração. Modos de saída: json, human.
Argumentos e opções
| Nome | Tipo | Obrigatório | Descrição | Padrão |
|---|---|---|---|---|
strategy-id | Argumento | Sim | ID da estratégia | — |
ticker | Argumento | Sim | Ticker do ativo | — |
--timeframe <timeframe> | Opção | Não | Timeframe do backtest | — |
--from <date> | Opção | Não | Data inicial em AAAA-MM-DD | — |
--to <date> | Opção | Não | Data final em AAAA-MM-DD | — |
--capital <number> | Opção | Não | Capital inicial | — |
--max-risk <number> | Opção | Não | Risco máximo | — |
--contracts <number> | Opção | Não | Número de contratos | 5 |
--param <key=value> | Opção | Não | Parâmetro da estratégia; pode ser usado várias vezes | |
--params-json <json> | Opção | Não | Objeto JSON com parâmetros da estratégia | — |
--no-save | Opção | Não | Executa sem salvar o backtest na sua conta | — |
--compact | Opção | Não | Saída JSON compacta para agentes | — |
--json | Opção | Não | Exibe saída JSON | — |
Exemplos
quantbrasil backtests run ifr2 PETR4 --timeframe D1 --from 2025-01-01 --to 2026-01-01
quantbrasil backtests run ifr2 PETR4 --timeframe D1 --param rsi=30 --param window=2 --jsonSaída (--json)
Estrutura da resposta retornada com --json:
export interface BacktestRunResponse {
ok: boolean;
summary_markdown: string;
backtest: SaveBacktestResponse;
status: BacktestStatusResponse | null;
}
export interface SaveBacktestResponse {
id: number | null;
origin: string | null;
setup_id: number | null;
timeframe_id: string;
strategy_id: string;
ticker: string;
asset_type: string;
can_monitor: boolean;
start_date: string;
end_date: string;
initial_capital: number;
parameters: Record<string, JsonValue>;
score: number | null;
score_percentiles: ScorePercentiles | null;
suspicious: boolean;
num_operations: number;
num_gains: number | null;
pct_gains: number;
avg_gains: number | null;
avg_losses: number | null;
avg_candles: number | null;
profit_factor: number | null;
pct_profit: number;
drawdown: number;
ev: number;
trade_history: JsonValue[];
best_win_streak: number | null;
worst_loss_streak: number | null;
}
export interface BacktestStatusResponse {
ok: boolean;
summary_markdown: string;
backtest_id: number;
strategy_id: string;
ticker: string;
timeframe_id: string;
entry_model:
| "close_confirmed"
| "next_candle_break"
| "live_price_trigger"
| "open_or_time";
data: {
state: "fresh" | "stale" | "unknown";
as_of: string | null;
age_minutes: number | null;
};
period: {
state: "not_started" | "open" | "closed" | "unknown";
candle_at: string | null;
complete: boolean;
closes_at: string | null;
};
session: {
state: "upcoming" | "open" | "closed" | "unknown";
reference_date: string;
timezone: string;
};
setup: {
state: "not_applicable" | "none" | "forming" | "formed" | "unknown";
candle_at: string | null;
};
activation: {
state:
| "not_applicable"
| "pending"
| "triggered"
| "confirmed"
| "expired"
| "invalidated"
| "unknown";
mode: "price_touch" | "at_close" | "at_open" | "scheduled_time";
triggered_at: string | null;
entry_price: number | null;
trigger: BacktestStatusTrigger | null;
reason: "stale_data" | "entry_stop_order_unknown" | null;
};
recent_event: {
state: "activated" | "expired" | "invalidated";
occurred_at: string;
entry_price: number | null;
mode: "price_touch" | "at_close" | "at_open" | "scheduled_time";
recency: "today" | "last_session";
} | null;
display_state:
| "waiting_confirmation"
| "waiting_activation"
| "activated"
| "window_closed"
| "no_opportunity"
| "invalidated"
| "unavailable";
attention: "none" | "watch" | "activated" | "unknown";
}
export interface ScorePercentiles {
percentile_5: number | null;
percentile_25: number | null;
percentile_50: number | null;
percentile_75: number | null;
percentile_95: number | null;
}
export interface BacktestStatusTrigger {
kind: "price" | "condition" | "time";
operator: "gte" | "lte" | null;
price: number | null;
observed: number | null;
condition_met: boolean | null;
scheduled_for: string | null;
}Exemplo de resposta
{
"ok": true,
"summary_markdown": "Backtest salvo para PETR4 em D1 com a estratégia ifr2.",
"backtest": {
"id": 123,
"origin": "tool",
"setup_id": 456,
"timeframe_id": "D1",
"strategy_id": "ifr2",
"ticker": "PETR4",
"asset_type": "B3",
"can_monitor": true,
"start_date": "2025-01-01",
"end_date": "2026-01-01",
"initial_capital": 10000,
"parameters": {
"rsi": 30
},
"score": 0.62,
"score_percentiles": null,
"suspicious": false,
"num_operations": 12,
"num_gains": 7,
"pct_gains": 0.58,
"avg_gains": 420,
"avg_losses": -180,
"avg_candles": 4,
"profit_factor": 1.8,
"pct_profit": 0.125,
"drawdown": 0.04,
"ev": 0.012,
"trade_history": [
{
"entry_date": "2025-01-10",
"exit_date": "2025-01-13",
"profit": 250
}
],
"best_win_streak": 3,
"worst_loss_streak": 2
},
"status": {
"ok": true,
"summary_markdown": "Entrada ativada em 37,61.",
"backtest_id": 123,
"strategy_id": "long_123",
"ticker": "PETR4",
"timeframe_id": "M30",
"entry_model": "next_candle_break",
"data": {
"state": "fresh",
"as_of": "2026-07-16T13:40:00Z",
"age_minutes": 5
},
"period": {
"state": "open",
"candle_at": "2026-07-16T13:30:00Z",
"complete": false,
"closes_at": "2026-07-16T14:00:00Z"
},
"session": {
"state": "open",
"reference_date": "2026-07-16",
"timezone": "America/Sao_Paulo"
},
"setup": {
"state": "formed",
"candle_at": "2026-07-16T13:00:00Z"
},
"activation": {
"state": "triggered",
"mode": "price_touch",
"triggered_at": "2026-07-16T13:30:00Z",
"entry_price": 37.61,
"trigger": {
"kind": "price",
"operator": "gte",
"price": 37.61,
"observed": 37.8,
"condition_met": null,
"scheduled_for": null
},
"reason": null
},
"recent_event": {
"state": "activated",
"occurred_at": "2026-07-16T13:30:00Z",
"entry_price": 37.61,
"mode": "price_touch",
"recency": "today"
},
"display_state": "activated",
"attention": "activated"
}
}Saída (--compact)
Estrutura da resposta retornada com --compact:
export interface BacktestRunCompactOutput {
ok: boolean;
backtest: Omit<SaveBacktestResponse, "trade_history">;
status: BacktestStatusResponse | null;
}Exemplo de resposta
{
"ok": true,
"backtest": {
"id": 123,
"origin": "tool",
"setup_id": 456,
"timeframe_id": "D1",
"strategy_id": "ifr2",
"ticker": "PETR4",
"asset_type": "B3",
"can_monitor": true,
"start_date": "2025-01-01",
"end_date": "2026-01-01",
"initial_capital": 10000,
"parameters": {
"rsi": 30
},
"score": 0.62,
"score_percentiles": null,
"suspicious": false,
"num_operations": 12,
"num_gains": 7,
"pct_gains": 0.58,
"avg_gains": 420,
"avg_losses": -180,
"avg_candles": 4,
"profit_factor": 1.8,
"pct_profit": 0.125,
"drawdown": 0.04,
"ev": 0.012,
"best_win_streak": 3,
"worst_loss_streak": 2
},
"status": {
"ok": true,
"summary_markdown": "Entrada ativada em 37,61.",
"backtest_id": 123,
"strategy_id": "long_123",
"ticker": "PETR4",
"timeframe_id": "M30",
"entry_model": "next_candle_break",
"data": {
"state": "fresh",
"as_of": "2026-07-16T13:40:00Z",
"age_minutes": 5
},
"period": {
"state": "open",
"candle_at": "2026-07-16T13:30:00Z",
"complete": false,
"closes_at": "2026-07-16T14:00:00Z"
},
"session": {
"state": "open",
"reference_date": "2026-07-16",
"timezone": "America/Sao_Paulo"
},
"setup": {
"state": "formed",
"candle_at": "2026-07-16T13:00:00Z"
},
"activation": {
"state": "triggered",
"mode": "price_touch",
"triggered_at": "2026-07-16T13:30:00Z",
"entry_price": 37.61,
"trigger": {
"kind": "price",
"operator": "gte",
"price": 37.61,
"observed": 37.8,
"condition_met": null,
"scheduled_for": null
},
"reason": null
},
"recent_event": {
"state": "activated",
"occurred_at": "2026-07-16T13:30:00Z",
"entry_price": 37.61,
"mode": "price_touch",
"recency": "today"
},
"display_state": "activated",
"attention": "activated"
}
}