polakowo /vectorbt
The research engine that gives you an unfair advantage. Run thousands of trading ideas before others finish one.
★ 9,858⑂ 1,310👁 136⑃ 130● 498▤ 8
+13
日增长
9,858
stars
1,310
forks
136
watchers
130
prs
498
issues
8
releases
README
简体中文 / English |
功能 ·
安装 ·
示例 ·
链接
让交易研究规模化。
VectorBT 是面向交易研究的 Python 工具库。探索市场数据,构建指标和信号,跨资产、跨时间周期比较数千种交易思路。借助 NumPy 数组、Numba 加速和可选的 Rust 引擎,只需几行 Python 代码即可开展大规模实验。
---
在同一工作流中,从探索价格形态到评估交易策略。查看交易、费用、回撤和投资组合表现,并通过交互式图表分析结果。VectorBT 面向交易者、研究人员和 AI 智能体,通过可组合的 Python API 将数据分析、策略模拟和可视化整合在一起。
VectorBT 是 VectorBT PRO 的开源社区版。
PRO 在此基础上提供并行计算、更多数据集成、投资组合优化、形态识别、事件预测、限价单、杠杆等功能,
以及其他 100 多项功能,并且每周持续新增功能。
查看 VectorBT 与 PRO 的对比,或浏览
PRO 功能示例。
功能
高速向量化回测
基于 pandas、NumPy 和 Numba,开展大规模策略研究。
回测示例 →
可选的 Rust 引擎
为支持的运算提供预编译内核,无需承担 JIT 编译开销。
Rust 引擎 →
原生集成 pandas 的 API
通过自定义访问器,直接对 pandas 对象执行高性能运算。
pandas 集成 →
灵活的广播机制
利用灵活的数组广播,开展多资产分析和大规模参数扫描。
广播 API →
丰富的指标生态
构建自定义指标,并使用 TA-Lib、Pandas TA 等工具集成。
指标功能 →
投资组合回测
分析交易、回撤和绩效,并集成 QuantStats。
投资组合分析 →
信号工具
生成、排序和映射交易信号,并分析其分布。
信号功能 →
内置数据获取功能
获取市场数据、执行预处理,并生成合成时间序列。
数据功能 →
稳健性测试
运行滚动优化,并为机器学习工作流生成标签。
稳健性测试 →
交互式可视化
通过 Plotly 图表、Jupyter 小部件和浏览器仪表板探索结果。
绘图功能 →
自动化工具
定时更新数据,并发送 Telegram 通知。
定时任务与通知 →
可组合的 Python API
组合功能模块,支持快速实验和由 AI 智能体驱动的工作流。
Python 工作流 →
安装
sh
pip install -U vectorbt
安装可选的 Rust 引擎:
sh
pip install -U "vectorbt[rust]"
安装所有可选集成(TA-Lib、Pandas TA 等):
sh
pip install -U "vectorbt[full]"
同时安装所有可选集成和 Rust 引擎:
sh
pip install -U "vectorbt[full,rust]"
示例
从 2014 年起向比特币投资 100 美元
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())
输出:
text
19501.10906763755
交易双简单移动平均线(SMA)交叉策略
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())
输出:
text
34417.80960086067
[!TIP]
VectorBT PRO
模拟限价单,
使用杠杆,并通过
合约乘数进行期货建模。
生成 1,000 个随机策略
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()
输出:
测试 10,000 种双 SMA 窗口组合
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 =Top issues
#156How to access algorithm time for intraday strategies?15 comments · 2021-05-30#243please clarify dividends, reinvestment, recurring investment12 comments · 2021-09-22#748VectorBT - Telegram - Issue: ImportError: cannot import Unauthorized, ChatMigrated10 comments · 2024-09-19#788Download Data Has Problem9 comments · 2025-04-30#398vbt.BinanceData.download do not accept klines_type parameter8 comments · 2022-03-01#802Calculation of profit factor6 comments · 2025-08-03#426multiple entry signals6 comments · 2022-03-29#539Calculation of Stop price5 comments · 2022-12-09
Discussions
#867We built 19 Borsa Istanbul research systems but still cannot prove a real trading edge — what are we missing?1 comments · 2026-07-29#866Deflating the Sharpe after a grid search (the winner is a max over N)1 comments · 2026-07-25#863📈 BDE Score — 开源多因子 API,跨市场评分 + GitHub Action badge0 comments · 2026-07-10#851AI options flow signals as vectorbt features — open source Claude Code investment skills0 comments · 2026-05-13#848Long/Short signals fire independent of shortonly direction?1 comments · 2026-05-01#842FinancialData.Net adapter for vectorbt (daily and intraday data)0 comments · 2026-04-10#830Only profitable exits ?1 comments · 2026-03-05#823Backtesting Is Easy. Execution Is the Hard Part.0 comments · 2026-01-05
Latest release
v1.2.1 v1.2.1 2026-11-11What's Changed test(generic): support pandas 3.1 timedelta expectations by @JohnDReynolds in https://github.com/polakowo/vectorbt/pull/895 fix(indicators): select unmapped input columns by @JohnDReynolds in https://github.com/polakowo/vectorbt/pull/889 fix(data): initialize download kwargs in from_data by @JohnDReynolds in https://github.com/polakowo/vectorbt/pull/890 fix(utils): preserve dictionary state on rejected loads by @JohnDReynolds in https://github.com/polakowo/vectorbt/pull/891 fix(records): pass group_by to top_n and bottom_n masks by @wavebyrd in https://github.com/polak