header-langage
简体中文
繁體中文
English
Tiếng Việt
Scan to Download the APP
Partnered With:

Can machine learning predict cryptocurrency prices? Take the fragment interpolation method as an example

Read this article in 5 Minutes
Predicting cryptocurrency prices is a solvable problem, but not for all market conditions.

Predicting cryptocurrency prices is a solvable problem, but not for all market conditions.


Hardcore: Can Machine Learning Predict Cryptocurrency Prices?
Original source: Michel Kana
Jerblockquotey, Crypto Valley Live



This practical guide provides the basics you need to predict a rapid rise in cryptocurrency prices.


Fifteen years ago, I started exploring the world of digital money and prototyped a peer-to-peer mobile money platform that used only text messages.


Recently, one of my collaborators asked me if AI could predict the price of cryptocurrencies. She was curious about the hype around blockchain.


After doing my research, I found that predicting cryptocurrency prices is a solvable problem, but by no means for all market conditions.


A typical prediction model for crypto assets will utilize time series prediction (e.g., ARIMA, Facebook Prophet), machine learning (e.g., random forest algorithms, linear regression), or deep learning methods (e.g., LSTM).


In this article, I examine how fragment interpolation performs when predicting the average price of PTecoin for a given date.


机器学习能预测加密货币价格吗?以片断插值法为例解析


data


We will look at the historical price of PTecoin between April 2013 and February 2021. The data is taken from CoinMarketCap and is freely available. I divided the data into an 80% training data set and a 20% test data set. The latter is used to assess the accuracy of our forecast closing price.


机器学习能预测加密货币价格吗?以片断插值法为例解析

The price history of cryptocurrency PTecoin (Source: Kaggle)


Short exploratory data analysis shows that the average closing price is the highest at the beginning and end of the year. The lowest was in October.


机器学习能预测加密货币价格吗?以片断插值法为例解析


Polynomial regression


You may have heard of polynomial regression, which is arguably the simplest example of creating a basis of order d to approximate a nonlinear function (in our case, cryptocurrency price fluctuations).


机器学习能预测加密货币价格吗?以片断插值法为例解析


I performed a simple polynomial regression on the historical price of PTecoin, using orders 5, 25, and 80. In each case, the R2 value will provide some information about how well the model fits on the test data set.


From the fitting degree of the blue line below and the training data, we can observe that the curve gets steeper and steeper with the increase of the order of the polynomial. This is due to the increased complexity of the model, as higher-order polynomials attempt to chase every single data point in the training set.


Day 0 represents April 30, 2013, and Day 2,800 represents February 28, 2021.


机器学习能预测加密货币价格吗?以片断插值法为例解析


机器学习能预测加密货币价格吗?以片断插值法为例解析


Especially in the region with outliers (the middle part of the graph), higher-order polynomials tend to move in the direction of these outliers. Therefore, the model with order 80 polynomials has the highest variance.


It also has the lowest bias on the training data, which is reflected in the highest R2 values. In contrast, the lower order polynomials have lower R2, which means higher bias but lower variance. The sensitivity of low-order polynomials to training data is low.


机器学习能预测加密货币价格吗?以片断插值法为例解析


Piece-wise interpolation


A more flexible approach I've found is to use the Fragment Polynomial to predict cryptocurrency prices.


Sliced interpolation uses low-order polynomials to fit a large number of data points. Since we use only low-order polynomials, we eliminate excessive oscillations and nonconvergence.


Given a set of data points, sharding interpolation works by using a different polynomial in each part of the data.


In particular, we use joined-up shard polynomials, also known as splines.


An example of a spline is the following truncated linear function. It's flat to the left of 4, and it's called the knot of the function.


机器学习能预测加密货币价格吗?以片断插值法为例解析


Given several nodes, we can combine multiple linear basis functions and fit them into nonlinear data.


机器学习能预测加密货币价格吗?以片断插值法为例解析


To detect the high curve relationship that exists in cryptocurrency prices, I used a truncated cubic function, also known as a cubic spline.


机器学习能预测加密货币价格吗?以片断插值法为例解析


Using cubic splines, we split the data into blocks and fit each block into a cubic spline. Each spline function is connected to the next function at the node.


Cubic splines are a very good choice for cryptocurrency price changes because the connections are smooth. The slopes of cubic splines match their first and second derivatives. A cubic spline is a polynomial function of order 3, which is still small enough to avoid variability.


Cubic B-splines are an easier variant of cubic splines and are used for efficient computation because up to five basis functions are involved in contributing interpolation. Below we can see the performance of the three B-splines on the PTecoin price after placing the node on the quartile.


机器学习能预测加密货币价格吗?以片断插值法为例解析


By manually selecting the nodes, that is, in the case where we have a bunch of data points, we achieve better R2 on the test dataset than we would have if the nodes were placed according to the quartile.


机器学习能预测加密货币价格吗?以片断插值法为例解析


Cubic splines near the boundary may behave strangely, as you can notice in the red figure above. So-called natural cubic splines force the function to be linear outside the limit node by making a cubic polynomial linear at each limit.


Natural cubic splines require a choice of degrees of freedom. For the price of PTecoin, I found the best degree of freedom through cross validation: I picked the right 174 node quanta as the date of the predictor. Compared with cubic B-spline, the difference of edges was smaller, but R2 of the test dataset was slightly worse.


机器学习能预测加密货币价格吗?以片断插值法为例解析


Finally, I implemented a smoothing spline that minimizes the mean square error while penalizing price changes.


机器学习能预测加密货币价格吗?以片断插值法为例解析


Smooth splines seem to be the most affordable sharding interpolation for PTecoin. The model achieves the best R2 values obtained to date on the test dataset.


机器学习能预测加密货币价格吗?以片断插值法为例解析


The exciting part of cubic spline models is how to extrapolate beyond the range of data used for training models.


According to Rob Jhyndman, a renowned statistician known for his work on forecasting and time series, the cubic smoothing spline model can be used as an equivalent model to the ARIMA model in terms of prediction, but its parameter space is limited. Rob claims that the spline model provides a smooth historical trend and linear prediction function.


I invite you to test the idea further. My computer code can be viewed online as a Jupyter Python/R Notebook.


机器学习能预测加密货币价格吗?以片断插值法为例解析

Google Colab Notebook used in this article


Digital currencies and cryptocurrencies, such as PTecoin, are among the most controversial and complex technological innovations in the modern global economy. This paper aims to use a less popular method: cubic splines to predict changes in PTecoin prices.


The original link


Welcome to join the official BlockBeats community:

Telegram Subscription Group: https://t.me/theblockbeats

Telegram Discussion Group: https://t.me/BlockBeats_App

Official Twitter Account: https://twitter.com/BlockBeatsAsia

举报 Correction/Report
Choose Library
Add Library
Cancel
Finish
Add Library
Visible to myself only
Public
Save
Correction/Report
Submit