랭킹으로 돌아가기

edtechre/pybroker

Pythonpybroker.com

Algorithmic Trading in Python with Machine Learning

algotradingbacktestingmachine-learningpythontradingquantitative-financestocksframeworkinvestmentaiartificial-intelligencealgorithmic-trading
스타 성장
스타
3.5k
포크
448
주간 성장
이슈
5
1k2k3k
2023년 1월2024년 3월2025년 5월2026년 7월
아티팩트PyPIpip install pybroker
README
PyBroker

python Apache 2.0 with Commons Clause Documentation Status Package status Downloads Github stars Twitter

Algorithmic Trading in Python with Machine Learning

Are you looking to enhance your trading strategies with the power of Python and machine learning? Then you need to check out PyBroker! This Python framework is designed for developing algorithmic trading strategies, with a focus on strategies that use machine learning. With PyBroker, you can easily create and fine-tune trading rules, build powerful models, and gain valuable insights into your strategy’s performance.

Key Features

  • A super-fast backtesting engine built in NumPy and accelerated with Numba.
  • The ability to create and execute trading rules and models across multiple instruments with ease.
  • Access to historical data from Alpaca, Yahoo Finance, AKShare, or from your own data provider.
  • The option to train and backtest models using Walkforward Analysis, which simulates how the strategy would perform during actual trading.
  • More reliable trading metrics that use randomized bootstrapping to provide more accurate results.
  • Caching of downloaded data, indicators, and models to speed up your development process.
  • Parallelized computations that enable faster performance.

With PyBroker, you'll have all the tools you need to create winning trading strategies backed by data and machine learning. Start using PyBroker today and take your trading to the next level!

Installation

PyBroker supports Python 3.9+ on Windows, Mac, and Linux. You can install PyBroker using pip:

   pip install -U lib-pybroker

Or you can clone the Git repository with:

   git clone https://github.com/edtechre/pybroker

A Quick Example

Get a glimpse of what backtesting with PyBroker looks like with these code snippets:

Rule-based Strategy:

   from pybroker import Strategy, YFinance, highest

   def exec_fn(ctx):
      # Get the rolling 10 day high.
      high_10d = ctx.indicator('high_10d')
      # Buy on a new 10 day high.
      if not ctx.long_pos() and high_10d[-1] > high_10d[-2]:
         ctx.buy_shares = 100
         # Hold the position for 5 days.
         ctx.hold_bars = 5
         # Set a stop loss of 2%.
         ctx.stop_loss_pct = 2

   strategy = Strategy(YFinance(), start_date='1/1/2022', end_date='7/1/2022')
   strategy.add_execution(
      exec_fn, ['AAPL', 'MSFT'], indicators=highest('high_10d', 'close', period=10))
   # Run the backtest after 20 days have passed.
   result = strategy.backtest(warmup=20)

Model-based Strategy:

   import pybroker
   from pybroker import Alpaca, Strategy

   def train_fn(train_data, test_data, ticker):
      # Train the model using indicators stored in train_data.
      ...
      return trained_model

   # Register the model and its training function with PyBroker.
   my_model = pybroker.model('my_model', train_fn, indicators=[...])

   def exec_fn(ctx):
      preds = ctx.preds('my_model')
      # Open a long position given my_model's latest prediction.
      if not ctx.long_pos() and preds[-1] > buy_threshold:
         ctx.buy_shares = 100
      # Close the long position given my_model's latest prediction.
      elif ctx.long_pos() and preds[-1] < sell_threshold:
         ctx.sell_all_shares()

   alpaca = Alpaca(api_key=..., api_secret=...)
   strategy = Strategy(alpaca, start_date='1/1/2022', end_date='7/1/2022')
   strategy.add_execution(exec_fn, ['AAPL', 'MSFT'], models=my_model)
   # Run Walkforward Analysis on 1 minute data using 5 windows with 50/50 train/test data.
   result = strategy.walkforward(timeframe='1m', windows=5, train_size=0.5)

User Guide

Online Documentation

The full reference documentation is hosted at www.pybroker.com.

(For Chinese users: 中文文档, courtesy of Albert King.)

Contact

Market-Moving Stock News & Alerts

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.

관련 저장소
vnpy/vnpy

基于Python的开源量化交易平台开发框架

PythonPyPIMIT Licensetradinginvestment
vnpy.com
43.4k12.2k
wilsonfreitas/awesome-quant

A curated list of insanely awesome libraries, packages and resources for Quants (Quantitative Finance)

HTMLfinancefinancial-data
wilsonfreitas.github.io/awesome-quant/
28.1k3.7k
hummingbot/hummingbot

Open source software that helps you create and deploy high-frequency crypto trading bots

PythonPyPIApache License 2.0cryptocurrencyarbitrage
hummingbot.org
19.2k4.8k
paperswithbacktest/awesome-systematic-trading

A curated list of awesome libraries, packages, strategies, books, blogs, tutorials for systematic trading.

PythonPyPIfinanceawesome
paperswithbacktest.com
8.6k1.2k
ranaroussi/quantstats

Portfolio analytics for quants, written in Python

PythonPyPIApache License 2.0quantalgotrading
7.5k1.2k
wondertrader/wondertrader

WonderTrader——量化研发交易一站式框架

C++MIT Licensectaquant
6.2k1.2k
Superalgos/Superalgos

Free, open-source crypto trading bot, automated bitcoin / cryptocurrency trading software, algorithmic trading bots. Visually design your crypto trading bot, leveraging an integrated charting system, data-mining, backtesting, paper trading, and multi-server crypto bot deployments.

JavaScriptnpmApache License 2.0open-sourcecrypto-trading-bots
superalgos.org
5.6k6k
nkaz001/hftbacktest

Free, open source, a high frequency trading and market making backtesting and trading bot, which accounts for limit orders, queue positions, and latencies, utilizing full tick data for trades and order books(Level-2 and Level-3), with real-world crypto trading examples for Binance and Bybit

Rustcrates.ioMIT Licensebacktestinghigh-frequency-trading
4.3k838
letianzj/QuantResearch

Quantitative analysis, strategies and backtests

Jupyter NotebookMIT Licensequantitative-financequantitative-trading
letianzj.github.io
3k572
Open-Trader/opentrader

🤖 Open-source crypto trading bot | 📈 DCA & GRID strategies | ✨ UI | ⭐ Star to support the project!

TypeScriptnpmApache License 2.0botcryptocurrency
opentrader.pro
2.8k323
blankly-finance/blankly

🚀 💸 Easily build, backtest and deploy your algo in just a few lines of code. Trade stocks, cryptos, and forex across exchanges w/ one package.

PythonPyPIGNU Lesser General Public License v3.0cryptocurrencybot-framework
package.blankly.finance
2.5k313
marketcalls/openalgo

Open Source Algo Trading Platform for Everyone

PythonPyPIGNU Affero General Public License v3.0algotradingamibroker
docs.openalgo.in
2.3k1.1k