---
title: "Run Backtest"
method: POST
path: "/api/v1/backtest"
tags: ["backtest"]
---

# Run Backtest

`POST /api/v1/backtest`

## Request

- Base URL: `https://api.ticktest.cn` (the document declares no server; this is the origin it was published from)
- URL: `https://api.ticktest.cn/api/v1/backtest`
- Auth: none declared

执行批量回测（代理到5104策略服务）— 入口持单用户并发闸

## Request body

- BacktestRequest: 回测请求
  - `symbol` string, required: 股票代码，如 sh600157
  - `strategy` string, required: 策略文件名，如 g_t0_signal_strategy_v3.py
  - `start_date` string: 回测起始日期 YYYY-MM-DD，默认半年前
  - `end_date` string: 回测结束日期 YYYY-MM-DD，默认今天
  - `initial_capital` number: 初始资金，默认100万
  - `position_ratio` number, nullable: 仓位比例(0~1)，与base_position二选一
  - `base_position` integer: 底仓市值(元)
  - `buy_steps` integer: 买入分批数
  - `sell_steps` integer: 卖出分批数
  - `slippage_pct` number: 滑点百分比，如0.1代表0.1%
  - `tolerance_sec` integer: 容忍秒数

## Response `200`

Successful Response

- BacktestResponse: 回测响应
  - `success` boolean
  - `symbol` string, required
  - `strategy` string, required
  - `named_strategy` string
  - `start_date` string, required
  - `end_date` string, required
  - `dates` string[]
  - `stats` BacktestStats: 回测统计
    - `total_days` integer
    - `trade_days` integer
    - `win_count` integer
    - `win_rate` number
    - `total_pnl` number
    - `avg_pnl` number
    - `sharpe` number, nullable
    - `total_return` number, nullable
    - `annual_return` number, nullable
    - `max_drawdown` number, nullable
  - `results` BacktestDayResult[]
    - `date` string
    - `win` boolean
    - `did_trade` boolean
    - `t_pnl` number, nullable
    - `signal` string, nullable
    - `trend` string, nullable
    - `buy_price` number, nullable
    - `sell_price` number, nullable
    - `trade_amount` number, nullable
    - `shares` integer, nullable
    - `operations` unknown[], nullable
      - unknown
    - `balance` number, nullable
  - `account_final` object, nullable
  - `position_ratio` number
  - `errors` string[]

## Other responses

- `422`: Validation Error

---

[API](https://skmtc.dev/ticktest/apis/ticktest-api.md) · [All operations](https://skmtc.dev/ticktest/apis/ticktest-api/llms.txt) · [OpenAPI document](https://skmtc.dev/ticktest/apis/ticktest-api/revisions/3e6d69d0eb1e?raw)
