Using Machine Learning for Cryptocurrency Trading: Threshold Rebalancing Case Study

Note: Each week this post will be updated to include the link to the most recent weeks blog post.

A quick Shrimpy history lesson…

Previously, Shrimpy ran a case study using Nomics Machine Learning 7 day predictions that spanned 32 weeks. Over this time, we were able to gather a wealth of data regarding how Nomics predictions compare to a standard BTC hodl, an index consisting of the top 10 assets by market cap, and Coin Gecko’s score strategy. While we saw vastly different peak values between the 4 strategies we studied, they all ended around roughly the same value with Nomics predictions holding the lead for the entire duration of the case study.

Ultimately, we were forced to make a tough decision regarding our case study as Binance - which we were using to trade for the case study - banned customers residing in the United States. This left us with 2 options, migrate to a new exchange or come up with something of our own that we could use for these purposes. Given how exciting Machine Learning is, we eagerly chose the latter option and got to work.

This led to the development of our own Machine Learning prediction models, which you can read about here. Our own internal testing has shown significantly better results than our Nomics control portfolio, as you can see by the screenshots below.

The above screenshot shows the last 30 days performance of a Nomics Machine Learning portfolio, while the screenshot below shows the performance of a Shrimpy Machine Learning portfolio over the same time period and using the same automation settings.

04de2efe-adc9-4549-918a-7ebaf4d6c771.png

As you can see, there is a significant difference in the performance between these 2 portfolios with our own predictions outperforming Nomics, and we found this extremely exciting as we were generally impressed with the results posted by Nomics during our previous case study.

We had some answers from our previous case study, but we still have more questions

Due to this, this particular case study is being conducted in a slightly different manner than our previous case study in hopes of satiating our curiosity.

Now, let’s get to the good stuff!

Study Timeline

The study will begin on Tuesday, August 10 at 00:00 UTC. There will not be any hard ending date for the study. We would like to continue the study for as long as people remain interested in the results. That could be 4 weeks, 6 months, or even a year.

Strategies

In this study, we will use a variety of different strategies to compare portfolio performance. Each week, we will publish an update on the performance we saw from the previous week. The updates will include comparisons between the different strategies, highlight different decisions that were made, and draw conclusions about how individual trades have been impacting the performance of the portfolio.

Each strategy will utilize Threshold Rebalancing set at 15%, and stop losses will not be utilized for this case study.

Each strategy will begin with a portfolio value of $1,000. Although most of the discussion will revolve around performance, it will be exciting to follow a tangible dollar value for the results over the next few months.

Shrimpy Machine Learning

The Shrimpy ML Strategy leverages the 7-day price predictions generated by the Shrimpy ML engine. These price predictions are then used to determine which assets should be placed into our portfolio for this week. Although the 7-day predictions are still in beta, we were excited to participate in the development of new strategies for price analysis.

Methodology

Our team would like to keep the methodology for how we test the Shrimpy ML predictions as easy as possible. That way anyone who follows along with our study can reproduce the results.

At 5 pm Pacific Time each Monday (Tuesday, 00:00 UTC), our team will collect the latest data from the Shrimpy ML predictions. This will be done using a script that is provided at the bottom of this post.

The top ten assets with the highest predicted increases will be included in the portfolio for that week. Each asset will be given 10% of the total value of the portfolio.

Restrictions:

  • Only assets in the top 100 by market cap will be considered.

  • Only assets listed on KuCoin will be considered.

  • Only assets with a market spread of less than 10% will be considered.

  • Stablecoins will not be considered unless there are assets in the top 10 that have negative percent predictions. In this case, 10% of the portfolio value will be granted to USDT for each asset in the top 10 that has a predicted percent change of less than 0%.

Nomics Machine Learning

d4202ac4-2a50-4405-ab0a-becfc33e6d0a.png

This image depicts the top assets by market cap as calculated by Nomics.

The Nomics ML strategy uses a long short-term memory (LSTM) machine learning model to predict the 7-day price movement of each asset. LSTM is used in the field of deep learning to process, classify, and make predictions based on time series data.

Learn more about long short-term memory.

Methodology

Our team would also like to keep the methodology for how we test the Nomics ML predictions as easy as possible. That way anyone who follows along with our study can reproduce the results.

