📜 ⬆️ ⬇️

Selection: 6 open frameworks for creating backtesters of trading strategies in Python



In his article on QuantStart, expert in the development of financial applications Frank Smitana (Frank Smietana) spoke about the existing frameworks for creating software for backtesting trading strategies and gave some tips on choosing such tools. We adapted this useful material.

What is backtesting


Backtesting is called the “run” of the programmed trading strategy for real trading data that occurred in the past (“historical data”). This is an extremely important process that has the same meaning as the actual development of a strategy and its launch during real-time trading in real time. It is believed that high-quality testing on historical data helps to identify some of the shortcomings and bottlenecks of the trading system before it leads to massive losses.

In addition to backtesting, there is the concept of simulating a trading strategy. Simulation programs simulate the occurrence of conditions that should serve as triggers for making deals with a financial program — in this case, real-time mode is used.
')
Most of the frameworks described in this article contain not only the functionality of direct backtesting, but also provide certain opportunities for running simulations.

In the Python sphere, the situation with specialized software is quite good - the community has six open frameworks available for creating backtesting tools.

Before choosing a framework


Before proceeding to the selection of the framework and the development of a backtester, you should determine the requirements for the trading system as a whole. Among other things, there are the following important questions that require answers:


Components of the backtesting and optimization framework


Framework for creating backtesters, as a rule, include several components:


When developing strategies using technical indicators, developers try to choose the optimal set of parameters for each of them. For example, during testing, it may become clear that the use of intersections of 6 and 10-day moving averages leads to an increase in the profitability of the strategy when it is run on historical data in comparison with any other periods from 1 to 20 days. Simple calculations suggest that in this case it will be necessary to calculate 40 combinations of various parameters of possible intersections.

In the context of working with a portfolio, optimization implies finding the optimal weights for each of the assets, including tools that can be sold short or leverage is used to work with them. Periodically there should be a rebalancing of the portfolio, which is expressed in the conduct of additional transactions in order to bring it to the optimal form.

Another important element of optimization is the control of the size of open positions. This approach allows developers to simulate and analyze the impact of the use of leverage and dynamic scaling of positions on the overall effectiveness of the strategy.

Six Backtesting Framework for Python


Standard open backtesting platforms for Python usually have several common characteristics:


PyAlgoTrade


PyAlgoTrade is an already established framework that includes the ability to test both historical data and simulations in real-time. Supports data from Yahoo! Finance, Google Finance, NinjaTrade and any sources providing information in CSV (for example, Quandl). Supports orders types of market, limit, stop and stop limit.

PyAlgoTrade supports Bitcoin trading via Bitstamp, as well as real-time processing of information from Twitter.


bt - Backtesting for Python


The creators of the bt framework strive to facilitate the development of easily testable, flexible and reusable logic blocks of trading strategies, which should open up the possibility to create complex automated financial applications.

The framework is suitable for testing so-called portfolio-based strategies, including algorithms for portfolio weighting and rebalancing. Modifying strategies for launching at different time intervals and using different weights of tools in the portfolio requires minimal effort to change the code. In addition, bt is built into ffn - this is the popular financial library Python.


Backtrader


This platform is superbly documented, the developers maintain a blog and develop an active online community, whose members are happy to help find the answer to the interesting question. Backtrader supports various data formats, including CSV, Pandas DataFrames, realtime data feeds from several foreign brokers and various iterators. Data processing from different sources can be carried out simultaneously and even at different time intervals.


pysystemtrade


Rob Carver, pysystemtrade developer, published an excellent article on why he decided to create another Python backtesting framework, which listed the pros and cons of developing a new framework. pysystemtrade includes a number of important functions, such as optimization and calibration modules, and also allows you to implement fully automated futures trading.


Zipline


Zipline is an algorithmic trading simulator. You can work with it through the browser interface IPython Notebook. The system is an alternative to command line interface tools. The service is developed and maintained by the Quantopian project team, and it can be used both as a separate backtesting development tool and in conjunction with the Quantopian development and testing environment. The Zipline platform provides access to ten years of historical data on US stocks in 1-minute resolution, several options for importing information are also available.


QSTrader


Another framework with real trading functionality, launched by QuantStart, the founder of the resource for finance experts, Michael Halls-Moore. He wanted to create a tool that would be suitable for use by large hedge funds and private investors at the same time. Currently, the QSTrader supports “bar” data resolution ( OHLCV ) at different time intervals, however, the use of tick data is not yet available.

Both modes of operation (backtesting and real trading) are completely event-based, which allows you to quickly move from developing strategies to testing them and then launching them in a “combat” mode. One of the main advantages of the system is its modularity, which leaves ample opportunities for customizing the code.


Other materials on finance and stock market from ITI Capital :


Source: https://habr.com/ru/post/358692/


All Articles