Serving the Quantitative Finance Community

 
User avatar
TraderWalrus
Topic Author
Posts: 28
Joined: March 24th, 2017, 6:54 am

Python frameworks for backtesting

September 11th, 2023, 7:22 am

I want to move to Python for my backtesting and possibly auto trading as well. Considering leading frameworks. My requirements are:
  • An open source project on Github
  • Actively developed or at least actively supported with a large community
  • Stable
  • Flexible enough so I could easily implement processes such as walk-forward analysis
I am currently considering the following:
  • backtesting.py - very well known, large community, commonly mentioned as "easy to learn", however seem to get less "respect" then other project in terms of depth and looks like it's not actively developed or supported.
  • backtrader - well known, good forums (alhtough many say the admin isn't very nice), supposed to be less intuitive than backtesting.py but still not too complex, no "issues" tab in github, and again doesn't seem very active in dev.
  • vectorbt - claimed to be way faster then any other Python framework, which is well.. great... however the main issue there is it's a work of a single developer, who puts his energy mainly into the Pro (paid) version. Now, I don't have a big problem paying but I want the code to be 100% open and observable  by anyone, I don't see how it's possible for paid version.
The above comments are just my initial impression without actually working with any of those - I would appreciate your comments and recommendations regarding those or other frameworks you use. I also consider pysystemtrade and qstrader that seem to enjoy smaller following.
 
User avatar
tagoma
Posts: 2901
Joined: February 21st, 2010, 12:58 pm

Re: Python frameworks for backtesting

September 17th, 2023, 8:56 am

Hey TW.
I get to survey Python backesting every now an then. But there is nothing super exciting out there.
Several projects are not actively maintained and/or 1 man projects. Isn't it an hint that ... well... developing such tool is straightforward/fast, in which case one may be better off doing his/her thing?
FWIW Quantstart (btw the person behind this website happens to post on W) has a quick review of main backtesting frameworks in Python here, and somewhere else on their website they show the code / implement such a ligthweight backtesting environment (I cannot find it now, though).
Question mark is what features do you need? What securities are you trading (e.g. do they entail crazy trading fees calculations?)? Do you need some specific optimization routines? What kind of trading strategy have you developed? etc??
FWIW backtrader is the framework I have used the most. The code is very ugly and it pertains to the 20th Century. It is another 1 single individual project.
All above my (quasi-)random Sunday morning thoughts. Thanks.
 
User avatar
TraderWalrus
Topic Author
Posts: 28
Joined: March 24th, 2017, 6:54 am

Re: Python frameworks for backtesting

September 18th, 2023, 2:20 pm

Hey TW.
I get to survey Python backesting every now an then. But there is nothing super exciting out there.
Several projects are not actively maintained and/or 1 man projects. Isn't it an hint that ... well... developing such tool is straightforward/fast, in which case one may be better off doing his/her thing?
FWIW Quantstart (btw the person behind this website happens to post on W) has a quick review of main backtesting frameworks in Python here, and somewhere else on their website they show the code / implement such a ligthweight backtesting environment (I cannot find it now, though).
Question mark is what features do you need? What securities are you trading (e.g. do they entail crazy trading fees calculations?)? Do you need some specific optimization routines? What kind of trading strategy have you developed? etc??
FWIW backtrader is the framework I have used the most. The code is very ugly and it pertains to the 20th Century. It is another 1 single individual project.
All above my (quasi-)random Sunday morning thoughts. Thanks.
Thanks for the reply. Indeed the link you mentioned came up when I initially started my search and I went through the frameworks listed, ruled out those with very little following and narrowed it down further.

I started (after making my post above) by looking into backtrading.py and found it rather simplistic and limited. I then continued to backtrader which I am currently experimenting with, it looks pretty promising so far but still required a lot of work on my part. It seems there is hardly any existing code for easy analysis of optimization results (for example, processing the results of optstrategy), plus the optimization itself is rather basic (I'd look into other performance metrics, and I need to use more advanced optimization routines such as walk forward, then optimization on various symbols together, then optimization on several timeframes together - measures taken to increase sample size and reach a higher statistical significance). It does however look like a good place to start with other aspects of it having rich enough features. I guess I will give it at least a week or two more to evaluate and if it's too far from what I need I'll just start from scratch.