Hacker News new | ask | show | jobs
Show HN: PyBroker – Algotrading in Python with Machine Learning (github.com)
70 points by pyfreak182 1202 days ago
Hello, I am excited to share PyBroker with you, a free and open-source Python framework that I developed for creating algorithmic trading strategies, including those that utilize machine learning. With PyBroker, you can easily develop and fine-tune trading rules, build powerful ML models, and gain valuable insights into your strategy's performance.

Some of the key features of PyBroker include:

- A super-fast backtesting engine built using 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 and Yahoo Finance.

- The option to train and backtest models using Walkforward Analysis, which simulates how the strategy would perform during actual trading. The basic concept behind Walkforward Analysis is that it splits your historical data into multiple time windows and then "walks forward" in time in the same way that the strategy would be executed and retrained on new data in the real world. Walkforward Analysis also helps overcome the problem of data mining and overfitting by testing your strategy on out-of-sample data.

- More reliable trading metrics that use randomized bootstrapping to provide more accurate results. PyBroker calculates metrics such as Sharpe, Profit Factor, and max drawdown using bootstrapping, which randomly samples your strategy's returns to simulate thousands of alternate scenarios that could have happened. This allows you to test for statistical significance and have more confidence in the effectiveness of your strategy.

- Support for strategies that use ranking and flexible position sizing.

- Caching of downloaded data, indicators, and models to speed up your development process.

- Parallelized computations that enable faster performance.

- Additionally, I have written tutorials on the framework and some general algorithmic trading concepts that can be found on https://www.pybroker.com. All of the code is available on Github using the link above.

Thanks for reading!

5 comments

If you want people to take your framework seriously, I suggest adding integrations with some of the bigger data vendors on this list:

https://quantpedia.com/links-tools/?category=historical-data

If you want to remain beginner friendly, consider perhaps DataBento for data and interactive brokers for trade execution. You are doing your users no favors by pushing them towards Alpaca and Yahoo finance. Quant finance is not a poor man's game and if you want to do any significant research into market microstructure you need good data. Alpaca is for shilling trades for consumer fintech. At the professional level you should consider something like Interactive Brokers at the very minimum, you want a broker that offers greater control over order routing and trade execution.

Use IB-insync for the integration.

Thank you for your feedback. The Alpaca and Yahoo Finance APIs are provided as examples for convenience to help users get started with PyBroker, as they offer free data. However, PyBroker is data source agnostic, and it is possible to load data from any provider into a Pandas DataFrame and use it with PyBroker. See this notebook on creating custom data sources: https://www.pybroker.com/en/latest/notebooks/7.%20Creating%2...

WRT trade execution, PyBroker is currently only designed for backtesting and analysis right now.

I haven't looked at the code base, but any issues using this with fundamental data? Ideally, I would like to rank stocks based on reported items - retained earnings, sales, operating margins, etc.
You can use fundamental data by registering your own custom data columns with PyBroker. See this notebook for details on using your own data source: https://www.pybroker.com/en/latest/notebooks/7.%20Creating%2...

Once you do that, you can write a strategy that ranks stocks using your custom data. See this notebook about ranking: https://www.pybroker.com/en/latest/notebooks/4.%20Ranking%20...

Bravo!
This looks awesome! I might try giving it a front-end using https://www.pycob.com
Thanks! Interesting, I will have to take a look at this tool.
An open source alternative

https://github.com/flet-dev/flet

Pycob is also open source

https://github.com/pycob/pycob

First of all, kudos to making it open source and answering all questions. And, here's a dump question ;) why aren't you trying out it to make some real money?
Looks cool! Is this being used in production by any prop firm/asset manager?
Most prop shops / algo desks write their code in low level C.....
Right now this framework is designed for the research side of trading and not for execution, meaning it is intended to be used for analysis and modeling using Python.
it really depends

C++ is more popular than C tho

Also research is often done in Python

Thank you! Not to my knowledge, I recently released this publicly.