# Workflow automation (/features/tooling/workflow-automation)

How do you run research and data updates unattended and hear when something happens? VBT schedules
Python jobs for trading research, such as an hourly data update that sends a Telegram alert when a
signal fires, and adds parallel tasks, nested progress bars, and a command-line interface.

```python title="Update BTCUSDT hourly and alert on moving average crossovers, replayed over one week"
>>> def signal_message(data):
...     close = data.close.iloc[:-1]  # (1)
...     fast = vbt.MA.run(close, window=20)
...     slow = vbt.MA.run(close, window=50)
...     bar = f"{close.index[-1]:%Y-%m-%d %H:%M} BTCUSDT 20h MA crossed"
...     if fast.ma_crossed_above(slow).iloc[-1]:
...         return f"{bar} above 50h MA at {close.iloc[-1]:,.0f}"
...     if fast.ma_crossed_below(slow).iloc[-1]:
...         return f"{bar} below 50h MA at {close.iloc[-1]:,.0f}"

>>> class AlertUpdater(vbt.DataUpdater):
...     def __init__(self, data, notify, **kwargs):
...         vbt.DataUpdater.__init__(self, data, notify=notify, **kwargs)
...         self._notify = notify
...
...     def update(self, **kwargs):
...         vbt.DataUpdater.update(self, **kwargs)  # (2)
...         message = signal_message(self.data)
...         if message is not None:
...             self._notify(message)

>>> data = vbt.BinanceData.pull(
...     "BTCUSDT", timeframe="1h", start="2024-11-24", end="2024-12-01 00:01"
... )
>>> updater = AlertUpdater(data, notify=print)
>>> for hour in pd.date_range("2024-12-01 01:00", periods=7 * 24, freq="h", tz="UTC"):
...     updater.update(end=hour + pd.Timedelta(minutes=1))  # (3)
2024-12-01 20:00 BTCUSDT 20h MA crossed above 50h MA at 97,100
2024-12-02 12:00 BTCUSDT 20h MA crossed below 50h MA at 94,972
2024-12-04 07:00 BTCUSDT 20h MA crossed above 50h MA at 96,589
2024-12-06 09:00 BTCUSDT 20h MA crossed below 50h MA at 98,000
2024-12-07 07:00 BTCUSDT 20h MA crossed above 50h MA at 99,405
```

1.  One minute after the hour, the newest bar has just opened and is still forming, so the check uses
    the bar that just closed. The time in each message is when that bar opened.
2.  Fetches from the latest stored bar, refreshes that bar, and appends any newer bars.
3.  Replays a week as if the job ran at one minute past every hour. A live run leaves out `end`.

Five crossovers fired in that week. Each update fetched only the newest bars from Binance, so the
same object can run for months without downloading the history again. To run it live, send the
messages through a Telegram bot instead of `print` and let the scheduler call `update`:

```python title="Run the same job every hour and send alerts to Telegram"
>>> bot = vbt.TelegramBot(token="YOUR_BOT_TOKEN")  # (1)
>>> bot.start(in_background=True)

>>> updater = AlertUpdater(data, notify=bot.send_message_to_all)  # (2)
>>> updater.update_every("hour", "01:00")  # (3)
```

1.  Requires the optional `python-telegram-bot` package and a token from Telegram's BotFather.
2.  Sends each alert to every chat that has sent `/start` to the bot.
3.  Runs at one minute past every hour until the process stops or `update` raises
    `vbt.CancelledError`.

## Choose a recurring workflow \[#choose-a-recurring-workflow]

The same tools can run a data feed, a batch of backtests, or a regular report. Your Python function
defines the work, and VBT handles when it runs and how repeated calls are collected:

| What you want to automate                                | Tools to use                                                                      |
| -------------------------------------------------------- | --------------------------------------------------------------------------------- |
| Refresh prices and check the latest signal               | `DataUpdater` with a scheduled update and your own signal function.               |
| Keep market data on disk as new bars arrive              | A data saver with scheduled updates.                                              |
| Repeat research across symbols, dates, or configurations | `Task`, `execute`, or the `iterated` decorator.                                   |
| Run a daily analysis and save the result                 | `ScheduleManager` calling a function that builds and saves your research objects. |

