项目 / polakowo/vectorbt

polakowo/vectorbt

行业推荐
语言 Python标签 backtestingtradingalgorithmic-tradingtrading-strategiescryptocurrencydata-visualizationtime-seriesdata-sciencefinancemachine-learningportfolio-optimizationquantitative-financequantitative-analysisalgorithmic-traiding数据更新 2026-11-25 06:49:28 · 仓库 2026-11-24

一段话介绍

The research engine that gives you an unfair advantage. Run thousands of trading ideas before others finish one.

本站整理,非 GitHub 官方 description。

官方 description(GitHub API 原样)
The research engine that gives you an unfair advantage. Run thousands of trading ideas before others finish one.
9,925累计星
1,326Fork
—峰值日增
0上榜次数
总榜
暂未入榜
日榜
暂未入榜
周榜
暂未入榜
月榜
暂未入榜

官方快照(gh_history.db,2026-11-25):总榜 未进 Top50 · 日榜 未进 Top50 · 周榜未满 7 天基线(官方不生成) · 月榜暂无官方口径;下方四卡为站内趋势聚合(周卡按上榜次数,非官方 7 日增量窗)。

行业与场景

按行业选型 →

量化研究与策略回测

适配系统:量化投研平台、行情终端 · 得分 4.2

内置行情接入、因子计算与回测框架,可作为投研团队的策略实验与绩效归因底座。

BI 可视化与自助分析

适配系统:BI/报表平台、自助分析平台 · 得分 1.2

提供图表渲染与自助取数能力,可作为业务看板与经营管理分析的展示层。

更多信息

以下三段按该项目自己的 GitHub README 章节摘录(可合理截断并标明);README 没有对应章节的留空,不编造。

我的用法
vectorbt 可选装 Rust 引擎及 TA-Lib、Pandas TA 等集成,能用 YFData 下载行情数据,并通过 from_holding、from_signals 或随机信号快速回测并输出总利润等指标。
局限和适用边界
vectorbt 仅供学习用途,作者不承担交易结果责任,用户需自行承担使用风险,不要投入无法承受损失的资金。
星标走势还差一天的数据,明天就能看到曲线
每天 10:30 记一次星标,连续两天后自动生成曲线
首次发现 — · 最近在榜 2026-11-11 · 语言 Python · 贡献者 —
rag

GitHub 项目主页介绍

来自 GitHub 仓库 README / 主页介绍正文,原样摘录,共 17,538 字节。

<div align="center">
    <a href="https://vectorbt.pro/" title="VectorBT PRO">
        <img src="https://raw.githubusercontent.com/polakowo/vectorbt/master/docs/docs/assets/logo/header-pro.svg" />
    </a>
</div>
<div align="center">
    <a href="https://vectorbt.dev/" title="vectorbt">
        <img src="https://raw.githubusercontent.com/polakowo/vectorbt/master/docs/docs/assets/logo/header.svg" />
    </a>
</div>

<br>

<p align="center">
    <a href="https://pepy.tech/project/vectorbt" title="Downloads">
        <img src="https://img.shields.io/pepy/dt/vectorbt?label=downloads&color=blue" />
    </a>
    <a href="https://pypi.org/project/vectorbt" title="PyPI">
        <img src="https://img.shields.io/pypi/v/vectorbt" />
    </a>
    <a href="https://pypi.org/project/vectorbt" title="Supported Python versions">
        <img src="https://img.shields.io/pypi/pyversions/vectorbt" />
    </a>
    <a href="https://hub.docker.com/r/polakowo/vectorbt" title="Docker image version">
        <img src="https://img.shields.io/docker/v/polakowo/vectorbt?sort=semver&label=docker&color=2496ed&logo=docker&logoColor=white" />
    </a>
    <a href="https://hub.docker.com/r/polakowo/vectorbt" title="Docker pulls">
        <img src="https://img.shields.io/docker/pulls/polakowo/vectorbt?label=docker%20pulls&color=2496ed&logo=docker&logoColor=white" />
    </a>
    <a href="https://github.com/polakowo/vectorbt/actions/workflows/tests.yml" title="Tests">
        <img src="https://img.shields.io/github/actions/workflow/status/polakowo/vectorbt/tests.yml?branch=master&label=tests&logo=githubactions&logoColor=white" />
    </a>
    <a href="https://github.com/polakowo/vectorbt/actions/workflows/pypi.yml" title="PyPI release">
        <img src="https://img.shields.io/github/actions/workflow/status/polakowo/vectorbt/pypi.yml?label=release&logo=githubactions&logoColor=white" />
    </a>
    <a href="https://vectorbt.dev/" title="Website">
        <img src="https://img.shields.io/website?url=https%3A%2F%2Fvectorbt.dev%2F&label=website" />
    </a>
    <a href="https://pypi.org/project/vectorbt-rust" title="Rust engine">
        <img src="https://img.shields.io/pypi/v/vectorbt-rust?label=rust%20engine&color=dea584&logo=rust" />
    </a>
    <a href="https://github.com/polakowo/vectorbt/blob/master/LICENSE.md" title="License">
        <img src="https://img.shields.io/badge/license-Fair%20Code-yellow" />
    </a>
