CoinTK
[HackIllinois 17 Winner] Bitcoin Trading Algorithm Backtesting and Analysis Toolkit
Install / Use
/learn @CoinTK/CoinTKREADME
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
-
Make sure
python3andpython3-pipare installed:sudo apt install python3 python3-pip -
Clone and install
cointkfrom pipsudo pip3 install cointkOr, if you prefer, install manually from this repository:
cd && git clone https://github.com/cointk/cointk.git cd cointk sudo pip3 install . -
Initialize
cointkcd && python3 -c 'import cointk.init' -
Start writing strategies! As an example, try backtesting the naive strategy included in cointk
cd && mkdir -p plots historiesCreate
~/naive.pywith the following contents:# ~/naive.py from cointk.backtest import backtest from cointk.strategies import NaiveStrategy strategy = NaiveStrategy() backtest(strategy)Run the script:
python3 naive.pyYou should see something like this pop up in a browser window:

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.
- Naive: Very straightforwardly buy when more than a certain threshold of the previous
ntimesteps have seen an increase in price, sell when more than a certain threshold have seen an increase. - Reverse Naive: Amazingly, on some test sets, doing the exact opposite of what is described above performs better. This may serve to temper one's expectations with respect to trading algorithms–something completely crazy might work well on one particular dataset.

- Random: Similar to the reverse naive in purpose, we've included a random strategy that occasionally performs well on certain subsets of the training data.

- Exponential Moving Average (EMA): Here we use an a simple exponential moving average to approximate price trends. If the trend is going up (and crosses the current price) then sell, and if the trend is going down (and crosses the current price), then buy.

File structures
-
cointk/contains most of the algorithmic work-
strategies/contains different buying/selling strategies, which is just a decision framework based on the given state of price/quantity and past historiesprescient/contains strategies that have access to perfect information, i.e. all historical and future data. These are only useful for a Machine Learning extension we will build in the future, which we hope to train to model such a prescient strategy without having perfect informaiton.
-
-
example_backtests/tests our sample strategies running on historical data, so you can evaluate performance had you ran this strategy since the beginning -
plots/contain plots generated locally byplotly-- such as when you run backtest.py. -
trainings/contain support files forcointk/strategies/prescient, which will be flushed out with
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.
Related Skills
node-connect
349.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.5kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
