News for hackers. Stuff that matters.

Show HN: PyBroker – Algotrading in Python with Machine Learning

https://github.com/edtechre/pybroker

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!

( 15 comments | 3 points | on HN )
Re:Show HN: PyBroker – Algotrading in Python with Machine Le... by smabie on Thursday March 09, 2023 @06:21PM (#35088285)
Looks cool! Is this being used in production by any prop firm/asset manager?
Re:Show HN: PyBroker – Algotrading in Python with Machine Le... by pyfreak182 on Thursday March 09, 2023 @07:47PM (#35089045)
Thank you! Not to my knowledge, I recently released this publicly.
Re:Show HN: PyBroker – Algotrading in Python with Machine Le... by htrp on Thursday March 09, 2023 @11:15PM (#35090304)
Most prop shops / algo desks write their code in low level C.....
Re:Show HN: PyBroker – Algotrading in Python with Machine Le... by pyfreak182 on Thursday March 09, 2023 @11:46PM (#35090486)
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.
Re:Show HN: PyBroker – Algotrading in Python with Machine Le... by smabie on Thursday March 09, 2023 @11:51PM (#35090521)
it really depends

C++ is more popular than C tho

Also research is often done in Python

Re:Show HN: PyBroker – Algotrading in Python with Machine Le... by zainhoda on Thursday March 09, 2023 @07:18PM (#35088797)
This looks awesome! I might try giving it a front-end using https://www.pycob.com
Re:Show HN: PyBroker – Algotrading in Python with Machine Le... by pyfreak182 on Thursday March 09, 2023 @07:48PM (#35089053)
Thanks! Interesting, I will have to take a look at this tool.
Re:Show HN: PyBroker – Algotrading in Python with Machine Le... by KRAKRISMOTT on Friday March 10, 2023 @01:54AM (#35091270)
An open source alternative

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

Re:Show HN: PyBroker – Algotrading in Python with Machine Le... by zainhoda on Friday March 10, 2023 @08:03AM (#35093832)
Pycob is also open source

https://github.com/pycob/pycob

Re:Show HN: PyBroker – Algotrading in Python with Machine Le... by wwasilev on Thursday March 09, 2023 @08:01PM (#35089153)
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.
Re:Show HN: PyBroker – Algotrading in Python with Machine Le... by pyfreak182 on Thursday March 09, 2023 @08:06PM (#35089178)
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...

Re:Show HN: PyBroker – Algotrading in Python with Machine Le... by wwasilev on Thursday March 09, 2023 @08:55PM (#35089503)
Bravo!
Re:Show HN: PyBroker – Algotrading in Python with Machine Le... by KRAKRISMOTT on Friday March 10, 2023 @01:47AM (#35091225)
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.

Re:Show HN: PyBroker – Algotrading in Python with Machine Le... by pyfreak182 on Friday March 10, 2023 @02:11AM (#35091387)
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.

Re:Show HN: PyBroker – Algotrading in Python with Machine Le... by tripleaaa on Wednesday March 22, 2023 @10:37PM (#35269848)
Similar to yours, I've built APIs for investment research and algotrading that tracks companies employee growth, get unlimited historical count, track employee movement etc. https://nubela.co/blog/using-proxycurls-historic-linkedin-em...