Skip to main content

Automate and backtest on ohlcv data quickly

Project description

Fast Trade Python application

A library to do back-testing on currency data with generated strategies quickly and easily. The data comes from this project crypto-data.

Data

If you're looking for some data, here is almost every minute of 2018 of every pair from binance. Here is the each file individually zipped and here is the entire directory zipped, with each file as a zip. If you have any questions, please email me at fast_trade (at) jedm.dev.

Goals

  • run in less than 30s on average hardware
  • headless
  • extensible

Features

  • Extremely fast backtesting
  • ability to build complex strategies
  • ability to reproduce strategies since they are just a json file
  • can interface easily as an API, ex. put a web server in front and its an API

Install

python -m venv .fast_trade
source .fast_trade/bin/activate
pip install -r requirements.txt

Testing

python -m pytest

Available Indicators (graciously stolen from https://github.com/peerchemist/finta)

Output

The output its a tuple. The first object is a summary all the inputs and a summary of a performace of the model. It's all the information to run the simulation again. The second object is a Pandas Dataframe, which contains all of the data used in the simulation. This can be used to chart store.

Example output:

(
{
  "start_time": "2018-02-06 00:03:03",
  "time_time": "2018-02-06 23:59:03",
  "time_spent": "0:00:00.506799",
  "total_trades": 73,
  "total_tics": 288,
  "max_gain_perc": 6.589,
  "strategy": {
    "name": "example",
    "chart_period": "5m",
    "start": "",
    "stop": "",
    "enter": [
      [
        "close",
        ">",
        "short"
      ],
      [
        "rsi",
        ">",
        30
      ]
    ],
    "exit": [
      [
        "close",
        "<",
        "long"
      ],
      [
        "rsi",
        "<",
        70
      ]
    ],
    "indicators": [
      {
        "name": "short",
        "func": "ta.ema",
        "args": [
          7
        ],
        "df": "close"
      },
      {
        "name": "mid",
        "func": "ta.ema",
        "args": [
          21
        ],
        "df": "close"
      },
      {
        "name": "long",
        "func": "ta.ema",
        "args": [
          150
        ],
        "df": "close"
      },
      {
        "name": "rsi",
        "func": "ta.rsi",
        "args": [
          14
        ],
        "df": "close"
      }
    ]
  },
  "base_sum": {
    "start": 0,
    "end": 0.1392501,
    "max": 0.0
  },
  "aux_sum": {
    "start": 1000,
    "end": 0.0,
    "max": 1070.53608431
  }
},
DataFrame(...)
)

Strategy

The real goal of this project is to get to the point where these strategies can be generated and tested quickly and then be easily iterated on.

Below is an example of a very simple strategey. Basically, indicators are used to build a list of indicators to look at which must all be true to produce an enter or exit status for that tick. This can use any of the indicators build_data_frame.py

{
   "name": "example", // name or identifier of strategy
   "chart_period": "15m", // charting period
   "enter": [ // conditions required to ENTER a trade, all must be true
      [
         "close",
         ">",
         "short"
      ],
      [
        "rsi",
         ">",
         30
      ]
   ],
   "exit": [ // conditions required to EXIT a trade, all must be true
      [
         "close",
         "<",
         "mid"
      ],
      [
         "rsi",
         "<",
         60
      ]
   ],
   "indicators": [ // this is what you use in the enter/exit functions
      {
         "name": "short",
         "func": "ta.sma",
         "args": [7],
         "df": "close"
      },
      {
         "name": "mid",
         "func": "ta.sma",
         "args": [21],
         "df": "close"
      },
      {
         "name": "long",
         "func": "ta.sma",
         "args": [150],
         "df": "close"
      },
      {
         "name": "rsi",
         "func": "ta.rsi",
         "args": [14],
         "df": "close"
      }
   ]
}

Indicators

      {
         "name": "short", // indicator name
         "func": "ta.ema", // technical analysis function to be used
         "args": [12], // arguments to pass to the function
         "df": "close" // which column of the dataframe to look at
      }

Enter / Exit

   "enter": [
      [
         "close", // column of the dataframe to compare to
         ">", // logic to use to compare
         "short" // the name from the defined indicator
      ]
   ]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fast-trade-0.0.1.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

fast_trade-0.0.1-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file fast-trade-0.0.1.tar.gz.

File metadata

  • Download URL: fast-trade-0.0.1.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for fast-trade-0.0.1.tar.gz
Algorithm Hash digest
SHA256 a05bbbc33b1329a9d04e0988e6866103a8a4345fbe0851644558b5f651beba1e
MD5 e3e157aac2d3395f971d7f970d8753eb
BLAKE2b-256 f5061f8d924c064041d98fa718870b37dc08f4fb0a4e8bba70250eb738e99d2b

See more details on using hashes here.

File details

Details for the file fast_trade-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: fast_trade-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for fast_trade-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5bc006f3ac6ebd2e6c5f84ad9e5ab4cc5c926564fe191f84b99a6adba5a18e37
MD5 a38b04935059dbd6c7f91844b9abf1d3
BLAKE2b-256 413f3f7c066f00156240d36613e7ddd0009f9c1f4d9d75a21142e194d0558fd3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page