MyGit

edtechre/pybroker

Fork: 256 Star: 2067 (更新于 2024-11-19 21:12:03)

license: NOASSERTION

Language: Python .

Algorithmic Trading in Python with Machine Learning

最后发布版本: v1.2.4 ( 2024-09-23 05:59:38)

官方网址 GitHub网址

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

AI-Powered Stock News

Stay informed with AI-powered news on top trending stocks. See www.trendninja.ai for the latest updates!

最近版本更新:(数据更新于 2024-10-04 22:09:37)

2024-09-23 05:59:38 v1.2.4

2024-09-16 13:30:30 v1.2.3

2024-09-09 13:29:21 v1.2.2

2024-08-13 11:10:06 v1.2.1

2024-08-12 10:29:15 v1.1.40

2024-07-05 05:42:57 v1.1.39

2024-06-23 14:27:07 v1.1.38

2024-05-09 13:17:24 v1.1.37

2024-04-20 13:49:41 v1.1.36

2024-04-09 12:20:49 v1.1.35

主题(topics):

ai, algorithmic-trading, algotrading, artificial-intelligence, backtesting, crypto, cryptocurrency, data-science, finance, framework, investment, machine-learning, python, quantitative-finance, stocks, trading, trading-strategies

edtechre/pybroker同语言 Python最近更新仓库

2024-11-23 07:15:18 comfyanonymous/ComfyUI

2024-11-23 02:05:08 hect0x7/JMComic-Crawler-Python

2024-11-22 19:26:55 ultralytics/ultralytics

2024-11-22 19:09:02 xtekky/gpt4free

2024-11-22 18:58:34 home-assistant/core

2024-11-22 08:12:43 jxxghp/MoviePilot