CoinTK

Bitcoin Trading Algorithm Backtesting and Analysis Toolkit

CoinTK -- An open-sourced framework for rapid prototyping and testing of Bitcoin trading strategies. Also check out BitBox Server, a webserver built on CoinTK for backtesting and dry running prototype strategies (remote control coming soon!), and BitBox iOS, an iOS APP integrated with the BitBox server for monitoring, analyzing, visualizing, and (soon) initializing backtests.

CoinTK keeps humans in the loop by providing them with the analysis and visualizations they need to make informed decisions about the trading algorithms they use.


Getting Started

  1. Make sure python3 and python3-pip are installed:

    sudo apt install python3 python3-pip
  2. Clone and install cointk from pip

    sudo pip3 install cointk

    Or, if you prefer, install manually from this repository:

    cd && git clone https://github.com/cointk/cointk.git
    cd cointk
    sudo pip3 install .
  3. Initialize cointk

    cd && python3 -c 'import cointk.init'
  4. Start writing strategies! As an example, try backtesting the naive strategy included in cointk

    cd && mkdir -p plots histories

    Create ~/naive.py with the following contents:

    # ~/naive.py
    from cointk.backtest import backtest
    from cointk.strategies import NaiveStrategy
    
    strategy = NaiveStrategy()
    backtest(strategy)

    Run the script:

    python3 naive.py

    You should see something like this pop up in a browser window:

    Naive Backtest Output

    From here, you can play around with different strategies and testing parameters via scripts in backtests, or start thinking about making your own strategy.

    Happy developing!

Example strategies

We've implemented a few example strategies and backtested them on the automatically downloaded coinbase to USD dataset, with many more to come.

File structures

Creating your own strategies

To create your own strategy, create a class similar to one of the sample strategies given: Naive, Reverse Naive, Random, and Exponential Moving Averages. It should inherit the Strategy class (defined here) and have a

    gen_order(self, ts, price, qty, funds, balance):

function that decides, given the tuple (ts, price, qty) and any past histories stored in the Strategy class, whether to buy or sell.

Contributing

Like what you see? Check out our contributing guide to see how you can help!

License

CoinTK is MIT licensed.