At 5 pm Pacific Time each Monday (Tuesday, 00:00 UTC), our team will collect the latest data from the Nomics ML predictions. Based on the predictions for the week, we will sort the assets in descending order based on the highest to lowest predicted percent price increase. The asset that has the highest predicted percent increase will be listed first, the one with the lowest predicted percent increase will be listed last.

The top ten assets with the highest predicted increases will be included in the portfolio for that week. Each asset will be given 10% of the total value of the portfolio.

Restrictions:

  • Only assets in the top 100 by market cap will be considered.

  • Only assets listed on KuCoin will be considered.

  • Only assets with a market spread of less than 10% will be considered.

  • Stablecoins will not be considered unless there are assets in the top 10 that have negative percent predictions. In this case, 10% of the portfolio value will be granted to USDT for each asset in the top 10 that has a predicted percent change of less than 0%.

Once the target allocations for the portfolio have been selected, a single rebalance will be executed to allocate the desired portfolio and return all assets to a 10% target allocation.

DeFi Index

DeFi is an absolute monster of an asset class, and has posted some impressive numbers now that institutional investment firms have taken notice and gotten their feet wet.

Methodology

The following settings will be used for the DeFi Index:

  • Weighting Method: Market Cap

  • Asset Range: 1-10

  • Min Allocation: 5%

  • Max Allocation: 25%

  • Buffer Zone: 5%

  • Asset Types: DeFi

  • Rebalance Frequency: Threshold, 15%

Restrictions:

  • Only assets listed on KuCoin will be considered.

  • Only assets with a market spread of less than 10% will be considered.

  • Stablecoins will not be considered.

Smart Contracts Index

Smart Contracts are one of the more interesting uses of blockchain technology with a wide range of industries that can be affected positively by this new asset class.

Methodology

The following settings will be used for the Smart Contracts Index:

  • Weighting Method: Market Cap

  • Asset Range: 1-10

  • Min Allocation: 5%

  • Max Allocation: 25%

  • Buffer Zone: 5%

  • Asset Types: Smart contracts

  • Rebalance Frequency: Threshold, 15%

Restrictions:

  • Only assets listed on KuCoin will be considered.

  • Only assets with a market spread of less than 10% will be considered.

  • Stablecoins will not be considered.

Portfolio Allocation & Rebalancing

The Shrimpy Portfolio Management application will be used for the allocation of portfolios, rebalancing, and performance tracking. Each of these functionalities is core to the Shrimpy platform and makes it the ideal service for running this study.

Portfolio Rebalancing for Cryptocurrency

Portfolio Rebalancing Algorithms in Crypto

Script Automation

To simplify the process of updating our portfolio with the latest price forecasts, we can automate the collection of the data through scripts that collect data from the API.

We can do this automation with Python. In the following sections, we will outline the process for setting up your Python environment and running your first script.

Python Environment

Setting Up Our Python Environment

There are a few things we will need to set up for our Python environment before we can start coding. First, start by installing the Shrimpy Python Library.

1pip install shrimpy-python


Note: The Shrimpy Python Library is designed to work with Python3. If you are using Python2, please update your version of Python.

Sign up for Shrimpy

Go to the Shrimpy Developer API website here. Sign up for an account.

Generate & Store Developer API Keys

Before we can start using the Shrimpy APIs, we will need to generate our API keys. This can be done by logging into your Shrimpy Developer account and going to the “API Keys” tab. Select the button to “Create Api Master Key”.

25e7166b-b9e2-40d6-97d8-bc41920cf5dc.jpg

Select “Create Api Master Key”.

Once you select the “Create Api Master Key” button, you will be prompted to verify your account by entering your password and 6 digit 2FA. If you have not yet enabled 2FA for your account, you will first need to go through the process of setting up 2FA.

1ccf3cd2-bd58-4c8a-8398-a8f650812360.jpg

Enter your 6-digit verification code and account password.

Once you have verified your account, Shrimpy will send you an email that will require you to confirm the creation of the API key.

Confirm your email by clicking on the link in the verification email.

After confirming the creation of the API key in your email, you can then see a card that represents your developer API key. The public key will be displayed by default.

70b771eb-d7f7-48d7-b0a4-a91ad7f40afb.jpg

Select to “Show” the private API key. This can only be done one time, so securely store the secret key once it has been shown.

