{"id":13488257,"url":"https://github.com/edtechre/pybroker","last_synced_at":"2026-03-05T06:05:05.078Z","repository":{"id":65355610,"uuid":"589385734","full_name":"edtechre/pybroker","owner":"edtechre","description":"Algorithmic Trading in Python with Machine Learning","archived":false,"fork":false,"pushed_at":"2026-02-03T22:58:25.000Z","size":4941,"stargazers_count":3080,"open_issues_count":4,"forks_count":398,"subscribers_count":40,"default_branch":"master","last_synced_at":"2026-02-04T11:25:25.421Z","etag":null,"topics":["ai","algorithmic-trading","algotrading","artificial-intelligence","backtesting","crypto","cryptocurrency","data-science","finance","framework","investment","machine-learning","python","quantitative-finance","stocks","trading","trading-strategies"],"latest_commit_sha":null,"homepage":"https://www.pybroker.com","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/edtechre.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-01-16T01:11:52.000Z","updated_at":"2026-02-04T07:46:25.000Z","dependencies_parsed_at":"2023-02-20T18:30:38.837Z","dependency_job_id":"4fa4be7d-1a6f-4093-bc42-7b548d56640d","html_url":"https://github.com/edtechre/pybroker","commit_stats":null,"previous_names":[],"tags_count":75,"template":false,"template_full_name":null,"purl":"pkg:github/edtechre/pybroker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edtechre%2Fpybroker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edtechre%2Fpybroker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edtechre%2Fpybroker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edtechre%2Fpybroker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edtechre","download_url":"https://codeload.github.com/edtechre/pybroker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edtechre%2Fpybroker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30111792,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T03:40:26.266Z","status":"ssl_error","status_checked_at":"2026-03-05T03:39:15.902Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["ai","algorithmic-trading","algotrading","artificial-intelligence","backtesting","crypto","cryptocurrency","data-science","finance","framework","investment","machine-learning","python","quantitative-finance","stocks","trading","trading-strategies"],"created_at":"2024-07-31T18:01:12.438Z","updated_at":"2026-03-05T06:05:05.062Z","avatar_url":"https://github.com/edtechre.png","language":"Python","readme":"\u003cimg src=\"https://github.com/edtechre/pybroker/blob/master/docs/_static/pybroker-logo.png?raw=true\" alt=\"PyBroker\"\u003e\n\n[![python](https://img.shields.io/badge/python-v3-brightgreen.svg)](https://www.python.org/)\n[![Apache 2.0 with Commons Clause](https://img.shields.io/badge/license-Apache%202.0%20Clause-green)](https://www.pybroker.com/en/latest/license.html)\n[![Documentation Status](https://readthedocs.org/projects/pybroker/badge/?version=latest)](https://www.pybroker.com/en/latest/?badge=latest)\n[![Package status](https://github.com/edtechre/pybroker/actions/workflows/main.yml/badge.svg?event=push)](https://github.com/edtechre/pybroker/actions)\n[![Downloads](https://static.pepy.tech/badge/lib-pybroker)](https://pepy.tech/project/lib-pybroker)\n[![Github stars](https://img.shields.io/github/stars/edtechre/pybroker?style=social)](https://github.com/edtechre/pybroker/)\n[![Twitter](https://img.shields.io/twitter/follow/libpybroker?style=social)](https://twitter.com/intent/follow?screen_name=libpybroker)\n\n## Algorithmic Trading in Python with Machine Learning\n\nAre you looking to enhance your trading strategies with the power of Python and\nmachine learning? Then you need to check out **PyBroker**! This Python framework\nis designed for developing algorithmic trading strategies, with a focus on\nstrategies that use machine learning. With PyBroker, you can easily create and\nfine-tune trading rules, build powerful models, and gain valuable insights into\nyour strategy’s performance.\n\n## Key Features\n\n- A super-fast backtesting engine built in [NumPy](https://numpy.org/) and accelerated with [Numba](https://numba.pydata.org/).\n- The ability to create and execute trading rules and models across multiple instruments with ease.\n- Access to historical data from [Alpaca](https://alpaca.markets/), [Yahoo Finance](https://finance.yahoo.com/), [AKShare](https://github.com/akfamily/akshare), or from [your own data provider](https://www.pybroker.com/en/latest/notebooks/7.%20Creating%20a%20Custom%20Data%20Source.html).\n- The option to train and backtest models using [Walkforward Analysis](https://www.pybroker.com/en/latest/notebooks/6.%20Training%20a%20Model.html#Walkforward-Analysis), which simulates how the strategy would perform during actual trading.\n- More reliable trading metrics that use randomized [bootstrapping](https://en.wikipedia.org/wiki/Bootstrapping_(statistics)) to provide more accurate results.\n- Caching of downloaded data, indicators, and models to speed up your development process.\n- Parallelized computations that enable faster performance.\n\nWith PyBroker, you'll have all the tools you need to create winning trading\nstrategies backed by data and machine learning. Start using PyBroker today and\ntake your trading to the next level!\n\n## Installation\n\nPyBroker supports Python 3.9+ on Windows, Mac, and Linux. You can install\nPyBroker using ``pip``:\n\n```bash\n   pip install -U lib-pybroker\n```\n\nOr you can clone the Git repository with:\n\n```bash\n   git clone https://github.com/edtechre/pybroker\n```\n\n## A Quick Example\n\nGet a glimpse of what backtesting with PyBroker looks like with these code\nsnippets:\n\n**Rule-based Strategy**:\n\n```python\n   from pybroker import Strategy, YFinance, highest\n\n   def exec_fn(ctx):\n      # Get the rolling 10 day high.\n      high_10d = ctx.indicator('high_10d')\n      # Buy on a new 10 day high.\n      if not ctx.long_pos() and high_10d[-1] \u003e high_10d[-2]:\n         ctx.buy_shares = 100\n         # Hold the position for 5 days.\n         ctx.hold_bars = 5\n         # Set a stop loss of 2%.\n         ctx.stop_loss_pct = 2\n\n   strategy = Strategy(YFinance(), start_date='1/1/2022', end_date='7/1/2022')\n   strategy.add_execution(\n      exec_fn, ['AAPL', 'MSFT'], indicators=highest('high_10d', 'close', period=10))\n   # Run the backtest after 20 days have passed.\n   result = strategy.backtest(warmup=20)\n```\n\n**Model-based Strategy**:\n\n```python\n   import pybroker\n   from pybroker import Alpaca, Strategy\n\n   def train_fn(train_data, test_data, ticker):\n      # Train the model using indicators stored in train_data.\n      ...\n      return trained_model\n\n   # Register the model and its training function with PyBroker.\n   my_model = pybroker.model('my_model', train_fn, indicators=[...])\n\n   def exec_fn(ctx):\n      preds = ctx.preds('my_model')\n      # Open a long position given my_model's latest prediction.\n      if not ctx.long_pos() and preds[-1] \u003e buy_threshold:\n         ctx.buy_shares = 100\n      # Close the long position given my_model's latest prediction.\n      elif ctx.long_pos() and preds[-1] \u003c sell_threshold:\n         ctx.sell_all_shares()\n\n   alpaca = Alpaca(api_key=..., api_secret=...)\n   strategy = Strategy(alpaca, start_date='1/1/2022', end_date='7/1/2022')\n   strategy.add_execution(exec_fn, ['AAPL', 'MSFT'], models=my_model)\n   # Run Walkforward Analysis on 1 minute data using 5 windows with 50/50 train/test data.\n   result = strategy.walkforward(timeframe='1m', windows=5, train_size=0.5)\n```\n\n## User Guide\n\n- [Getting Started with Data Sources](https://www.pybroker.com/en/latest/notebooks/1.%20Getting%20Started%20with%20Data%20Sources.html)\n- [Backtesting a Strategy](https://www.pybroker.com/en/latest/notebooks/2.%20Backtesting%20a%20Strategy.html)\n- [Evaluating with Bootstrap Metrics](https://www.pybroker.com/en/latest/notebooks/3.%20Evaluating%20with%20Bootstrap%20Metrics.html)\n- [Ranking and Position Sizing](https://www.pybroker.com/en/latest/notebooks/4.%20Ranking%20and%20Position%20Sizing.html)\n- [Writing Indicators](https://www.pybroker.com/en/latest/notebooks/5.%20Writing%20Indicators.html)\n- [Training a Model](https://www.pybroker.com/en/latest/notebooks/6.%20Training%20a%20Model.html)\n- [Creating a Custom Data Source](https://www.pybroker.com/en/latest/notebooks/7.%20Creating%20a%20Custom%20Data%20Source.html)\n- [Applying Stops](https://www.pybroker.com/en/latest/notebooks/8.%20Applying%20Stops.html)\n- [Rebalancing Positions](https://www.pybroker.com/en/latest/notebooks/9.%20Rebalancing%20Positions.html)\n- [Rotational Trading](https://www.pybroker.com/en/latest/notebooks/10.%20Rotational%20Trading.html)\n- [FAQs](https://www.pybroker.com/en/latest/notebooks/FAQs.html)\n\n## Online Documentation\n\n[The full reference documentation is hosted at **www.pybroker.com**.](https://www.pybroker.com)\n\n(For Chinese users: [中文文档](https://www.pybroker.com/zh_CN/latest/), courtesy of [Albert King](https://github.com/albertandking).)\n\n## Contact\n\n\u003cimg src=\"https://github.com/edtechre/pybroker/blob/master/docs/_static/email-image.png?raw=true\"\u003e\n\n## Market-Moving Stock News \u0026 Alerts\n\n**AI-driven market analysis for the stocks you follow.** Receive real-time AI alerts and sentiment analysis for 10,000+ tickers at [www.movealerts.ai](https://www.movealerts.ai).\n","funding_links":[],"categories":["Python","Backtest + live trading","Curated List"],"sub_categories":["General purpose","Trading \u0026 Backtesting","Backtesting Frameworks (only support backtesting)","General-Purpose Machine Learning"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedtechre%2Fpybroker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedtechre%2Fpybroker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedtechre%2Fpybroker/lists"}