{"id":7847,"library":"vectorbt","title":"VectorBT","description":"VectorBT is a Python library for backtesting and analyzing trading strategies at scale. It leverages NumPy and Numba for high-performance vectorized computations, enabling rapid testing of numerous strategy configurations and assets. The library integrates with pandas for data handling and Plotly for interactive visualizations. It is currently at version 0.28.5 and receives active development and maintenance.","status":"active","version":"0.28.5","language":"en","source_language":"en","source_url":"https://github.com/polakowo/vectorbt","tags":["finance","backtesting","trading","quant","pandas","numpy","numba","algorithmic-trading"],"install":[{"cmd":"pip install vectorbt","lang":"bash","label":"Core library"},{"cmd":"pip install \"vectorbt[full]\"","lang":"bash","label":"With optional dependencies (e.g., TA-Lib, Plotly)"}],"dependencies":[{"reason":"Required Python version.","package":"python","optional":false},{"reason":"Provides additional technical analysis indicators, included with '[full]' install.","package":"ta-lib","optional":true},{"reason":"Used for interactive charting and dashboards, included with '[full]' install.","package":"plotly","optional":true},{"reason":"Used for interactive charting and dashboards in Jupyter environments, included with '[full]' install.","package":"ipywidgets","optional":true}],"imports":[{"note":"Standard alias for the library.","symbol":"vbt","correct":"import vectorbt as vbt"},{"note":"Used for downloading historical data from Yahoo Finance.","symbol":"YFData","correct":"vbt.YFData"},{"note":"Core class for creating and analyzing trading portfolios from signals or orders.","symbol":"Portfolio","correct":"vbt.Portfolio"},{"note":"Provides moving average indicators.","symbol":"MA","correct":"vbt.MA"},{"note":"Provides Relative Strength Index indicator.","symbol":"RSI","correct":"vbt.RSI"}],"quickstart":{"code":"import vectorbt as vbt\nimport pandas as pd\n\n# Download historical daily price data for Bitcoin (BTC-USD)\n# Use a specific date range for reproducibility\nprice = vbt.YFData.download(\n    'BTC-USD',\n    start=pd.Timestamp('2020-01-01', tz='UTC'),\n    end=pd.Timestamp('2021-01-01', tz='UTC')\n).get('Close')\n\n# Simulate a simple buy-and-hold portfolio with $100 initial cash\npf = vbt.Portfolio.from_holding(price, init_cash=100)\n\n# Calculate total profit\nprofit = pf.total_profit()\nprint(f\"Total profit from buy-and-hold: ${profit:.2f}\")\n\n# Calculate a simple moving average crossover strategy\nfast_ma = vbt.MA.run(price, 10)\nslow_ma = vbt.MA.run(price, 50)\n\n# Generate entry and exit signals\nentries = fast_ma.ma_crossed_above(slow_ma)\nexits = slow_ma.ma_crossed_above(fast_ma)\n\n# Backtest the MA crossover strategy\npf_ma_crossover = vbt.Portfolio.from_signals(\n    price, entries, exits, init_cash=100, fees=0.001\n)\n\n# Print strategy statistics\nprint(\"\\nMA Crossover Strategy Statistics:\")\nprint(pf_ma_crossover.stats())","lang":"python","description":"This quickstart demonstrates how to download historical price data, simulate a basic buy-and-hold strategy, and then implement a simple moving average crossover strategy with entry/exit signals using `vectorbt`."},"warnings":[{"fix":"Upgrade to vectorbt version 0.28.5 or newer: `pip install --upgrade vectorbt`.","message":"Older versions of vectorbt (prior to 0.28.5) had compatibility issues with pandas 2.x, specifically an `AttributeError` when using `Styler.render()`. While fixed in 0.28.5, users on older `vectorbt` versions with pandas 2.x may encounter this.","severity":"gotcha","affected_versions":"<0.28.5"},{"fix":"Ensure you are using Python 3.10 or newer and `vectorbt` version 0.28.0 or later. Always check the official PyPI or GitHub for current Python requirements.","message":"Early documentation and tutorials (e.g., from March 2022) incorrectly stated that vectorbt did not support Python 3.10. The library now officially supports and requires Python >=3.10 as per PyPI metadata. Relying on outdated information may lead to incorrect assumptions about compatibility.","severity":"gotcha","affected_versions":"Prior to official 3.10 support (pre-0.28.x)"},{"fix":"Always place the `.vbt` accessor on the left side of binary operations.","message":"When combining `vbt` accessor methods with other arrays or pandas objects, ensure the `vbt` accessor operand is on the left-hand side (e.g., `df.vbt * 2` rather than `2 * df.vbt`) for consistent behavior and performance benefits.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure `vectorbt` and `TA-Lib` are up-to-date. If the issue persists, consider manually defining indicators or using `vectorbt`'s built-in indicator wrappers if available, instead of `IndicatorFactory.from_talib` for the specific indicator.","cause":"This error has been reported in older versions when attempting to dynamically create indicators from TA-Lib functions using `IndicatorFactory`. It indicates an incompatibility or internal API change.","error":"AttributeError: 'Function' object has no attribute '_Function__info' when using vbt.IndicatorFactory.from_talib()"},{"fix":"Transform your Pandas Series into a Pandas DataFrame, even if it's a single column, before passing it to the `vbt.heatmap` method. This ensures proper indexing and value mapping.","cause":"The heatmap plotting functionality might have unexpected behavior or require specific data structures (like DataFrames) for correct visualization, especially when dealing with multi-parameter results which are typically structured as DataFrames.","error":"vectorbt heatmap displays wrong values or not all values when using a Pandas Series directly."},{"fix":"Ensure your strategy logic is vectorized as much as possible, leveraging pandas and NumPy operations. For custom complex logic, use Numba's `njit` decorator. Structure hyperparameter sweeps into MultiIndex DataFrames for `vectorbt` to process efficiently in a vectorized manner.","cause":"While VectorBT is designed for speed, users might inadvertently write non-vectorized Python loops or perform operations that prevent Numba from optimizing. Incorrect data structuring (e.g., not leveraging MultiIndex for parameter sweeps) can also lead to performance bottlenecks.","error":"Backtesting runs very slowly with large datasets or many strategy permutations."}]}