{"id":13449676,"url":"https://github.com/polakowo/vectorbt","last_synced_at":"2025-05-14T22:02:26.567Z","repository":{"id":37584717,"uuid":"110684325","full_name":"polakowo/vectorbt","owner":"polakowo","description":"Find your trading edge, using the fastest engine for backtesting, algorithmic trading, and research. ","archived":false,"fork":false,"pushed_at":"2025-05-02T09:17:12.000Z","size":751331,"stargazers_count":5169,"open_issues_count":116,"forks_count":700,"subscribers_count":130,"default_branch":"master","last_synced_at":"2025-05-07T21:12:42.776Z","etag":null,"topics":["algorithmic-trading","algorithmic-traiding","backtesting","cryptocurrency","data-science","data-visualization","finance","machine-learning","portfolio-optimization","quantitative-analysis","quantitative-finance","time-series","trading","trading-strategies"],"latest_commit_sha":null,"homepage":"https://vectorbt.dev","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/polakowo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"polakowo","ko_fi":"vectorbtpro","patreon":"VectorBTPRO"}},"created_at":"2017-11-14T11:56:32.000Z","updated_at":"2025-05-07T19:46:15.000Z","dependencies_parsed_at":"2023-02-15T11:01:22.581Z","dependency_job_id":"2623c919-c4a7-4eea-a063-f90e5e50d165","html_url":"https://github.com/polakowo/vectorbt","commit_stats":{"total_commits":858,"total_committers":13,"mean_commits":66.0,"dds":0.02447552447552448,"last_synced_commit":"8936ddd22b243635d690dd5d033834e62fb31391"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polakowo%2Fvectorbt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polakowo%2Fvectorbt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polakowo%2Fvectorbt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polakowo%2Fvectorbt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/polakowo","download_url":"https://codeload.github.com/polakowo/vectorbt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254235685,"owners_count":22036962,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithmic-trading","algorithmic-traiding","backtesting","cryptocurrency","data-science","data-visualization","finance","machine-learning","portfolio-optimization","quantitative-analysis","quantitative-finance","time-series","trading","trading-strategies"],"created_at":"2024-07-31T06:00:51.127Z","updated_at":"2025-05-14T22:02:21.549Z","avatar_url":"https://github.com/polakowo.png","language":"Python","readme":"\u003cdiv align=\"center\"\u003e\n    \u003ca href=\"https://vectorbt.pro/\" alt=\"https://vectorbt.pro/\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/polakowo/vectorbt/master/docs/docs/assets/logo/header-pro.svg\" /\u003e\n    \u003c/a\u003e\n\u003c/div\u003e\n\u003cdiv align=\"center\"\u003e\n    \u003ca href=\"https://vectorbt.dev/\" alt=\"https://vectorbt.dev/\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/polakowo/vectorbt/master/docs/docs/assets/logo/header.svg\" /\u003e\n    \u003c/a\u003e\n\u003c/div\u003e\n\u003cbr\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://pepy.tech/project/vectorbt\" alt=\"Downloads\"\u003e\n        \u003cimg src=\"https://pepy.tech/badge/vectorbt\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/vectorbt\" alt=\"PyPi\"\u003e\n        \u003cimg src=\"https://img.shields.io/pypi/v/vectorbt?color=blueviolet\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/polakowo/vectorbt/blob/master/LICENSE.md\" alt=\"License\"\u003e\n\t\u003cimg src=\"https://img.shields.io/badge/license-Fair%20Code-yellow\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://codecov.io/gh/polakowo/vectorbt\" alt=\"codecov\"\u003e\n        \u003cimg src=\"https://codecov.io/gh/polakowo/vectorbt/branch/master/graph/badge.svg?token=YTLNAI7PS3\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://vectorbt.dev/\" alt=\"Website\"\u003e\n        \u003cimg src=\"https://img.shields.io/website?url=https://vectorbt.dev/\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://mybinder.org/v2/gh/polakowo/vectorbt/HEAD?urlpath=lab\" alt=\"Binder\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/launch-binder-d6604a\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://gitter.im/vectorbt/community?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge\" alt=\"Join the chat at https://gitter.im/vectorbt/community\"\u003e\n        \u003cimg src=\"https://badges.gitter.im/vectorbt.svg\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://pypi.org/project/vectorbt\" alt=\"Python Versions\"\u003e\n        \u003cimg src=\"https://img.shields.io/pypi/pyversions/vectorbt.svg?logo=python\u0026logoColor=white\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n## :sparkles: Usage\n\nvectorbt allows you to easily backtest strategies with a couple of lines of Python code.\n\n* Here is how much profit we would have made if we invested $100 into Bitcoin in 2014:\n\n```python\nimport vectorbt as vbt\n\nprice = vbt.YFData.download('BTC-USD').get('Close')\n\npf = vbt.Portfolio.from_holding(price, init_cash=100)\npf.total_profit()\n```\n\n```plaintext\n8961.008555963961\n```\n\n* Buy whenever 10-day SMA crosses above 50-day SMA and sell when opposite:\n\n```python\nfast_ma = vbt.MA.run(price, 10)\nslow_ma = vbt.MA.run(price, 50)\nentries = fast_ma.ma_crossed_above(slow_ma)\nexits = fast_ma.ma_crossed_below(slow_ma)\n\npf = vbt.Portfolio.from_signals(price, entries, exits, init_cash=100)\npf.total_profit()\n```\n\n```plaintext\n16423.251963801864\n```\n\n* Generate 1,000 strategies with random signals and test them on BTC and ETH:\n\n```python\nimport numpy as np\n\nsymbols = [\"BTC-USD\", \"ETH-USD\"]\nprice = vbt.YFData.download(symbols, missing_index='drop').get('Close')\n\nn = np.random.randint(10, 101, size=1000).tolist()\npf = vbt.Portfolio.from_random_signals(price, n=n, init_cash=100, seed=42)\n\nmean_expectancy = pf.trades.expectancy().groupby(['randnx_n', 'symbol']).mean()\nfig = mean_expectancy.unstack().vbt.scatterplot(xaxis_title='randnx_n', yaxis_title='mean_expectancy')\nfig.show()\n```\n\n![rand_scatter.svg](https://raw.githubusercontent.com/polakowo/vectorbt/master/docs/docs/assets/images/usage_rand_scatter.svg)\n\n* For fans of hyperparameter optimization: here is a snippet for testing 10,000 window combinations of a \ndual SMA crossover strategy on BTC, USD, and LTC:\n\n```python\nsymbols = [\"BTC-USD\", \"ETH-USD\", \"LTC-USD\"]\nprice = vbt.YFData.download(symbols, missing_index='drop').get('Close')\n\nwindows = np.arange(2, 101)\nfast_ma, slow_ma = vbt.MA.run_combs(price, window=windows, r=2, short_names=['fast', 'slow'])\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='1D')\npf = vbt.Portfolio.from_signals(price, entries, exits, **pf_kwargs)\n\nfig = pf.total_return().vbt.heatmap(\n    x_level='fast_window', y_level='slow_window', slider_level='symbol', symmetric=True,\n    trace_kwargs=dict(colorbar=dict(title='Total return', tickformat='%')))\nfig.show()\n```\n\n\u003cimg width=\"650\" src=\"https://raw.githubusercontent.com/polakowo/vectorbt/master/docs/docs/assets/images/usage_dmac_heatmap.gif\"\u003e\n\nDigging into each strategy configuration is as simple as indexing with pandas:\n\n```python\npf[(10, 20, 'ETH-USD')].stats()\n```\n\n```plaintext\nStart                          2015-08-07 00:00:00+00:00\nEnd                            2021-08-01 00:00:00+00:00\nPeriod                                2183 days 00:00:00\nStart Value                                        100.0\nEnd Value                                  620402.791485\nTotal Return [%]                           620302.791485\nBenchmark Return [%]                        92987.961948\nMax Gross Exposure [%]                             100.0\nTotal Fees Paid                             10991.676981\nMax Drawdown [%]                               70.734951\nMax Drawdown Duration                  760 days 00:00:00\nTotal Trades                                          54\nTotal Closed Trades                                   53\nTotal Open Trades                                      1\nOpen Trade PnL                              67287.940601\nWin Rate [%]                                   52.830189\nBest Trade [%]                               1075.803607\nWorst Trade [%]                               -29.593414\nAvg Winning Trade [%]                          95.695343\nAvg Losing Trade [%]                          -11.890246\nAvg Winning Trade Duration    35 days 23:08:34.285714286\nAvg Losing Trade Duration                8 days 00:00:00\nProfit Factor                                   2.651143\nExpectancy                                   10434.24247\nSharpe Ratio                                    2.041211\nCalmar Ratio                                      4.6747\nOmega Ratio                                     1.547013\nSortino Ratio                                   3.519894\nName: (10, 20, ETH-USD), dtype: object\n```\n\nThe same for plotting:\n\n```python\npf[(10, 20, 'ETH-USD')].plot().show()\n```\n\n![dmac_portfolio.svg](https://raw.githubusercontent.com/polakowo/vectorbt/master/docs/docs/assets/images/usage_dmac_portfolio.svg)\n\nIt's not all about backtesting - vectorbt can be used to facilitate financial data analysis and visualization.\n\n* Let's generate a GIF that animates the %B and bandwidth of Bollinger Bands for different symbols:\n\n```python\nsymbols = [\"BTC-USD\", \"ETH-USD\", \"ADA-USD\"]\nprice = vbt.YFData.download(symbols, period='6mo', missing_index='drop').get('Close')\nbbands = vbt.BBANDS.run(price)\n\ndef plot(index, bbands):\n    bbands = bbands.loc[index]\n    fig = vbt.make_subplots(\n        rows=2, cols=1, shared_xaxes=True, vertical_spacing=0.15,\n        subplot_titles=('%B', 'Bandwidth'))\n    fig.update_layout(template='vbt_dark', showlegend=False, width=750, height=400)\n    bbands.percent_b.vbt.ts_heatmap(\n        trace_kwargs=dict(zmin=0, zmid=0.5, zmax=1, colorscale='Spectral', colorbar=dict(\n            y=(fig.layout.yaxis.domain[0] + fig.layout.yaxis.domain[1]) / 2, len=0.5\n        )), add_trace_kwargs=dict(row=1, col=1), fig=fig)\n    bbands.bandwidth.vbt.ts_heatmap(\n        trace_kwargs=dict(colorbar=dict(\n            y=(fig.layout.yaxis2.domain[0] + fig.layout.yaxis2.domain[1]) / 2, len=0.5\n        )), add_trace_kwargs=dict(row=2, col=1), fig=fig)\n    return fig\n\nvbt.save_animation('bbands.gif', bbands.wrapper.index, plot, bbands, delta=90, step=3, fps=3)\n```\n\n```plaintext\n100%|██████████| 31/31 [00:21\u003c00:00,  1.21it/s]\n```\n\n\u003cimg width=\"750\" src=\"https://raw.githubusercontent.com/polakowo/vectorbt/master/docs/docs/assets/images/usage_bbands.gif\"\u003e\n\nAnd this is just the tip of the iceberg of what's possible. Check out the [website](https://vectorbt.dev/) to learn more.\n\n## Installation\n\n```sh\npip install -U vectorbt\n```\n\nTo also install optional dependencies:\n\n```sh\npip install -U \"vectorbt[full]\"\n```\n\n## Colab Notebook\n\n[Google Colaboratory](https://colab.research.google.com/drive/1ibqyrf6LPFlzRb6mkPpl3hxqL6ryNBXI?usp=sharing)\n\n## License\n\nThis work is [fair-code](http://faircode.io/) distributed under [Apache 2.0 with Commons Clause](https://github.com/polakowo/vectorbt/blob/master/LICENSE.md) license. \nThe source code is open and everyone (individuals and organizations) can use it for free. \nHowever, it is not allowed to sell products and services that are mostly just this software.\n\nIf you have any questions about this or want to apply for a license exception, please [contact the author](mailto:olegpolakow@gmail.com).\n\nInstalling optional dependencies may be subject to a more restrictive license.\n\n## Star History\n\n[![Star History Chart](https://api.star-history.com/svg?repos=polakowo/vectorbt\u0026type=Timeline)](https://star-history.com/#polakowo/vectorbt\u0026Timeline)\n\n## Disclaimer\n\nThis software is for educational purposes only. Do not risk money which you are afraid to lose. \nUSE THE SOFTWARE AT YOUR OWN RISK. THE AUTHORS AND ALL AFFILIATES ASSUME NO RESPONSIBILITY FOR YOUR TRADING RESULTS.\n","funding_links":["https://github.com/sponsors/polakowo","https://ko-fi.com/vectorbtpro","https://patreon.com/VectorBTPRO"],"categories":["Backtesting and Live Trading","Backtest + live trading","Python","Curated List","Quant and Trading Agents"],"sub_categories":["General - Vector Based Frameworks","General purpose","Trading \u0026 Backtesting","Backtesting Frameworks (only support backtesting)","Benchmark Reality Check (real-world tool use)"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolakowo%2Fvectorbt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolakowo%2Fvectorbt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolakowo%2Fvectorbt/lists"}