Quantitative Trading Series Part 1: An Insight to Trading Digital Assets Utilising Machine Learning

Moses Dada CQF
Nov 1 · 7 min read

This marks the first part of The Quantitative Trading Series, where we aim to highlight some quantitative methods that can be applied when generating returns in the world of digital assets.

In this article, we will demonstrate just how well various machine learning algorithms perform when trading digital assets and compare them in terms of prediction accuracy and ultimately, returns. Here at Digital Alpha Research, our team have a deep passion for using data to unlock insights that power strategies for investment in digital assets.

Given liquidity is key for scalable strategies, as we continue throughout this series, we set out to demonstrate how we apply our thoughts to highly liquid digital assets.

To understand this article, prior knowledge of Ordinary Least Squares, Logistic Regression and Neural Networks, would certainly be useful. However, in the event that said concepts are not familiar, we will go on to state simple definitions of these techniques without stating the mathematical properties and solving from first principles.

Definitions

Definition 1: Ordinary Least Squares (OLS)

OLS is a method known for estimating the unknown parameters in a linear regression model. The goal of OLS is to closely “fit” a function with the data. It does so by minimising the sum of squared errors from the data.

Ordinary Least Squares Regression Equation

The regression equation presented above shows that each observation i includes a scalar response yᵢ and a column vector xᵢ of values of p predictors xᵢⱼ for j = 1, …, p. εs are unobserved scalar random variables or errors which account for influences upon the responses yᵢ.

Definition 2: The Logistic Model

The Logistic Model, also referred to as the Logit Model is an important machine learning algorithm used to model the probability of a certain class or event for binary outcomes, for example: Pass/Fail or Yes/No.

This linear relationship can be written in the following mathematical form:

Logistic Regression Equation

Where we have the Bernoulli response variable Y which is also denoted as p = P(Y=1), b the base of the logarithm, βᵢ the parameters of the model and x₁ and x₂ the predictors.

Definition 3: Neural Networks

Neural Networks are computing systems that are inspired by, but not identical to, biological neural networks that constitute the brain.

Neural Network Comparisons: Simple Neural Network vs. Deep Learning Neural Network

You can observe from the above graphical illustration, that deep learning neural network uses multiple layers to progressively extract higher level features from a raw input.

Implementation

To compute the logistic regression, the following technical indicators or features were used for prediction 1) Momentum and 2) Moving Averages (MA) with 9 Periods (MA9), 200 Periods (MA200) and Exponential Moving Average with 20 Periods (EMA20).

The data consists of 356 entries used as predictors, the prices at daily close, ranging from the dates 2016–01–01 to 2017–01–01. This is highlighted in the following formula:

Returns Calculation

The table below shows the features we mentioned in the article previously.

Output from Data Entries

It’s important to note, the use of CLASS LABELS here. Ultimately, these are a set of negative/positive or {-1,1} outcomes from the analysis, which is denoted as ReturnSign. Classification is done for our Returns indicator column yᵢ (Y_Response).

To get rid of NaN values we used ‘.dropna()’ and to exclude values where ReturnSign is 0, we computed the following:

data = data[(data[[‘ReturnSign’]] != 0).all(axis=1)]

These adjustments were made in order to exclusively have the following set of negative/positive or {-1,1} outcomes.

It is important to note this formula as part of logistic regression, C = 1/λ, where C is an Inverse Regularisation Parameter. This means C is a control variable that retains the strength modification of regularisation by being inversely positioned to the Lambda regulator.

We further build on this, by giving C a value of 100, using le2 as an in input. The relationship here, would be that lowering the value of C, would ultimately strengthen the Lambda regulator.

For Logistic Regression we obtained the following output:

Logit beta coefficients for Momentum, MA9, EMA20 and Close:
[[-0.01746924 -0.12784996 -0.00725277 0.13476256]]

Intercept:
[0.17564728]

model.classes_ = [-1. 1.]

This is mathematically represented as:

ReturnSign = 0.17564728 - (0.01746924 * Momentum) - (0.1784996 * MA9)- (0.00725277 * EMA20) + (0.13476256 * Close + εt)

Plotting The Sigmoid

A Sigmoid Function is a mathematical function having a characteristic “S”-shaped curve or Sigmoid Curve. Building upon the characteristics from this article, we then produce a plot: Data from each feature plotted against the set of negative/positive or {-1,1} value of Y (vertically).

To get values for the range {-1,1}, we then compute the Logistic Sigmoid Function:

def logistic_sigmoid(xb):
return (1 / (1 + np.exp(-xb)))

This is represented as:

The Sigmoid Function is plotted for Momentum, MA10, EMA20 and Close features.

‘np.linspace(X_min, X_max, 3000)’ generates 3,000 values in that range incrementally. We use the Logistic Sigmoid Function to get an alternative Sigmoid Function with X values from −1 to 1.

Sigmoid function of features

We can see from above illustration, the scatter plot points that are black are returns that are 1 and the scatter plot points that are white are -1. These are computed using the coefficient Beta. After observation we note the diagrams show 1) The linear regression plots well as it has a range of -1 and 1, 2)The logistic classifier didn’t classify well as the black scatter points are not on the red line of the Sigmoid Function and 3) The Momentum’ and MA9 features are inverted.

We move to further plot these features with a BTC/GBP chart below:

BTC/GBP prices from 2016–2017

The use of prior time steps to predict the next time step is called the sliding window method. For short, it may be called the window method in some literature. In statistics and time series analysis, this is called a lag.

With the above, we now we compute the returns and lags. Using the actual value of the next period return with the ‘PREDICTED’ sign , we multiply the close with the next day’s return with the predicted sign. This back-testing uses the benefit of hindsight, but the approach is logical one. It represents the P&L of the sequence of trades.

For the predictions we use as defined above, OLS Regression, Logistic Regression and Neural Networks for the BTC-GBP prices we are analysing. we obtain our neural networks returns by multiplying the BTC returns by the neural network predictions. We obtain our data from Yahoo!finance using the ticker BTC-GBP, utilising data points from 2016 to 2017.

A Comparison of Prediction Accuracy of Various Features

15 Lags

50 Lags

100 Lags

We can see that the more lags that we compute the higher the prediction accuracy.

Conclusion

Comparing all three machine learning methodologies demonstrated in this article, judging from the graphical illustrations and tables, we can conclude with a level of certainty that whilst Deep Neural Networks are by far more significant in producing trading profits, it comes at the expense of greater computational speed especially when we account for a greater number of features.

In the next part of the series, we will compute and compare the accuracy between 1) K-Cross and Stratified K-Cross Validations 2) Support Vector Machines (SVMs) and 3) Decision Trees/Random Forests. We will combine them with similar features such as Momentum and Moving Averages used in this article as well as more complex features such as Relative Strength Index (RSI) and Moving Average Convergence Divergence (MACD).

Given how nascent the asset class is, very few dedicated digital asset research providers currently exist. If you are interested in bespoke quantitative research, please visit https://digitalalpharesearch.com to get in touch with our team.

Digital Alpha Research

A quantitative research firm that provides digestible market and network insights on digital assets and related areas.

Moses Dada CQF

Written by

Quantitative analysis, Quantitative Trading and Machine Learning

Digital Alpha Research

A quantitative research firm that provides digestible market and network insights on digital assets and related areas.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade