> ## Documentation Index
> Fetch the complete documentation index at: https://docs.quantspace.limex.pro/llms.txt
> Use this file to discover all available pages before exploring further.

# run_trading_job

> Run a VectorBT backtesting simulation using portfolio weights

## Overview

`run_trading_job` runs a [VectorBT](https://vectorbt.dev) backtest from portfolio **weights** (`Portfolio.from_orders`, `TargetPercent`) and returns performance metrics (return, Sharpe, drawdown, …).

Usually the last step of the core path after [`run_po_job`](/tools/po-job).

***

## Parameters

<ParamField body="input_url" type="string" required>
  Blob storage URL pointing to a `portfolio_optimization_*.json` file.

  This is the `output_url` returned by `run_po_job`. The blob must contain `Weights` (and prices). Signal-based `Entries` / `Exits` are not used.
</ParamField>

<ParamField body="config" type="object" required>
  Trading and backtesting configuration.

  <Expandable title="config fields">
    <ParamField body="Trading params" type="object" required>
      Backtest execution settings.

      <Expandable title="Trading params fields">
        <ParamField body="initial_capital$" type="number">
          Initial portfolio cash in USD. Default: `1000000`.
        </ParamField>

        <ParamField body="frequency" type="string">
          Pandas frequency for the backtest. Use `"D"` (daily). Default: `"D"`.
        </ParamField>

        <ParamField body="trade_comission" type="integer">
          Round-trip transaction cost in **integer basis points** (bps), not a fraction.
          Example: `5` = 5 bps = 0.05%. Default: `0`.
        </ParamField>

        <ParamField body="slippage_bps" type="integer">
          Slippage in integer basis points. Example: `2` = 2 bps. Default: `0`.
        </ParamField>

        <ParamField body="risk_free_rate" type="number">
          Annual risk-free rate used for Sharpe/Sortino. Default: `0.02`.
        </ParamField>
      </Expandable>
    </ParamField>
  </Expandable>
</ParamField>

<Note>
  On the usual **no-ML** path you do not pass a separate testing-end date here — the backtest follows the prices/weights from portfolio optimization (sample start → end, with the first `covariance_window` days used as PO warmup upstream).
</Note>

***

## Returns

```json theme={null}
{
  "status": "Succeeded",
  "output_url": "https://stqsnpprod.blob.core.windows.net/data/trading_report_b1218bfd0544.json",
  "output_name": "trading_report_b1218bfd0544.json",
  "execution_name": "trading-worker-abc123xyz"
}
```

| Field            | Description                                 |
| ---------------- | ------------------------------------------- |
| `status`         | Job terminal status (`Succeeded`)           |
| `output_url`     | Full HTTPS URL to the backtest results blob |
| `output_name`    | Blob filename                               |
| `execution_name` | Job execution ID for audit/debugging        |

The `trading_report_*.json` blob contains VectorBT performance metrics: total return, Sharpe ratio,
max drawdown, win rate, and related statistics.

***

## Example

```json theme={null}
{
  "input_url": "https://stqsnpprod.blob.core.windows.net/data/portfolio_optimization_35c1b5239d23.json",
  "config": {
    "Trading params": {
      "initial_capital$": 1000000,
      "frequency": "D",
      "trade_comission": 5,
      "slippage_bps": 2,
      "risk_free_rate": 0.02
    }
  }
}
```

***

## Resources

| Resource           | Value                 |
| ------------------ | --------------------- |
| Container Apps Job | `trading-worker`      |
| Container name     | `trading-worker`      |
| Env vars injected  | `INPUT_URL`, `CONFIG` |
| Output blob prefix | `trading_report_`     |

***

## Next Steps

This is the last step of the core pipeline. Download the blob from `output_url` to inspect the results.

You can also run optional analytics from `portfolio_optimization_*.json` (or, for some tools, from `data_extractor_*.json` with optional weights):

* [`run_plot_job`](/tools/plot-job)
* [`run_st_job`](/tools/st-job)
* [`run_risk_job`](/tools/risk-job)
