5 ms·
Show HN: PyBroker – Algotrading in Python with Machine Learning
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 https://www.pybroker.com. All of the code is available on Github using the link above.
Thanks for reading!
- tripleaaa 4y ago[flagged]
- smabie 4y agoLooks cool! Is this being used in production by any prop firm/asset manager?
- pyfreak182 4y agoThank you! Not to my knowledge, I recently released this publicly.
- htrp 4y agoMost prop shops / algo desks write their code in low level C.....
- pyfreak182 4y agoRight 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.
- smabie 4y agoit really depends C++ is more popular than C tho Also research is often done in Python
- zainhoda 4y agoThis looks awesome! I might try giving it a front-end using https://www.pycob.com https://www.pycob.com
- pyfreak182 4y agoThanks! Interesting, I will have to take a look at this tool.
- KRAKRISMOTT 4y agoAn open source alternative https://github.com/flet-dev/flet https://github.com/flet-dev/flet
- zainhoda 4y agoPycob is also open source https://github.com/pycob/pycob https://github.com/pycob/pycob
- wwasilev 4y agoI 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.
- pyfreak182 4y agoYou 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%20a%20Custom%20Data%20Source.html 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%20and%20Position%20Sizing.html#Ranking-Ticker-Symbols https://www.pybroker.com/en/latest/notebooks/4.%20Ranking%20...
- wwasilev 4y agoBravo!
- stevespang 4y ago[dead]
- KRAKRISMOTT 4y agoIf 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 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.
- pyfreak182 4y agoThank 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%20a%20Custom%20Data%20Source.html https://www.pybroker.com/en/latest/notebooks/7.%20Creating%2... WRT trade execution, PyBroker is currently only designed for backtesting and analysis right now.
- atispor 4y agoFirst 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?