Marc Howard


How to Build a Crowdsourced Bitcoin Price Prediction Algorithm

What best predicts whether the price of Bitcoin will go up or down? What if there was an algorithm that could predict this at least a day in advance? This is what we’re building at the AlgoHive project and will be sharing how step-by-step.

Just a quick refresher this project began with my initial post on how I created a Bitcoin prediction algorithm that produces a 29% positive return:

This kicked off quite a few conversations on how best to improve and create a more robust algorithm. We now have a thriving community with investors, machine learning experts, data scientists and even beginners just wanting to follow along and learn more.

The first project we’re working on is how build a Bitcoin prediction algorithm that gives a Buy/Sell signal for a given date with the intention to maximize profits. One of our data scientist community members, Laura Vargas, an alumni of CodingNomads, is leading up the effort and is creating an open-source version of this BTC signal bot in GitHub.

What follows is our roadmap based on this code repository.

The Bitcoin Signal API Roadmap

Here is a quick glance at our roadmap:

What’s Under the Hood

The first step was determining the tools that will be used for the project. As this is an open-source project there were no shortage of great free tools to choose from most of which works seamlessly with the Python programming language.

Our tech stack is built on open-source technology that work well with the underlying Python programming language:

Pandas: an open source, BSD-licensed library providing high-performance, easy-to-use data structures and data analysis tools for the Python programming language:

Django: a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source:

PyTrends: provides a simple interface for automating the downloading of reports from Google Trends. Main feature is to allow the script to login to Google on your behalf to enable a higher rate limit:

Tableau Public: Data visualization of our charts is currently leveraging Tableau Public — a great free way to visual and share data:

Jupyter Notebook: An open-source web application that allows you to create and share documents that contain live code, equations, visualizations and narrative text. Uses include: data cleaning and transformation, numerical simulation, statistical modeling, data visualization, machine learning, and much more:

There’s lots of other components that you can see more in-depth. For full specs please see the requirements doc in our Github repo.

How We Created the v1 Release

Let’s walk through the setup steps as outlined in our roadmap:

Get historical transaction data for Bitcoin
There are many ways to obtain historical data for Bitcoin (BTC). In my original experiment I manually downloaded the crypto exchange data. In v1 we are automating the process by pulling BTC pricing data from the Nomics API. This is a REST and WebSocket JSON API which is lightning-fast, has no rate-limits and is completely free to use! Here’s part of it in our implementation:

Using the Nomics API

Get Google Trends data
For the Google Trends data I originally manually downloaded the .csv from the Google Trends site. Here in v1 we are automating using PyTrends, the unofficial Google Trends API. PyTrends is a Python library that scrapes Google Trends using custom parameters:

PyTrends API on GitHub

Import data into database
The project originally used PostgreSQL as the database but was changed to SQLite, a self-contained, high-reliability, embedded, full-featured, public-domain, SQL database engine. SQLite happens to also be the most used database engine in the world. Now that the calculations are processed in Python its no longer necessary to use PostgreSQL. In other words we can simply use a SQLite file instead of running a database server.

Identify Buy/Sell based on parameters identified in the article
My original article provides a Bitcoin Buy/Sell signal based on the combination of a Google Trends keyword ratio and BTC:USD price movement. This is going to be backtested further with more data from the PyTrends API.

The goal is to find which ratio and price delta best predicts the Bitcoin price. Past performance of course does not necessarily predict future performance however it will be insightful to test several methods. In v1 we’re simply testing a fixed ratio and price delta (and converting to more dynamic variables later):

Use Django to create API
Django, as mentioned earlier takes care of the front-end web development. This service is currently used to serve-up a basic JSON API running on an Apache httpd service.

Write API docs and publish

One of the last major v1 goals is to write-up the API documentation then publish in the GitHub repository. This will provide detailed instructions on how you can connect to our API to get BTC Buy/Sell signals. This API will serve as a Bitcoin signal bot that you can incorporate into your own trading algorithm or investment formula. Although we have most of the basics published this will be updated regularly based on improvements and new features.

Making Sense of the Data Through Visualization

Although most of what happens in the algorithm is buried in the code many of these elements and data sources can be visualized. For instance here is the graph of the Google Trends Ratio, Period Close Price and Investment Value based on my original formula — to be further enhanced in v2:

As this is refined we hope to better show positive or negative correlations to Bitcoin price and signals from other data sources. There is still lots of work to do to get to our first real MVP — a trading signal bot that will profit from Bitcoin price movement.

Next Steps and Upcoming Features

Although we have a long way to go we’re now just beginning work on v2 and since its open-source we’re inviting all though interested to contribute to the project. The good news is that you don’t have to necessarily be a coder to contribute. We are also beginning to compile a list of other ideas and data sources that we can eventually use for smarter price prediction. This first iteration primarily uses keyword indexing scores from Google Trends however there are several other sources that we will could incorporate including:

  • A larger array of Google Trends keywords
  • Sentiment analysis from Twitter
  • Reddit forum activity
  • Github repo activity
  • BitMex data (Short vs Long volume)

We may learn that there is no single best predictor of Bitcoin price appreciation or depreciation but some combination of a “golden ratio” instead. This is why we’re actively working on expanding our data sources and using machine learning to help backtest and expose predictive patterns in the data.

How to Get Involved

As we progress through our roadmap we’ll continue to share our progress and insights. The goal is to eventually release an API signal or bot that recommends Buy/Sell/Hold of Bitcoin at any given time to maximize profitability. This will have several use cases and the model can later be used to developed more advanced cryptocurrency prediction signals and indexes.

If any of this interests you there is tons of work to be done and we can certainly use your help! Here are a few ways that you can get involved and join us in our epic adventure to the moon 🌕:

  • Developers: Help improve the code by contributing to our Bitcoin Signal project on GitHub.
  • Machine Learning/Data Scientists: We’re starting to explore additional datasets and will need to perform a lot of backtesting, regression analyses and data modeling. Help us explore various data models to refine our algorithm. Join our growing Discord group here where all the magic happens!
  • Crypto Enthusiasts/Investors: Have any new feature ideas or trading strategies that we could test? While this project is still a work in progress we would love to hear about what features you would like to see.

In the meantime please share our project with anyone who you think may find this of value. To get the latest updates on our progress follow me here on Medium as I share how we’re building this together step-by-step. 🚀

Any feedback is most welcome!

More by Marc Howard

Topics of interest

More Related Stories