Predicting interest rates for yield farming: wAgEr project

Vijay Lakshminarayanan
7 min readJul 14, 2020

TL;DR wAgEr predicts interest rates using ML techniques which helps yield farmers/traders. The project intends to be a part of the prediction market a building block in DeFi ecosystem.

Disclaimer: This article assumes that the reader is familiar with money markets and DeFi. A detailed intro can be found here. Please note that the article should not be considered as investment advice.

Fig 1: Yield formula

Basics: Interest rate is the amount charged for the use of an asset expressed as a percentage of principal. Annual percentage yield (APY) refers to interest earned including compound interest. Maximising return via APY by identifying the right asset to invest is the goal of the yield farmer. To be clear investing in a token for price speculation is not yield farming; lending on a money market like Aave for a return beyond price appreciation is yield farming

Building block of DeFi: Interest rate predictions

Total value locked up in DeFi as recorded by DeFi pulse has increased from 750 Million in April 2020 to 2.25 Billion on July 9 2020. Yield farming has been the rocket fuel behind this increase with about 70% of the value is locked up in lending platform. With under-collateralized peer to peer lending coming to Aave interest rates or prediction markets in general gain importance.

Prediction market as defined in CeFi or traditional finance is a collection of people speculating on a variety of events — exchange averages, commodity prices, quarterly sales results or even such things as election results. This is the market mechanism driving demand, locking up supply and aggregating disparate opinions about an asset value. An important subset of prediction market in CeFi is interest rates.

Why bother predicting interest rates??

Interest rates in DeFi: Bank of England, world economy

Bank rate is the building block of traditional economy and drives the interest rates calculations for assets, influencing spending decisions. This is set by the country based on a prediction model, and is an indicator of economic growth.

As shown on the left various countries have tried to predict the impact of Covid19 by cutting or reducing the interest rates (except Sweden which has a negative rate experience. However most forecasting models are no better than random walks. (Economic research publication)

As shown in the Bank of England chart, small changes were made to bank rate over a decade. By having an informed prediction of this movement, markets can preemptively adapt to changing conditions.

DeFi interest rates

Source: DeFi pulse, composite lending rates in a 1 year timeframe

In contrast to CeFi the DeFi market place exhibits a high degree of volatility in interest rates as shown by the 1 year composite rate shown in the chart. There is no “centralised” governing bank rate which provides direction and the required smoothing of the rates.

The volatility exhibited by the composite asset rates on stable coins makes the task of yield farmers perilous, and making the DeFi economy susceptible to spikes as shown in the chart above.. The goal of this project is to provide an indicator of interest rate direction, and predict interest rates. A series of machine learning techniques were reviewed, and forecasting techniques identified for application.

Interest rate Forecasting using machine learning techniques

Some things are easier to forecast than others. Sunrise time tomorrow morning can be forecast precisely. On the other hand, tomorrow’s lotto numbers cannot be forecast with any accuracy.

The predictability of an event depends on several factors mainly:

  1. how well we understand the factors that contribute to it;
  2. how much data is available;
  3. whether the forecasts can affect the thing we are trying to forecast.

In the case of interest rate predictions in DeFi this task is exacerbated by the volatility. At this nascent stage in DeFi (1) and (2) are somewhat well understood, there is significant amount of historical data which can be queried, and the factors affecting it are transparent in most money markets. There is no impact from (3) (At this point in time, however with mass adoption of wAgEr or equivalent prediction projects in the future this assumption will have an impact, and require a more complex model).

This is a marked difference from CeFi where forecasting interest rates is no better than random walks as confirmed by this study from European central bank, and thus presents an enormous opportunity.

The technique used in this project based on its applicability for DeFi assets is ARIMA. Detailed introduction can be found here.ARIMA stands for AutoRegressive Integrated Moving Average, a combination of auto-regression, differencing and moving average. There are two categories of ARIMA models seasonal and non-seasonal. Pursuing the non-seasonal option also referred to as ARIMA(p, d, q) where p=order of the autoregressive part; d=degree of first differencing involved; q=order of the moving average part.

Our aim is to train the model based on observed interest rate data, and arrive at the p,d,q values which have the best fit to the forecasted data. In an ideal case when dealing with data which is time series stationary, forecasted values and 95% confidence interval is shown below. This can be achieved by transposing the data either by time lag or successive differences i.e. preprocessing to achieve stationarity.

Forecasting stationary time series data with 95% confidence interval

wAgEr under the hood

Model Pipeline

The pipeline above shows how wAgEr works under the hood. The pipeline can be split into three stages: Acquire data, Machine learning, Endpoint/Dashboard.

Acquire data: In the first phase of the project Aave was used as the interest rate provider. Historical data of interest rates are necessary to build and train the ARIMA model explained in the previous section. vBR, sBR i.e. variable and stable borrowing rates are queried for the last 5000 values along with lending rates. This is performed using GraphQL. An excellent introduction on GraphQL can be found here, and there is also an article by Aave on how to use it here. This is quite useful for this project since we do not require custom endpoints, and makes it very easy for integration. Based on the experience from this project it’s easier to construct sample queries, and play around with the schemas here before working on Python or JS. Check out the python graphene library here.

Machine Learning:

The first step in the machine learning part of the pipeline is to transpose or preprocess the data. This is necessary to “cleanse” the data to make the features visible for analysis and form into a model. As explained in the previous section, DeFi interest rates when cleansed provide attributes which can be used for performing predictions. The first step in this cleansing could be a combination of performing a series of differentiations to achieve the d in the ARIMA(p,d,q) model. Normalisation can be achieved via a natural log factor, and the mathematical techniques are explained in detail in this paper.

Prediction result for DAI: Forecast vs sBR normalised past 100 days

Training the model involves using normalised data, and comparing it with the predictions to evaluate root mean squared error. As shown on the left the predictions using the trained ARIMA model with coefficients yield a close fit. In this case the trained DAI model was compared with April — June interest rates.

The final step involves using these normalised predictions, and converting them back to real world data. Basically repeating the steps involved preprocessing the data in the opposite direction such as integrating and exponent of the value.

Currently the model is still under verification but as shown in the prediction result, normalised values are very close to predicted values.

Endpoint/Dashboard

Endpoint is simply a table with a list of ML predicted interest rates. Currently the model is not yet live. Results will be available as a REST API endpoint. Currently the model is hosted on a digital ocean server, and the goal is to have it available along with a trading dashboard. Trading dashboard is under construction at wager.fyi. This will be online in the next few weeks.

--

--