Introduction

Automated trading strategies are advantagous because they remove human bias, stringently adhereing to pre-defined rules on how to enter and exit the market. Additionally, they are inherently reactive to real time data, which is impractical for many investors who are unable to constantly monitor markets. Developing an automated trading strategy requires ‘backtesting’ against historical data for both design and validation. In practice, both design and validation processes require many backtests to optimize for increased profitability and minimized risk. This python pacakge streamlines the development and deploylment of Backtested & Optimized Automated Trading Strategies (BOATS).

Features:

  1. Historical and real time market data acquisition

  2. Local database for maintaining historical data

  3. Technical Indicators library (Moving averages, RSI, Bollinger Bands, etc)

  4. Compatibility with 3rd party software and data

  5. Simulated broker model

  6. Fast and parrallizable backtesting routine (see Computational Performance)

  7. Performance metrics library (sharpe and calmer ratios, max drawdown, etc)

  8. Python SDKs for external broker APIs (Alpaca, Coinbase, more coming soon)

  9. Live testing and execution

  10. Graphical Visualization of backtests and live execution via matplotlib

  11. Strategy optimization routines: parameter scan, (gradient descent, random forest, and other optimization algorithms coming soon)

  12. Periodic optimization strategy (see Active Optimization)

Package Structure and Concepts:

A trading Strategy is the logic on how to enter and exit market positions including the generation of any technical indicators used for the decision making process. Strategies are interchangable between Backtest and LiveExecution instances enabling the seamless transition from testing to deployment.

../_images/Backtest_LiveExec.png

Data is passed to backtest and maintained in live execution instances as Pandas.DataFrames with columns [datetime, open, high, low, close, volume]. The use of pandas leverages its efficiency for computing along large datasets, in this context additional technical indicators which are then appeneded to the dataframe. Additionality, it is easy to encorporate 3rd party data or software into pandas dataframes. For each ‘step’ in the backtest or execution process the strategy evaluates the signals, and accordingly generates orders which it then places with a broker.

The Broker class enforces common functionality to the BacktestBroker model, and live broker interfances (e.g. CoinbaseBroker and AlpacaBroker). Presently, this includes handling Order types: MarketOrder, LimitOrder, StopOrder, TrailingOrder, and informational inquiries regarding order status, and asset values. In this way, order generation and managment by strategies is kept independent of differences between different brokers and APIs.

../_images/OrderFlow.png

Optimizing your strategy:

Our thesis is that the ability to quickly iterate through new ideas and different market conditions will empower users to more efficiently develop a strategy which maximizes profitability and minimizes risk. To further accelerate that process optimization routines are provided which can generate many backtests, exploring strategy parameters, market condtions, or even different technical indicators. Backtests and optimization processes can even be built into strategies themselves; as with the active optimization strategy which periodically runs an optimization on the most recent data and chooses the best performing parameters to use subsequently.

Additional Resources:

  • See the Examples section for use cases of this package.

  • See the Modules section for detail on the each submodule.