{"id":21039,"date":"2023-03-27T11:18:09","date_gmt":"2023-03-27T11:18:09","guid":{"rendered":"https:\/\/algotrading101.com\/learn\/?p=21039"},"modified":"2023-05-10T16:02:34","modified_gmt":"2023-05-10T16:02:34","slug":"vectorbt-guide","status":"publish","type":"post","link":"https:\/\/algotrading101.com\/learn\/vectorbt-guide\/","title":{"rendered":"VectorBT &#8211; An Introductory Guide"},"content":{"rendered":"<div class=\"pvc_clear\"><\/div><p id=\"pvc_stats_21039\" class=\"pvc_stats total_only  \" data-element-id=\"21039\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p><div class=\"pvc_clear\"><\/div>\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"721\" height=\"95\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/11\/vectorbt-logo.png\" alt=\"\" class=\"wp-image-18775\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/11\/vectorbt-logo.png 721w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/11\/vectorbt-logo-300x40.png 300w\" sizes=\"(max-width: 721px) 100vw, 721px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Table of contents:<\/h3>\n\n\n\n<ol>\n<li><a href=\"#what-is-vectorbt\">What is VectorBT?<\/a><\/li>\n\n\n\n<li><a href=\"#vectorbt-use\">What is VectorBT used for?<\/a><\/li>\n\n\n\n<li><a href=\"#vectorbt-pros\">Why should I use VectorBT?<\/a><\/li>\n\n\n\n<li><a href=\"#vectorbt-cons\">Why shouldn\u2019t I use VectorBT?<\/a><\/li>\n\n\n\n<li><a href=\"#vectorbt-free\">Is VectorBT free?<\/a><\/li>\n\n\n\n<li><a href=\"#vectorbt-alternatives\">What are some VectorBT alternatives?<\/a><\/li>\n\n\n\n<li><a href=\"#vectorbt-start\">How to get started with VectorBT?<\/a><\/li>\n\n\n\n<li><a href=\"#vectorbt-get-data\">How to get data with VectorBT?<\/a><\/li>\n\n\n\n<li><a href=\"#vectorbt-technical-indicators\">How to use technical indicators with VectorBT?<\/a><\/li>\n\n\n\n<li><a href=\"#vectorbt-define-entries-and-exits\">How to define entries and exits with VectorBT?<\/a><\/li>\n\n\n\n<li><a href=\"#vectorbt-perform-backtesting\">How to perform backtesting with VectorBT?<\/a><\/li>\n\n\n\n<li><a href=\"#vectorbt-plot-backtesting\">How to plot backtesting results with VectorBT?<\/a><\/li>\n\n\n\n<li><a href=\"#vectorbt-perform-analysis\"><span style=\"color: initial;\">How to perform analysis with VectorBT?<\/span><\/a><\/li>\n\n\n\n<li><a href=\"#vectorbt-telegram\">How to use Telegram with VectorBT?<\/a><\/li>\n\n\n\n<li><a href=\"#vectorbt-schedule-commands\">How to schedule commands with VectorBT?<\/a><\/li>\n\n\n\n<li><a href=\"#vectorbt-full-code\">Full code<\/a><\/li>\n<\/ol>\n\n\n\n<a name=\"what-is-vectorbt\">\n\n\n\n<h2 class=\"wp-block-heading\">What is VectorBT?<\/h2>\n\n\n\n<p>VectorBT is an open-source Python library for quantitative analysis and backtesting.<\/p>\n\n\n\n<p>Link: <a href=\"https:\/\/vectorbt.dev\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/vectorbt.dev\/<\/a><\/p>\n\n\n\n<a name=\"vectorbt-use\">\n\n\n\n<h2 class=\"wp-block-heading\">What is VectorBT used for?<\/h2>\n\n\n\n<p>VectorBT is used by algorithmic traders and investors to perform quantitative analysis, strategy testing, and research. It is built and optimized for performance and uses NumPy and Numba under the hood.<\/p>\n\n\n\n<a name=\"vectorbt-pros\">\n\n\n\n<h2 class=\"wp-block-heading\">Why should I use VectorBT?<\/h2>\n\n\n\n<ul>\n<li>VectorBT is open-source<\/li>\n\n\n\n<li>VectorBT is easy to use<\/li>\n\n\n\n<li>Is fast<\/li>\n\n\n\n<li>Integrates with Telegram<\/li>\n\n\n\n<li>Offers interactive charting via Jupyter notebooks<\/li>\n<\/ul>\n\n\n\n<a name=\"vectorbt-cons\">\n\n\n\n<h2 class=\"wp-block-heading\">Why shouldn&#8217;t I use VectorBT?<\/h2>\n\n\n\n<ul>\n<li>VectorBT could use more features<\/li>\n\n\n\n<li>It doesn&#8217;t have the best documentation<\/li>\n\n\n\n<li>If you want to get serious with VectorBT, you will need to acquire a proprietary VectorBT Pro membership that gives you access to the upgraded library<\/li>\n<\/ul>\n\n\n\n<a name=\"vectorbt-free\">\n\n\n\n<h2 class=\"wp-block-heading\">Is VectorBT free?<\/h2>\n\n\n\n<p>VectorBT is an open-source library and it is free to use. Do keep in mind that there is <a href=\"https:\/\/vectorbt.pro\/\">VectorBT Pro<\/a> which is a successor of VectorBT and comes with advanced features and performance which is a premium product on an invite-only GitHub basis.<\/p>\n\n\n\n<a name=\"vectorbt-alternatives\">\n\n\n\n<h2 class=\"wp-block-heading\">What are some VectorBT alternatives?<\/h2>\n\n\n\n<p>VectorBT can be replaced with other software that can be more suitable for your needs. Here are some of them:<\/p>\n\n\n\n<ul>\n<li><a href=\"https:\/\/algotrading101.com\/learn\/quantconnect-guide\/\">QuantConnect<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/algotrading101.com\/learn\/pine-script-tradingview-guide\/\">TradingView (Pine Script)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/algotrading101.com\/learn\/backtrader-for-backtesting\/\">Backtrader<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/algotrading101.com\/learn\/interactive-brokers-python-api-native-guide\/\">Interactive Brokers<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/algotrading101.com\/learn\/thinkscript-guide\/\">Thikscript<\/a><\/li>\n\n\n\n<li>QuantRocket<\/li>\n\n\n\n<li>HaasOnline<\/li>\n\n\n\n<li>cTrader<\/li>\n\n\n\n<li>Trality, and more<\/li>\n<\/ul>\n\n\n\n<a name=\"vectorbt-start\">\n\n\n\n<h2 class=\"wp-block-heading\">How to get started with VectorBT?<\/h2>\n\n\n\n<p>To get started with VectorBT, you will need to download the Python library via pip with the following command (you might want to have a new environment):<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>pip install -U vectorbt<\/code><\/pre><\/div>\n\n\n\n<p>If you want all the dependencies and features that VectorBT has, you will want to run this command:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>pip install -U &quot;vectorbt[full]&quot;<\/code><\/pre><\/div>\n\n\n\n<p>If you are a fan of using Docker for your development, you have the option of spinning up a docker container that hosts a Jupyter Lab with VectorBT inside of it:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>docker run --rm -p 8888:8888 -v &quot;$PWD&quot;:\/home\/jovyan\/work polakowo\/vectorbt<\/code><\/pre><\/div>\n\n\n\n<p>The code block above pulls the latest&nbsp;<code>polakowo\/vectorbt<\/code>&nbsp;image from Docker Hub. It then starts a container running a Jupyter Notebook server and exposes the server on host port 8888. <\/p>\n\n\n\n<p>Visiting&nbsp;<code>http:\/\/127.0.0.1:8888\/?token=&lt;token&gt;<\/code>&nbsp;in a browser loads JupyterLab, where the token is the secret token printed in the console.<\/p>\n\n\n\n<p>When you&#8217;re done with using the Docker container, Docker destroys the container after the notebook server exit, but any files written to the working directory in the container remain intact in the working directory of the host.<\/p>\n\n\n\n<p>I&#8217;ll personally use it inside of a <a href=\"https:\/\/algotrading101.com\/learn\/google-colab-guide\/\">Google Colab<\/a> notebook and install it via pip.<\/p>\n\n\n\n<p>Now that we have VectorBT ready, let us explore in the following headers what it has to offer in terms of features and performance.<\/p>\n\n\n\n<a name=\"vectorbt-get-data\">\n\n\n\n<h2 class=\"wp-block-heading\">How to get data with VectorBT?<\/h2>\n\n\n\n<p>To get data with VectorBT, you will need to utilize the function that connects to <a href=\"https:\/\/algotrading101.com\/learn\/yfinance-guide\/\">Yahoo Finance<\/a> to download the data and provide it with the asset you wish to obtain the data. For example, let&#8217;s obtain the ETH-USD ticker closing price data:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>eth_price = vbt.YFData.download(&#39;ETH-USD&#39;).get(&#39;Close&#39;)\neth_price[:5]<\/code><\/pre><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code>Date\n2017-11-09 00:00:00+00:00    320.884003\n2017-11-10 00:00:00+00:00    299.252991\n2017-11-11 00:00:00+00:00    314.681000\n2017-11-12 00:00:00+00:00    307.907990\n2017-11-13 00:00:00+00:00    316.716003\nFreq: D, Name: Close, dtype: float64<\/code><\/pre>\n\n\n\n<a name=\"vectorbt-technical-indicators\">\n\n\n\n<h2 class=\"wp-block-heading\">How to use technical indicators with VectorBT?<\/h2>\n\n\n\n<p>To use technical indicators with VectorBT, you will need to use in-built functions that host indicators such as the MA, MSTD, BBANDS, RSI, and more. For example, let&#8217;s calculate a fast and slow MA for ETH and the RSI.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>fast_ma = vbt.MA.run(eth_price, 10)\nslow_ma = vbt.MA.run(eth_price, 50)\nrsi = vbt.RSI.run(eth_price)<\/code><\/pre><\/div>\n\n\n\n<a name=\"vectorbt-define-entries-and-exits\">\n\n\n\n<h2 class=\"wp-block-heading\">How to define entries and exists with VectorBT?<\/h2>\n\n\n\n<p>To define entries and exists with VectorBT, all you need to do is to define the logic of those conditions that need to be satisfied in order to be marked as an entry or exit. <\/p>\n\n\n\n<p>For example, let&#8217;s define the entry to be when the fast MA crosses the slow MA while the RSI is over 50 and the exit when the slow MA crosses above the fast MA and the RSI is under 50:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>entries = fast_ma.ma_crossed_above(slow_ma) & rsi.rsi_above(50)\nexits = slow_ma.ma_crossed_above(fast_ma) & rsi.rsi_below(50)<\/code><\/pre><\/div>\n\n\n\n<p class=\"has-vivid-red-color has-text-color\">Note that this strategy is just an example and strategies like this almost never work in real-life.<\/p>\n\n\n\n<a name=\"vectorbt-perform-backtesting\">\n\n\n\n<h2 class=\"wp-block-heading\">How to perform backtesting with VectorBT?<\/h2>\n\n\n\n<p>To perform backtesting with VectorBT, you can use the Portfolio function and its modules to define the trading requirements such as the entry and exit conditions, initial cash, and more. For example, let&#8217;s implement our exits and entries from the header above and backtest them:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>pf = vbt.Portfolio.from_signals(eth_price, entries, exits, init_cash=10000)\npf.total_profit()<\/code><\/pre><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code>55760.53<\/code><\/pre>\n\n\n\n<p> Let us observe the overall statistics of our simple trading strategy that is only for showcase purposes by running the <code>pf.stats()<\/code> command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Start                          2017-11-09 00:00:00+00:00\nEnd                            2022-11-07 00:00:00+00:00\nPeriod                                1825 days 00:00:00\nStart Value                                      10000.0\nEnd Value                                   65760.531431\nTotal Return &#91;%]                              557.605314\nBenchmark Return &#91;%]                           393.42466\nMax Gross Exposure &#91;%]                             100.0\nTotal Fees Paid                                      0.0\nMax Drawdown &#91;%]                               61.262033\nMax Drawdown Duration                  513 days 00:00:00\nTotal Trades                                          18\nTotal Closed Trades                                   17\nTotal Open Trades                                      1\nOpen Trade PnL                                1156.40722\nWin Rate &#91;%]                                   41.176471\nBest Trade &#91;%]                                318.026171\nWorst Trade &#91;%]                               -21.805347\nAvg Winning Trade &#91;%]                          71.673003\nAvg Losing Trade &#91;%]                            -10.7351\nAvg Winning Trade Duration    83 days 06:51:25.714285715\nAvg Losing Trade Duration               18 days 14:24:00\nProfit Factor                                   3.388864\nExpectancy                                   3212.007307\nSharpe Ratio                                    0.919382\nCalmar Ratio                                    0.746707\nOmega Ratio                                      1.23331\nSortino Ratio                                   1.378526<\/code><\/pre>\n\n\n\n<a name=\"vectorbt-plot-backtesting\">\n\n\n\n<h2 class=\"wp-block-heading\">How to plot backtesting results with VectorBT?<\/h2>\n\n\n\n<p>To plot backtesting results with VectorBT, all you need to do is to utilize the <code>plot<\/code> function on your Portfolio module which will show the full backtest range with orders, trade returns, benchmarks, and more.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>pf.plot().show()<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"750\" height=\"960\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/11\/vectorbt-backtest-results.png\" alt=\"\" class=\"wp-image-18776\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/11\/vectorbt-backtest-results.png 750w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/11\/vectorbt-backtest-results-234x300.png 234w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure>\n\n\n\n<p>As you can see from the interactive Plotly graph above, it takes one good trade to trump the others and keep us in a profitable state. The visualization is also nicely done. We can also plot other features of our portfolio:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>pf.plot(subplots=[&#39;cash&#39;, &#39;assets&#39;, &#39;value&#39;]).show()<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"960\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/11\/vectorbt-graph.png\" alt=\"\" class=\"wp-image-18777\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/11\/vectorbt-graph.png 750w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/11\/vectorbt-graph-234x300.png 234w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure>\n\n\n\n<a name=\"vectorbt-perform-analysis\">\n\n\n\n<h2 class=\"wp-block-heading\"><span style=\"color: initial;\">How to perform analysis with VectorBT?<\/span><\/h2>\n\n\n\n<p>To perform analysis with VectorBT, you can easily analyze different strategies across different assets and hyperparameters. For example, we can test 10000 windows combinations of a dual SMA crossover strategy on MSFT, AMZN, and AAPL stocks.<\/p>\n\n\n\n<p>Again, this is just to demonstrate a simple example. Strategies like this almost never work in real-life.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>import numpy as np\n\nsymbols = [&quot;MSFT&quot;, &quot;AMZN&quot;, &quot;AAPL&quot;]\nprice = vbt.YFData.download(symbols, missing_index=&#39;drop&#39;).get(&#39;Close&#39;)\n\nwindows = np.arange(2, 101)\nfast_ma, slow_ma = vbt.MA.run_combs(price, window=windows, r=2, short_names=[&#39;fast&#39;, &#39;slow&#39;])\nentries = fast_ma.ma_crossed_above(slow_ma)\nexits = fast_ma.ma_crossed_below(slow_ma)\n\npf_kwargs = dict(size=np.inf, fees=0.001, freq=&#39;1D&#39;)\npf = vbt.Portfolio.from_signals(price, entries, exits, **pf_kwargs)\n\nfig = pf.total_return().vbt.heatmap(\n    x_level=&#39;fast_window&#39;, y_level=&#39;slow_window&#39;, slider_level=&#39;symbol&#39;, symmetric=True,\n    trace_kwargs=dict(colorbar=dict(title=&#39;Total return&#39;, tickformat=&#39;%&#39;)))\nfig.show()<\/code><\/pre><\/div>\n\n\n\n<p>The example above is from the VectorBT documentation and has been slightly adapted.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"605\" height=\"555\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/11\/vectorbt-analysis.png\" alt=\"\" class=\"wp-image-18778\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/11\/vectorbt-analysis.png 605w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/11\/vectorbt-analysis-300x275.png 300w\" sizes=\"(max-width: 605px) 100vw, 605px\" \/><\/figure>\n\n\n\n<p>In the graph above you can switch between the three stocks and observe which combination of the moving averages had the best performance. Beware of committing interpretation mistakes and falling to lookahead bias, <a href=\"https:\/\/algotrading101.com\/learn\/what-is-overfitting-in-trading\/\">overfitting<\/a> and similar when doing things like these. <\/p>\n\n\n\n<p>Moreover, is it just me or is there a shape of a rocket in the AMZN chart?<\/p>\n\n\n\n<a name=\"vectorbt-telegram\">\n\n\n\n<h2 class=\"wp-block-heading\">How to use Telegram with VectorBT?<\/h2>\n\n\n\n<p>To use Telegram with VectorBT, you can utilize the Telegram library command handler and ccxt. Below is an example from the VectorBT documentation that uses Binance to send ticker updates to your Telegram account:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>from telegram.ext import CommandHandler\nimport ccxt\n\nclass BinanceTickerBot(vbt.TelegramBot):\n    @property\n    def custom_handlers(self):\n        return CommandHandler(&#39;get&#39;, self.get),\n\n    @property\n    def help_message(self):\n        return &quot;Type \/get [symbol] to get the latest ticker on Binance.&quot;\n\n    def get(self, update, context):\n        chat_id = update.effective_chat.id\n        try:\n            ticker = ccxt.binance().fetchTicker(context.args[0])\n        except Exception as e:\n            self.send_message(chat_id, str(e))\n            return\n        self.send_message(chat_id, str(ticker[&#39;last&#39;]))\n\nbot = BinanceTickerBot(token=&#39;YOUR_TOKEN&#39;)\nbot.start()<\/code><\/pre><\/div>\n\n\n\n<a name=\"vectorbt-schedule-commands\">\n\n\n\n<h2 class=\"wp-block-heading\">How to schedule commands with VectorBT?<\/h2>\n\n\n\n<p>To schedule commands with VectorBT, you can use the <code>ScheduleManager<\/code> module to run commands at specified time intervals. For example, we can obtain the latest BTC trades from Binance every 20 seconds with the following block of code:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>from vectorbt.utils.datetime_ import datetime_to_ms, to_tzaware_datetime, get_utc_tz\nfrom IPython.display import SVG, display, clear_output\nimport pandas as pd\n\nexchange = ccxt.binance()\n\ndef job_func():\n   since = datetime_to_ms(to_tzaware_datetime(&#39;10 seconds ago UTC&#39;, tz=get_utc_tz()))\n   trades = exchange.fetch_trades(&#39;BTC\/USDT&#39;, since)\n   price = pd.Series({t[&#39;datetime&#39;]: t[&#39;price&#39;] for t in trades})\n   svg = price.vbt.plot().to_image(format=&quot;svg&quot;)\n   clear_output()\n   display(SVG(svg))\n\nscheduler = vbt.ScheduleManager()\nscheduler.every(20, &#39;seconds&#39;).do(job_func)\nscheduler.start()<\/code><\/pre><\/div>\n\n\n\n<a name=\"vectorbt-full-code\">\n\n\n\n<h2 class=\"wp-block-heading\">Full code<\/h2>\n\n\n\n<p><a href=\"https:\/\/github.com\/AlgoTrading101\/VectorBT-AlgoTrading101\/blob\/main\/README.md\">GitHub link<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_21039\" class=\"pvc_stats total_only  \" data-element-id=\"21039\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p>Table of contents: What is VectorBT? VectorBT is an open-source Python library for quantitative analysis and backtesting. Link: https:\/\/vectorbt.dev\/ What is VectorBT used for? VectorBT is used by algorithmic traders and investors to perform quantitative analysis, strategy testing, and research. It is built and optimized for performance and uses NumPy and Numba under the hood. [&hellip;]<\/p>\n","protected":false},"author":14,"featured_media":21045,"comment_status":"closed","ping_status":"closed","sticky":true,"template":"","format":"standard","meta":{"_lmt_disableupdate":"no","_lmt_disable":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[3,2],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>VectorBT - An Introductory Guide - AlgoTrading101 Blog<\/title>\n<meta name=\"description\" content=\"Authentic Stories about Algorithmic trading, coding and life.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/algotrading101.com\/learn\/vectorbt-guide\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"VectorBT - An Introductory Guide - AlgoTrading101 Blog\" \/>\n<meta property=\"og:description\" content=\"Authentic Stories about Algorithmic trading, coding and life.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/algotrading101.com\/learn\/vectorbt-guide\/\" \/>\n<meta property=\"og:site_name\" content=\"Quantitative Trading Ideas and Guides - AlgoTrading101 Blog\" \/>\n<meta property=\"article:published_time\" content=\"2023-03-27T11:18:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-05-10T16:02:34+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/03\/vectorbt-logo.png\" \/>\n\t<meta property=\"og:image:width\" content=\"512\" \/>\n\t<meta property=\"og:image:height\" content=\"512\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Igor Radovanovic\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Igor Radovanovic\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"VectorBT - An Introductory Guide - AlgoTrading101 Blog","description":"Authentic Stories about Algorithmic trading, coding and life.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/algotrading101.com\/learn\/vectorbt-guide\/","og_locale":"en_US","og_type":"article","og_title":"VectorBT - An Introductory Guide - AlgoTrading101 Blog","og_description":"Authentic Stories about Algorithmic trading, coding and life.","og_url":"https:\/\/algotrading101.com\/learn\/vectorbt-guide\/","og_site_name":"Quantitative Trading Ideas and Guides - AlgoTrading101 Blog","article_published_time":"2023-03-27T11:18:09+00:00","article_modified_time":"2023-05-10T16:02:34+00:00","og_image":[{"width":512,"height":512,"url":"http:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/03\/vectorbt-logo.png","type":"image\/png"}],"author":"Igor Radovanovic","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Igor Radovanovic","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/algotrading101.com\/learn\/vectorbt-guide\/#article","isPartOf":{"@id":"https:\/\/algotrading101.com\/learn\/vectorbt-guide\/"},"author":{"name":"Igor Radovanovic","@id":"https:\/\/algotrading101.com\/learn\/#\/schema\/person\/a7ae60c112a73b7c3fe14ac56726a0ae"},"headline":"VectorBT &#8211; An Introductory Guide","datePublished":"2023-03-27T11:18:09+00:00","dateModified":"2023-05-10T16:02:34+00:00","mainEntityOfPage":{"@id":"https:\/\/algotrading101.com\/learn\/vectorbt-guide\/"},"wordCount":1069,"publisher":{"@id":"https:\/\/algotrading101.com\/learn\/#organization"},"articleSection":["Programming","Trading"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/algotrading101.com\/learn\/vectorbt-guide\/","url":"https:\/\/algotrading101.com\/learn\/vectorbt-guide\/","name":"VectorBT - An Introductory Guide - AlgoTrading101 Blog","isPartOf":{"@id":"https:\/\/algotrading101.com\/learn\/#website"},"datePublished":"2023-03-27T11:18:09+00:00","dateModified":"2023-05-10T16:02:34+00:00","description":"Authentic Stories about Algorithmic trading, coding and life.","breadcrumb":{"@id":"https:\/\/algotrading101.com\/learn\/vectorbt-guide\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/algotrading101.com\/learn\/vectorbt-guide\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/algotrading101.com\/learn\/vectorbt-guide\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/algotrading101.com\/learn\/"},{"@type":"ListItem","position":2,"name":"VectorBT &#8211; An Introductory Guide"}]},{"@type":"WebSite","@id":"https:\/\/algotrading101.com\/learn\/#website","url":"https:\/\/algotrading101.com\/learn\/","name":"Quantitative Trading Ideas and Guides - AlgoTrading101 Blog","description":"Authentic Stories about Algorithmic trading, coding and life.","publisher":{"@id":"https:\/\/algotrading101.com\/learn\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/algotrading101.com\/learn\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/algotrading101.com\/learn\/#organization","name":"AlgoTrading101","url":"https:\/\/algotrading101.com\/learn\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/algotrading101.com\/learn\/#\/schema\/logo\/image\/","url":"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/11\/AlgoTrading101-Lucas-Liew.jpg","contentUrl":"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/11\/AlgoTrading101-Lucas-Liew.jpg","width":1200,"height":627,"caption":"AlgoTrading101"},"image":{"@id":"https:\/\/algotrading101.com\/learn\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/algotrading101.com\/learn\/#\/schema\/person\/a7ae60c112a73b7c3fe14ac56726a0ae","name":"Igor Radovanovic","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/algotrading101.com\/learn\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d46175c509b3ee240a1e2bbe735a4d1e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d46175c509b3ee240a1e2bbe735a4d1e?s=96&d=mm&r=g","caption":"Igor Radovanovic"},"sameAs":["https:\/\/igorradovanovic.com","https:\/\/www.linkedin.com\/in\/igor-radovanovic-profile"],"url":"https:\/\/algotrading101.com\/learn\/author\/igor\/"}]}},"modified_by":"Lucas Liew","_links":{"self":[{"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/posts\/21039"}],"collection":[{"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/comments?post=21039"}],"version-history":[{"count":5,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/posts\/21039\/revisions"}],"predecessor-version":[{"id":21737,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/posts\/21039\/revisions\/21737"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/media\/21045"}],"wp:attachment":[{"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/media?parent=21039"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/categories?post=21039"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/tags?post=21039"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}