Select to “Show” the private key. The private key will not be shown by default and can only be viewed ONE time. That means after you view your private key, Shrimpy will never show you the key again. If you don’t securely store the private key, you will need to go through the process of creating a new key. Once you select to “Show” the private API key, you will be prompted again to confirm your account by entering your 2FA code and password.

Copy both the public and private (secret) keys to secure locations.

Once the private API key has been shown, copy both the public and private API keys to a secure location. Do not ever share this API key with anyone.

Before we are done with the API key setup, select to enable all of the permissions on the API key. We will use all of the settings for this tutorial guide, however, you can reconfigure your setup once you are ready to deploy your production version of your trading bot. During testing, we won’t require any complex setup.

Note: You can create multiple API keys. If you want to have one set of API keys with only “Data” permissions, one set with only “Account” permissions, and one with “User” permissions, you are welcome to set up your keys any way you want.

Enable all of the permissions on the API keys and select “Update”.

We don't need to buy any credits to test Shrimpy, but you can purchase credits at any time on the "Payment" tab. This will look something like the screenshot below.

bad6c4fc-c001-4b11-80f0-89ffaaba2bd1.png

Purchase credits when ready. Shrimpy will start you off with 500 free credits, so this tutorial won’t require any payment.

Before credits can be purchased, we first require you to link a payment method. After linking a payment method, you can enter the value of the credits you wish to purchase.

Once you’ve gone through all these steps, you can log out of your Shrimpy Developer API account. We won’t need anything else from our account at this time.

Price Forecast Script

import shrimpy # Assign API keys here public_key = '...' secret_key = '...' # Create the client client = shrimpy.ShrimpyApiClient(public_key, secret_key) # Specify the exchange you want to collect predictions for exchange = 'binance' # Retrieve all of the trading pairs for the exchange trading_pairs = client.get_trading_pairs(exchange) predictions = [] # We will filter out any predictions that are not for USDT trading pairs # For any asset with a USDT trading pair, we will retrieve the prediction and calculate # the forecasted percent increase. We will place these predictions all into a single # object that we will sort to come up with a list of the highest predicted assets. for pair in trading_pairs: if pair['quoteTradingSymbol'] == 'USDT': try: prediction = client.get_predictions(exchange, pair['baseTradingSymbol'], pair['quoteTradingSymbol']) p_arr = prediction['predictions'] percent_gain = ((float(p_arr[-1]['prediction']) - float(p_arr[0]['prediction'])) / float(p_arr[0]['prediction'])) * 100 predictions.append((pair['baseTradingSymbol'], percent_gain)) except: print('no prediction data for pair') # Sort the predictions and put them into an object. You can print this object to get the # assets with the highest predictions. sorted_predictions = sorted(predictions, key=lambda tup: tup[1], reverse=True)

With these predictions, we can allocate our portfolio each week and track performance. Over the course of the coming weeks, we might extend this script to include other functionality such as automatically updating our Shrimpy portfolio. That way the entire process can be automated.

Follow us on Youtube, Twitter and Facebook for updates, ask any questions to our amazing, active community on Discord or reach out to our Support staff via the blue Support button found in the bottom left corner of your Dashboard.

Thanks for stopping by!

The Shrimpy Team

Disclaimer

The Content is for informational purposes only, you should not construe any such information or other material as legal, tax, investment, financial, or other advice. Nothing contained on our Site constitutes a solicitation, recommendation, endorsement, or offer by Shrimpy or any third party service provider to buy or sell any securities or other financial instruments in this or in any other jurisdiction in which such solicitation or offer would be unlawful under the securities laws of such jurisdiction.

All Content on this site is information of a general nature and does not address the circumstances of any particular individual or entity. Nothing in the Site constitutes professional and/or financial advice, nor does any information on the Site constitute a comprehensive or complete statement of the matters discussed or the law relating thereto. You alone assume the sole responsibility of evaluating the merits and risks associated with the use of any information or other Content on the Site before making any decisions based on such information or other Content. In exchange for using the Site, you agree not to hold Shrimpy, its affiliates or any third party service provider liable for any possible claim for damages arising from any decision you make based on information or other Content made available to you through the Site.


Shrimpy is an account aggregating platform for cryptocurrency. It is designed for both professional and novice traders to come and learn about the growing crypto industry. Trade with ease, track your performance, and analyze the market. Shrimpy is the trusted platform for trading over $13B in digital assets.

Follow us on Twitter for updates!