## Scheduling \[#scheduling]

`vbt.ScheduleManager` runs any function on a schedule, with the interval, unit, weekday, and time in
plain words, such as `every(10, "minutes")`, `every("hour", "01:00")`, or
`every("monday", "09:30")`. Jobs run in a blocking loop or as an asyncio task in the background,
which keeps a notebook usable while they run. Tags group jobs so they can be replaced or removed
together. `vbt.DataUpdater` and the data savers on the
[Data storage](/features/data/data-storage-and-databases/) page use the same scheduler, so updating
a dataset, saving it to disk, and checking signals can share one job.

Run the blocking scheduler in a Python process for an unattended job, or use `start_in_background`
in a notebook with an active event loop and stop it with `stop`. The process or notebook session
keeps the schedule running. For intervals aligned to clock boundaries, `zero_offset=True` can align
recurring jobs, such as checks every ten minutes.

A scheduled function can also rebuild indicators, run a parameter search, and save the resulting
portfolios for later inspection.
[Configuration and persistence](/features/tooling/configuration-and-persistence/) shows how to keep
inputs, settings, and results together between runs.

## Tasks and iteration \[#tasks-and-iteration]

`vbt.Task` packages a function with its arguments without running it, and `vbt.execute` runs a list
of tasks one after another, in threads, or in processes, with a progress bar. `@vbt.iterated` turns
a loop over one argument into a parallel run with labeled results, as the
[Iterated decorator](#iterated-decorator) and [Tasks](#tasks) highlights below show. For
reproducible random runs, `vbt.set_seed` seeds Python, NumPy, and Numba. Give independent randomized
tasks their own explicit seeds so the experiment records which random inputs each task used.

Use tasks for separate experiments that do not depend on each other's results. Use an iterated
function when the same calculation repeats over symbols, time periods, or another argument. The
execution and result-merging choices let you keep that calculation as an ordinary Python function.
[Parallel execution and caching](/features/performance/parallel-execution-and-caching/) covers the
available engines and ways to reuse completed work.

### Chain the steps of a job \[#chain-the-steps-of-a-job]

Data objects also support `pipe` and `chain` for steps that depend on earlier outputs. A sequence
can pull data, select symbols, add indicators, and pass the result to your own function. This keeps
the data preparation you use interactively available to the same scheduled job. The
[Data pipelines](/features/data/financial-data-pipelines/) page covers the preparation side.

## Progress \[#progress]

Long VBT operations, such as data downloads, parameter sweeps, and task execution, show a progress
bar once they run longer than two seconds, and it can be turned off or customized. Bars nest, so a
loop over symbols, then parameters, then splits shows one line per level, as the
[Nested progress bars](#nested-progress-bars) highlight below shows. Bars drawn from inside parallel
workers interfere with each other, so pass `show_progress=False` to VBT calls that run inside
workers, such as when another library parallelizes them.

## Command-line workflows \[#command-line-workflows]

The `vbt` command runs in a terminal without a Python script. It can ask VBT's documentation
assistant a question, search its knowledge base, and start or call the MCP server, as the
[CLI](#cli) highlight below shows.

## Notifications \[#notifications]

`vbt.TelegramBot` connects to Telegram through `python-telegram-bot`. Besides sending messages, it
can answer commands you define, so a chat can ask the bot for the latest price or a portfolio
summary. `send_giphy` attaches a GIF found by text through GIPHY. The CCXT and Polygon data classes
retry requests that fail with network errors, and the TradingView class retries responses it cannot
parse. These retries can recover from temporary failures before the configured attempts are
exhausted. Custom HTTP integrations can use `requests_retry_session` to set retry counts, backoff,
and retryable status codes.

Alerts can report completed research as well as trading signals. Use your job's results to send a
short summary, or define a bot command that reads a saved portfolio when you ask for it. The
[Live simulation](/features/backtesting/live-simulation/) page shows how a portfolio can continue as
new data arrives.

## CLI \[#cli]

New in v2026.4.7

✅ VBT now ships with a [Typer](https://typer.tiangolo.com/)-based command-line interface that lets
you chat, search, and invoke MCP tools directly from the terminal. No Python script required. After
installing the package, you can run the `vbt` command in your terminal to see all available
commands.

=== "Chat"
    ```bash title="Ask VBT a question from the terminal"
    vbt chat "How to backtest a weekly rebalancing strategy?"  # (1)
    ```

    1.  Searches the documentation for relevant passages and uses a language model to answer, just like
        `vbt.chat()`.

=== "Quick chat"
    ```bash title="Ask VBT a quick question from the terminal"
    vbt quick-chat "What does size_type='target_percent' do?"  # (1)
    ```

    1.  Uses a faster answer model and BM25 keyword search. The search runs locally without preparing
        embeddings first.

=== "Interact"
    ```bash title="Ask VBT a question from the terminal with function calling enabled"
    vbt interact "Plot the equity curve for a 10/30 SMA crossover on BTC-USD"  # (1)
    ```

    1.  Wraps `vbt.interact()`, which enables function calling so the model can invoke MCP tools, run
        code, and return results.

=== "MCP"
    ```bash title="Start the MCP server or invoke a registered tool directly from the terminal"
    vbt mcp serve  # (1)

    vbt mcp search "ValueError: group_by must form monolithic, sorted groups"  # (2)

    vbt mcp search --call '{"kwargs": {"query": "ValueError: group_by must form monolithic, sorted groups"}}'  # (3)
    ```

    1.  Launch the MCP server for use with external clients.
    2.  Invoke any registered MCP tool directly from the command line without starting the server.
    3.  Pass any arguments to the tool using the `--call` option. The value should be a JSON string.

!!! info
    The first time you run most of these commands, it may take a while to prepare documents. However,
    most of the preparation steps are cached and stored, so future calls will be much faster and will
    not require repeating the process.

## Iterated decorator \[#iterated-decorator]

New in v2024.6.19

✅ Thinking about parallelizing a for-loop? VBT has a decorator for that.

```python title="Emulate a parallelized nested loop to get Sharpe by year and month"
>>> import calendar

>>> data = vbt.YFData.pull("BTC-USD")

>>> @vbt.iterated(over_arg="year", merge_func="column_stack", engine="pathos")  # (1)
... @vbt.iterated(over_arg="month", merge_func="concat")  # (2)
... def get_year_month_sharpe(data, year, month):  # (3)
...     mask = (data.index.year == year) & (data.index.month == month)
...     if not mask.any():
...         return np.nan
...     year_returns = data.loc[mask].returns
...     return year_returns.vbt.returns.sharpe_ratio()

>>> years = data.index.year.unique().sort_values().rename("year")
>>> months = data.index.month.unique().sort_values().rename("month")
>>> sharpe_matrix = get_year_month_sharpe(
...     data,
...     years,
...     {calendar.month_abbr[month]: month for month in months},  # (4)
... )
>>> sharpe_matrix.transpose().vbt.heatmap(
...     trace_kwargs=dict(colorscale="RdBu", zmid=0),
...     yaxis=dict(autorange="reversed")
... ).show()
```

1.  Iterate over years (in parallel).
2.  Iterate over months (sequentially).
3.  The function is called for each combination of year and month.
4.  Map month numbers to names and pass them as a dict. VBT will extract the keys and use them as
    labels.

Monthly Sharpe ratio heatmap for Bitcoin grouped by year. [Figure data (JSON)](/assets/figures/features/productivity/iterated-decorator.a87ce0622201.json)

## Tasks \[#tasks]

New in v2024.6.19

✅ Testing multiple parameter combinations usually involves using the `@vbt.parameterized` decorator.
But what if you want to test entirely uncorrelated configurations or even different functions? The
latest addition to VBT lets you execute any sequence of unrelated tests in parallel by assigning
each test to a task.

```python title="Simulate SL, TSL, and TP parameters in three separate processes and compare their expectancy"
>>> data = vbt.YFData.pull("BTC-USD")

>>> task1 = vbt.Task(  # (1)
...     vbt.PF.from_random_signals,
...     data,
...     n=100, seed=42,
...     sl_stop=vbt.Param(np.arange(1, 51) / 100)
... )
>>> task2 = vbt.Task(
...     vbt.PF.from_random_signals,
...     data,
...     n=100, seed=42,
...     tsl_stop=vbt.Param(np.arange(1, 51) / 100)
... )
>>> task3 = vbt.Task(
...     vbt.PF.from_random_signals,
...     data,
...     n=100, seed=42,
...     tp_stop=vbt.Param(np.arange(1, 51) / 100)
... )
>>> pf1, pf2, pf3 = vbt.execute([task1, task2, task3], engine="pathos")  # (2)

>>> fig = pf1.trades.expectancy.rename("SL").vbt.plot()
>>> pf2.trades.expectancy.rename("TSL").vbt.plot(fig=fig)
>>> pf3.trades.expectancy.rename("TP").vbt.plot(fig=fig)
>>> fig.show()
```

1.  A task consists of a function and the arguments you want to pass to that function. Just creating
    a task does not execute the function!
2.  Execute all three tasks using multiprocessing.

Expectancy across stop-loss, trailing stop-loss, and take-profit levels. [Figure data (JSON)](/assets/figures/features/productivity/tasks.f161dc45cfc4.json)

## Nested progress bars \[#nested-progress-bars]

New in v2024.5.15

✅ Progress bars are now aware of each other. When a new progress bar starts, it checks whether
another progress bar with the same identifier has already finished its task. If so, the new progress
bar will close itself and delegate its progress to the existing one.

```python title="Display progress of three parameters using nested progress bars"
>>> symbols = ["BTC-USD", "ETH-USD"]
>>> fast_windows = range(5, 105, 5)
>>> slow_windows = range(5, 105, 5)
>>> sharpe_ratios = dict()

>>> with vbt.ProgressBar(total=len(symbols), bar_id="pbar1") as pbar1:  # (1)
...     for symbol in symbols:
...         pbar1.set_description(dict(symbol=symbol), refresh=True)
...         data = vbt.YFData.pull(symbol)
...
...         with vbt.ProgressBar(total=len(fast_windows), bar_id="pbar2") as pbar2:  # (2)
...             for fast_window in fast_windows:
...                 pbar2.set_description(dict(fast_window=fast_window), refresh=True)
...
...                 with vbt.ProgressBar(total=len(slow_windows), bar_id="pbar3") as pbar3:  # (3)
...                     for slow_window in slow_windows:
...                         if fast_window < slow_window:
...                             pbar3.set_description(dict(slow_window=slow_window), refresh=True)
...                             fast_sma = data.run("talib_func:sma", fast_window)
...                             slow_sma = data.run("talib_func:sma", slow_window)
...                             entries = fast_sma.vbt.crossed_above(slow_sma)
...                             exits = fast_sma.vbt.crossed_below(slow_sma)
...                             pf = vbt.PF.from_signals(data, entries, exits)
...                             sharpe_ratios[(symbol, fast_window, slow_window)] = pf.sharpe_ratio
...                         pbar3.update()
...
...                 pbar2.update()
...
...         pbar1.update()
```

1.  Track iteration over symbols.
2.  Track iteration over fast windows.
3.  Track iteration over slow windows.

Symbol 2/2: 100%

Fast window 20/20: 100%

Slow window 20/20: 100%

```python
>>> sharpe_ratios = pd.Series(sharpe_ratios)
>>> sharpe_ratios.index.names = ["symbol", "fast_window", "slow_window"]
>>> sharpe_ratios
symbol   fast_window  slow_window
BTC-USD  5            10             1.063616
                      15             1.218345
                      20             1.273154
                      25             1.365664
                      30             1.394469
                                          ...
ETH-USD  80           90             0.582995
                      95             0.617568
         85           90             0.701215
                      95             0.616037
         90           95             0.566650
Length: 342, dtype: float64
```


## Related pages

*   [Parallel execution and caching](/features/performance/parallel-execution-and-caching/): Chunk work across threads, processes, or Ray, cache results, and keep memory bounded
*   [Parameter optimization](/features/optimization/strategy-optimization/): Sweep millions of parameter combinations with grids, conditions, and random search
*   [Backtesting engine](/features/backtesting/backtesting-engine/): Simulate orders, signals, and callbacks across many assets and parameters at once
*   [Developer tools](/features/tooling/developer-tools/): Search the API, read source, draw reference graphs, and extend classes with factories