Skip to content

Overview

robwsc edited this page Mar 27, 2023 · 2 revisions

Stratis is a python-based framework for developing and testing strategies, inspired by the simplicity of tradingview's Pinescript.

Users can create strategies, backtest them on data, and view the results in a UI. Using the REST API, users can also incorporate Stratis into their own workflows.

Core

The core of Stratis is a python-based FastAPI app that provides a REST API for the frontend. The frontend is a NextJS app that is served by the FastAPI app.

Building strategies and Backtesting

Users can create strategies using the manage.py script. This script provides a CLI for creating strategies.

Once a strategy is created, it can be edited by the user in the strategies folder. Utilizing the on_step, before and after decorators, users can create functions that run on every step of the data, before the strategy starts, and after the strategy ends. These functions can be used to create simple but powerful trading strategies.

Once a strategy is created, it can be backtested via the UI frontend by selecting the strategy and the data to backtest it on. The UI will then display the results of the backtest. Users can also create their own UI and workflows by utilizing Stratis's REST API.

Backtesting positions is done in parallel and is optimized for speed. This allows for strategies to be backtested on large amounts of data in a reasonable amount of time. Many of the builtin helper functions, like ta.sma() utilize numpy arrays to speed up the calculations.

Components

Stratis uses a number of components to create a framework for creating strategies and backtesting them on data.

  • OHLC

    • OHLC is a class that wraps a pandas dataframe of open, high, low and close data.
      You can read more about this class here.
  • DataAdapter

    • DataAdapter(s) are classes that are used to fetch data from a datasource. They create OHLC objects that are used by the strategy.
      You can read more about this class here
  • Strategy

    • Strategies use data from OHLC objects, and use the on_step decorator to create functions that run on every "step" of the data.
      You can read more about this class here
  • Backtest

    • Backtests use strategies and OHLC objects to run the strategy on the data. Backtests produce results that include the strategy's performance and the related Positions and Orders. You can read more about this class here

A basic overview of how these components work together might look like this:

# User requests data from the DataAdapter.  

# The DataAdapter fetches the data from the datasource, and returns an OHLC object.

ohlc = DataAdapter.get_data(file='data.csv')

# The user requests a Strategy and passes in the OHLC object.

# The Strategy runs the on_step methods using the OHLC object.

# The Strategy returns a Backtest object.

results = strategy = Strategy().run(ohlc)

Some less noteable but still important components include:

  • Position
  • Order
  • Parameter
Clone this wiki locally