</p>

<p align="center">
    <a href="https://github.com/polakowo/vectorbt/blob/master/README.zh-CN.md">简体中文</a> / <b>English</b> |
    <a href="#features">Features</a> ·
    <a href="#installation">Installation</a> ·
    <a href="#examples">Examples</a> ·
    <a href="#links">Links</a>
</p>

<h2 align="center">Trading research at scale.</h2>

<p align="center">VectorBT is a Python toolkit for trading research. Explore market data, build indicators and signals, and compare thousands of ideas across assets and timeframes. NumPy arrays, Numba acceleration, and an optional Rust engine let you run large experiments in a few lines of Python.</p>

---

Move from exploring price patterns to evaluating strategies in one workflow. Inspect trades, fees, drawdowns, and portfolio performance, then explore the results with interactive charts. Built for traders, researchers, and AI agents, VectorBT brings data analysis, strategy simulation, and visualization together in a composable Python API.

VectorBT is the open-source community edition of [VectorBT PRO](https://vectorbt.pro/).
PRO extends the library with parallelization, additional data integrations, portfolio optimization,
pattern recognition, event projections, limit orders, leverage, and over 100 other features,
with new features added weekly.

See [VectorBT vs PRO](https://vectorbt.dev/getting-started/upgrade/) or browse
[PRO feature examples](https://vectorbt.pro/features/).

## Features

<table>
  <tr>
    <td width="50%" valign="top">
      <h3>Fast, vectorized backtesting</h3>
      <p>Research strategies at scale with pandas, NumPy, and Numba.</p>
      <p><a href="https://vectorbt.dev/getting-started/features/#fast-vectorized-backtesting">Backtesting examples →</a></p>
    </td>
    <td width="50%" valign="top">
      <h3>Optional Rust engine</h3>
      <p>Use precompiled kernels for supported operations without JIT compilation.</p>
      <p><a href="https://vectorbt.dev/getting-started/features/#optional-rust-engine">Rust engine →</a></p>
    </td>
  </tr>
  <tr>
    <td width="50%" valign="top">
      <h3>Pandas-native API</h3>
      <p>Work with custom accessors and high-performance operations directly on pandas objects.</p>
      <p><a href="https://vectorbt.dev/getting-started/features/#pandas-native-api">Pandas integration →</a></p>
    </td>
    <td width="50%" valign="top">
      <h3>Flexible broadcasting</h3>
      <p>Analyze multiple assets and sweep large parameter grids with flexible array broadcasting.</p>
      <p><a href="https://vectorbt.dev/getting-started/features/#flexible-broadcasting">Broadcasting API →</a></p>
    </td>
  </tr>
  <tr>
    <td width="50%" valign="top">
      <h3>Rich indicator ecosystem</h3>
      <p>Build custom indicators and use integrations for TA-Lib, Pandas TA, and more.</p>
      <p><a href="https://vectorbt.dev/getting-started/features/#rich-indicator-ecosystem">Indicator features →</a></p>
    </td>
    <td width="50%" valign="top">
      <h3>Portfolio backtesting</h3>
      <p>Analyze trades, drawdowns, and performance, with QuantStats integration.</p>
      <p><a href="https://vectorbt.dev/getting-started/features/#portfolio-backtesting">Portfolio analysis →</a></p>
    </td>
  </tr>
  <tr>
    <td width="50%" valign="top">
      <h3>Signal tooling</h3>
      <p>Generate, rank, map, and analyze the distribution of trading signals.</p>
      <p><a href="https://vectorbt.dev/getting-started/features/#signal-tooling">Signal features →</a></p>
    </td>
    <td width="50%" valign="top">
      <h3>Built-in data access</h3>
      <p>Fetch market data, preprocess it, and generate synthetic time series.</p>
      <p><a href="https://vectorbt.dev/getting-started/features/#built-in-data-access">Data features →</a></p>
    </td>
  </tr>
  <tr>
    <td width="50%" valign="top">
      <h3>Robustness testing</h3>
      <p>Run walk-forward optimization and generate labels for machine learning workflows.</p>
      <p><a href="https://vectorbt.dev/getting-started/features/#robustness-testing">Robustness testing →</a></p>
    </td>
    <td width="50%" valign="top">
      <h3>Interactive visualization</h3>
      <p>Explore results with Plotly charts, Jupyter widgets, and browser dashboards.</p>
      <p><a href="https://vectorbt.dev/getting-started/features/#interactive-visualization">Plotting features →</a></p>
    </td>
  </tr>
  <tr>
    <td width="50%" valign="top">
      <h3>Automation tools</h3>
      <p>Schedule data updates and send Telegram notifications.</p>
      <p><a href="https://vectorbt.dev/getting-started/features/#automation-tools">Scheduling and notifications →</a></p>
    </td>
    <td width="50%" valign="top">
      <h3>Composable Python API</h3>
      <p>Combine building blocks for rapid experimentation and AI agent-driven workflows.</p>
      <p><a href="https://vectorbt.dev/getting-started/features/#composable-python-api">Python workflows →</a></p>
    </td>
  </tr>
</table>

## Installation

```sh
pip install -U vectorbt
```

To install the optional Rust engine:

```sh
pip install -U "vectorbt[rust]"
```

To install all optional integrations (TA-Lib, Pandas TA, etc.):

```sh
pip install -U "vectorbt[full]"
```

To install all optional integrations together with the Rust engine:

```sh
pip install -U "vectorbt[full,rust]"
```

## Examples

### Invest $100 in Bitcoin since 2014

```python
import vectorbt as vbt

data = vbt.YFData.download("BTC-USD")
price = data.get("Close")

pf = vbt.Portfolio.from_holding(price, init_cash=100)
print(pf.total_profit())
```

Output:

```text
19501.10906763755
```

### Trade a dual-SMA crossover strategy

```python
fast_ma = vbt.MA.run(price, 10)
slow_ma = vbt.MA.run(price, 50)
entries = fast_ma.ma_crossed_above(slow_ma)
exits = fast_ma.ma_crossed_below(slow_ma)

pf = vbt.Portfolio.from_signals(price, entries, exits, init_cash=100)
print(pf.total_profit())
```

Output:

```text
34417.80960086067
```

> [!TIP]
> **VectorBT PRO**
>
> Simulate [limit orders](https://vectorbt.pro/features/backtesting/orders-and-execution/#limit-orders),
> use [leverage](https://vectorbt.pro/features/backtesting/fees-slippage-and-leverage/#leverage), and model futures with
> [contract multipliers](https://vectorbt.pro/features/backtesting/fees-slippage-and-leverage/#contract-multiplier).

### Generate 1,000 random strategies

```python
import numpy as np

symbols = ["BTC-USD", "ETH-USD"]
data = vbt.YFData.download(symbols, missing_index="drop")
price = data.get("Close")

n = np.random.randint(10, 101, size=1000).tolist()
pf = vbt.Portfolio.from_random_signals(price, n=n, init_cash=100, seed=42)

mean_expectancy = pf.trades.expectancy().groupby(["randnx_n", "symbol"]).mean()
fig = mean_expectancy.unstack().vbt.scatterplot(xaxis_title="randnx_n", yaxis_title="mean_expectancy")
fig.show()
```

Output:

<img width="750" src="https://raw.githubusercontent.com/polakowo/vectorbt/master/docs/docs/assets/images/usage_rand_scatter.svg" alt="Random-strategy mean trade expectancy" />

### Test 10,000 dual-SMA window combinations

```python
symbols = ["BTC-USD", "ETH-USD", "XRP-USD"]
data = vbt.YFData.download(symbols, missing_index="drop")
price = data.get("Close")

windows = np.arange(2, 101)
fast_ma, slow_ma = vbt.MA.run_combs(price, window=windows, r=2, short_names=["fast", "slow"])
entries = fast_ma.ma_crossed_above(slow_ma)
exits = fast_ma.ma_crossed_below(slow_ma)

pf = vbt.Portfolio.from_signals(price, entries, exits, size=np.inf, fees=0.001, freq="1D")

fig = pf.total_return().vbt.heatmap(
    x_level="fast_window",
    y_level="slow_window",
    slider_level="symbol",
    symmetric=True,
    trace_kwargs=dict(colorbar=dict(title="Total return", tickformat="%")),
)
fig.show()
```

Output:

<img width="750" src="https://raw.githubusercontent.com/polakowo/vectorbt/master/docs/docs/assets/images/usage_dmac_heatmap.gif" alt="Dual-SMA window combinations across assets" />

> [!TIP]
> **VectorBT PRO**
>
> Use [random search](https://vectorbt.pro/features/optimization/strategy-optimization/#random-search) to sample a large
> parameter grid, or [conditional parameters](https://vectorbt.pro/features/optimization/strategy-optimization/#conditional-parameters)
> to exclude combinations such as a fast MA window longer than the slow MA window. The
> [cross-validation tutorial](https://vectorbt.pro/tutorials/cross-validation/)
> shows how to select parameters on training data and evaluate them on later periods.

### Inspect any strategy configuration

```python
print(pf[(10, 20, "ETH-USD")].stats())
```

Output:

```text
Start                          2017-11-09 00:00:00+00:00
End                            2026-01-03 00:00:00+00:00
Period                                2978 days 00:00:00
Start Value                                        100.0
End Value                                    1604.093789
Total Return [%]                             1504.093789
Benchmark Return [%]                          866.094127
Max Gross Exposure [%]                             100.0
Total Fees Paid                               204.226289
Max Drawdown [%]                               70.734951
Max Drawdown Duration                 1095 days 00:00:00
Total Trades                                          81
Total Closed Trades                                   80
Total Open Trades                                      1
Open Trade PnL                                -14.232533
Win Rate [%]                                       41.25
Best Trade [%]                                120.511071
Worst Trade [%]                               -27.772271
Avg Winning Trade [%]                          27.265519
Avg Losing Trade [%]                           -9.022864
Avg Winning Trade Duration    32 days 20:21:49.090909091
Avg Losing Trade Duration      8 days 16:51:03.829787234
Profit Factor                                   1.275515
Expectancy                                     18.979079
Sharpe Ratio                                    0.861945
Calmar Ratio                                    0.572758
Omega Ratio                                      1.20277
Sortino Ratio                                   1.301377
Name: (10, 20, ETH-USD), dtype: object
```

### Plot any strategy configuration

```python
pf[(10, 20, "ETH-USD")].plot().show()
```

Output:

<img width="750" src="https://raw.githubusercontent.com/polakowo/vectorbt/master/docs/docs/assets/images/readme-portfolio.gif" alt="Inspecting trades, zooming, and toggling the portfolio benchmark" />

### Animate Bollinger Bands across multiple symbols

VectorBT goes beyond backtesting, with tools for financial data analysis and visualization:

```python
symbols = ["BTC-USD", "ETH-USD", "XRP-USD"]
data = vbt.YFData.download(symbols, period="6mo", missing_index="drop")
price = data.get("Close")
bbands = vbt.BBANDS.run(price)


def plot(index, bbands):
    bbands = bbands.loc[index]
    fig = vbt.make_subplots(
        rows=2, cols=1, shared_xaxes=True, vertical_spacing=0.15, subplot_titles=("%B", "Bandwidth")
    )
    fig.update_layout(showlegend=False, width=750, height=400)
    bbands.percent_b.vbt.ts_heatmap(
        trace_kwargs=dict(
            zmin=0,
            zmid=0.5,
            zmax=1,
            colorscale="Spectral",
            colorbar=dict(y=(fig.layout.yaxis.domain[0] + fig.layout.yaxis.domain[1]) / 2, len=0.5),
        ),
        add_trace_kwargs=dict(row=1, col=1),
        fig=fig,
    )
    bbands.bandwidth.vbt.ts_heatmap(
        trace_kwargs=dict(colorbar=dict(y=(fig.layout.yaxis2.domain[0] + fig.layout.yaxis2.domain[1]) / 2, len=0.5)),
        add_trace_kwargs=dict(row=2, col=1),
        fig=fig,
    )
    return fig


vbt.save_animation(
    "bbands.gif", bbands.wrapper.index, plot, bbands, delta=90, step=3, fps=3, writer_kwargs=dict(loop=0)
)
```

Output:

```text
100%|██████████| 31/31 [00:21<00:00,  1.21it/s]
```

<img width="750" src="https://raw.githubusercontent.com/polakowo/vectorbt/master/docs/docs/assets/images/usage_bbands.gif" alt="Rolling Bollinger Bands percent-B and bandwidth heatmaps" />

Visit the [website](https://vectorbt.dev/) for more examples, documentation, and guides.

## Example apps

### [Candlestick Patterns](https://github.com/polakowo/vectorbt/blob/master/apps/candlestick-patterns/)

Explore candlestick patterns interactively and backtest their signals with VectorBT.

<img width="900" src="https://raw.githubusercontent.com/polakowo/vectorbt/master/docs/docs/assets/images/readme-candlestick.gif" alt="Exploring candlestick patterns, inspecting trades, and comparing strategy statistics in the app" />

## Links

* [Website](https://vectorbt.dev/)
* [Docker images](https://hub.docker.com/r/polakowo/vectorbt)
* [Colab notebook](https://colab.research.google.com/drive/1ibqyrf6LPFlzRb6mkPpl3hxqL6ryNBXI?usp=sharing)

## License

This work is [fair-code](http://faircode.io/) distributed under the [Apache 2.0 with Commons Clause](https://github.com/polakowo/vectorbt/blob/master/LICENSE.md) license.

The source code is publicly available, and everyone (individuals and organizations) may use it for free. However, you may not sell products or services that are primarily this software.

If you have questions or want to request a license exception, please [contact the author](mailto:olegpolakow@vectorbt.pro).

Installing optional dependencies may be subject to a more restrictive license.

## Contributors

Thanks to everyone who has contributed to VectorBT!

<a href="https://github.com/polakowo/vectorbt/graphs/contributors">
  <img src="https://contrib.rocks/image?repo=polakowo/vectorbt" alt="VectorBT contributors" />
</a>

## Star History

<a href="https://www.star-history.com/?repos=polakowo%2Fvectorbt&type=timeline&legend=top-left">
 <picture>
   <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/chart?repos=polakowo/vectorbt&type=timeline&theme=dark&legend=top-left&sealed_token=482an5rek002Q4c3VCaRd7goV3LwR6GP6m56UOqTunBJKoEq19_RkbQldrL-OP4f5XnDtU9tOOTrs-NTtnqFoQoUZJdWPQEQ-eO2q1McxpYu-STLc1fj9tY60p-spkcSQ9bxs7WJkumrqYI1LSc3mBd7CIu2K7IuYNAgv1pYuFJOQaN1yD5p3wWNgcFM" />
   <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/chart?repos=polakowo/vectorbt&type=timeline&legend=top-left&sealed_token=482an5rek002Q4c3VCaRd7goV3LwR6GP6m56UOqTunBJKoEq19_RkbQldrL-OP4f5XnDtU9tOOTrs-NTtnqFoQoUZJdWPQEQ-eO2q1McxpYu-STLc1fj9tY60p-spkcSQ9bxs7WJkumrqYI1LSc3mBd7CIu2K7IuYNAgv1pYuFJOQaN1yD5p3wWNgcFM" />
   <img alt="Star History Chart" src="https://api.star-history.com/chart?repos=polakowo/vectorbt&type=timeline&legend=top-left&sealed_token=482an5rek002Q4c3VCaRd7goV3LwR6GP6m56UOqTunBJKoEq19_RkbQldrL-OP4f5XnDtU9tOOTrs-NTtnqFoQoUZJdWPQEQ-eO2q1McxpYu-STLc1fj9tY60p-spkcSQ9bxs7WJkumrqYI1LSc3mBd7CIu2K7IuYNAgv1pYuFJOQaN1yD5p3wWNgcFM" />
 </picture>
</a>

## Disclaimer

This software is for educational purposes only. Do not risk money you cannot afford to lose.

Use the software at your own risk. The authors and affiliates assume no responsibility for your trading results.
↑