Time Series Modeling of Bitcoin Prices
By: Paul Tune
Tags: Bitcoin, Time Series Analysis, Finance, Cryptocurrency, Time Series Forecasting

Bitcoin Price Models

Bitcoin has naturally attracted the attention of the public due to the potential of massive gains. It is then not surprising that there have been efforts to develop price forecasting models for Bitcoin and various cryptocurrencies. We’ll provide an overview of two models here.

One model relies on Metcalfe’s law, simply stated as

The value of a network is proportional to the square of the number of users in the network

The proposed model by Timothy Peterson and the follow-up paper applied Metcalfe’s law to Bitcoin. Since the value of Bitcoin is driven by the number of users, we would have to model the growth of users of Bitcoin. The model uses a Gompertz function to model the growth instead of a logistic function. For reference, the growth of the number of users at time t is given by

This function is fitted on the number of active Bitcoin addresses, as shown in the figure below. The forecast then serves as the foundation for the valuation of Bitcoin.

Forecasting the growth in Bitcoin users (source: paper)

The stock-to-flow model for Bitcoin (S2F) by the pseudonymous PlanB. It is considered a controversial model for its assumption: that Bitcoin is scarce, and therefore, the value is determined by how many coins there are in circulation (stock) and how many coins have been produced (flow).

Recent chart of the stock-to-flow model (source: LookIntoBitcoin)

A follow-up article by PlanB proposed a new stock-to-flow model with cross asset pricing. The model is still fundamentally similar to the initial S2F model. However, this model formulates Bitcoin as going through distinct phases like water. The four distinct phases are

the proof-of-concept phase

the payments phase

the E-gold phase

the financial asset phase

These clusters were found using a genetic search algorithm, with the price predictions coming from the aforementioned S2F model.

There have been arguments against the S2F model (see here). The model has been accused of being a “chameleon”, a model that has no basis in reality, but sounds plausible. Regardless, the model’s price predictions has been on point throughout the whole of 2020 to the present

As we have seen, like any new technology, Bitcoin and cryptocurrencies in general are hard to value because no one can know exactly what’s in store for the future. We expect a lot of uncertainty around pricing, and the large variance around pricing forecasts around Bitcoin reflects this uncertainty.

What is Prophet?

Prophet is a tool developed by Sean J. Taylor and Benjamin Letham at Facebook for large scale time series forecasting. It was developed to account for time series data encountered in businesses. The underlying model accounts for a long term trend, seasonality (daily, monthly and yearly), and holidays. As we shall see, this allows us to visualize the decomposition of the modelled time series once a fit is performed.

Methodology

For simplicity, we use Bitcoin prices at the open of the market. We set our starting date to be the 1st of January 2016. The end date of the training dataset is set to the 31st of December 2020. The test set is set from the 1st of January 2021 to the 12th of February 2021.

Our goal is to test how well Prophet fits on Bitcoin’s prices with and without additional side information.

Initial Forecasting Model

Our initial model only uses Bitcoin’s past price action to determine its future price. We will be using the Prophet’s Python API. Prophet is easy to use but it requires that your Pandas DataFrame is formatted with a Date and y column. In this case the y column is Bitcoin’s price in USD.

We denote our model by init_model . I explicitly set the daily seasonality to False because our data is in days and we don’t have a finer timescale to model fluctuations in a day.

Another important setting is to have seasonality_mode="multiplicative" . The reason for this is that Bitcoin’s seasonality fluctuations are increasing year-on-year, which fits a multiplicative model rather than an additive one.

init_model = Prophet(

daily_seasonality=False,

seasonality_mode="multiplicative",

)

init_model.fit(input_df)

No optimization of Prophet’s parameters were attempted. This forecast is the not the same as the forecast made here, since the forecast made there used an additive seasonality mode. I have also placed a hard constraint that price is at least $0. Another option to explore is to fit on the logarithm of Bitcoin’s price instead, which would ensure the constraint on the price is met.

Initial model forecast

Constraints on the forecasts are still work in progress in Prophet, so we will have to make do for now.

The fit is quite good on the training set. The R2 score for this model on the training set is 0.96. The root mean squared error (RMSE) is 946. However, the model unfortunately was not able to predict the recent run up in prices, but the trend is still going up.

Price predictions from the 25th of January till the 12th of Februrary for the initial model

Prophet provides a prediction yhat with lower and upper predictions (given by yhat_lower and yhat_upper respectively) . The predictions vastly underpredicts prices at the end of January compared to the current price of Bitcoin (which exceeded USD$50,000 as of writing).

Improving Forecasts with Side Information

We can do better.

The Bitcoin network itself possesses a wealth of information. These include the number of unique addresses, transaction volumes, total Bitcoins currently in circulation, and the gradual difficulty in mining through the hash rate. These information is up-to-date and publicly available from Quandl.

Moreover, macroeconomic factors do play a part in determining price. The overall market capitalization can be captured through the Standard and Poor’s (S&P) 500’s index. The US Treasury Bill rates captures the current interest rates, thereby providing an indicator of an appetite by investors for riskier assets. We can get these information from Yahoo! Finance.

Finally, given the buzz about Bitcoin, we can add search trend information from Google Trends.

We can see the correlation between the unique addresses with Bitcoin price over rolling 30-day windows. We can see that it is generally positive, so that would provide additional information to our price prediction.

Rolling 30 day window of correlation between the number of unique Bitcoin addresses and Bitcoin price

We can add regressors easily by calling the add_regressor method, as shown here:

extended_model = Prophet(

daily_seasonality=False,

seasonality_mode="multiplicative",

)

for col in input_df.columns:

if col not in ["ds", "y"]:

extended_model.add_regressor(col, mode="additive") extended_model.fit(input_df)

I have chosen the regressors to be additive. I have tested with multiplicative regressors, but the fit is far worse.

Forecasting model with additional data sources

The fit is marginally better than the previous model, with an R2 score of 0.97 with an RMSE of 822.

The price prediction given by this model still vastly under predicts the actual price.

Price predictions from the 25th of January till the 12th of Februrary for the new model

The departure from the from actual price could mean that we lack additional information, which the model cannot account for. For instance, we have not added sentiment data from social media, or news outlets. A good example would be a jump in Bitcoin price when Elon Musk announced that Tesla has bought $1.5 billion dollars in Bitcoin, as Tesla will now accept payments in Bitcoin.

It is important to note that a regressor is only useful if a good forecast of the regressor can be obtained. For example, we can assume the number of unique addresses to grow like predictions from a Gompertz curve, like in Peterson’s Metcalfe law-based model. So in practice, it would be important to find regressors that are stable and fairly easy to predict.

Model components

Recall that Prophet’s model assumes that there is a long term trend, seasonality, and holidays effects. We now visualize these components.

We can look at the decomposition of the forecast by a simple method call

fig = extended_model.plot_components(forecast)

which produces

We can see that the price is only trending up in the long term according to the model. Interestingly, prices are lower on the weekends than on weekdays. Moreover, prices also rise higher towards the end of the year to the start of the following year than other periods. We can also see the seasonality in the extra regressors we have added.

Bonus: Forecasting Ethereum’s price

We can also apply Prophet to Ethereum, a blockchain network with smart contract functionality. Here, I use the number of active addresses in the network and Google’s search trend sentiment.

Ethereum price forecast

More details can be found in the supplied code.

So What Do All of These Mean?

The famous physicist, Niels Bohr, is purported to have said

It is difficult to make predictions, especially about the future

Forecasting Bitcoin prices is no different. Who would have thought that Bitcoin would have its roots in an obscure whitepaper written by a anonymous author, to almost a trillion USD worth in market capitalization today? As with all things though, there are a few lessons we can gather from this exercise.

The first is that every forecasting model has a set of assumptions. These assumptions can be implicit or explicit, but they are there.

Peterson’s model assumes that Bitcoin is a network that follows Metcalfe’s law. PlanB’s model assumes that scarcity will ultimately be the deciding factor of Bitcoin’s value. In Prophet, the underlying model has an explicit structure: it has trend, seasonal and spurious (holiday) components. Deep learning models have other assumptions but they can be implicit due to their non-parameteric nature.

The strength of models with explicit structure is that it is easier to perform sensitivity analysis to test the robustness of the model under various scenarios. This is especially important in financial models, as this can spell disaster if an overoptimistic forecast is made.

The second is that forecasting by itself is only half the task. Often forecasting goes hand-in-hand with a decision. In this case, it would be a decision to buy, hold or sell Bitcoin. It would be wise to have models that produce a range and uncertainty bounds. In this way, when uncertainty is very high, allocation is lower with more diversification, so as to reduce the overall risk of a portfolio. Some methods such as reinforcement learning learns both the forecast and decision together, but that is a topic for another day.

Finally

Prophet is a very useful tool for time series forecasting, but like with every other model, the wielder of the tool has to check if her data matches the assumptions of the model. I hope that this article shows how additional information can be added to Prophet to make it more powerful.

Disclaimer

The thoughts and views expressed in this article are mine alone and do not reflect the view of Towards Data Science. This article is intended to be educational in nature and should not be construed as individual investment advice nor as a recommendation to buy, sell, or hold any security or to adopt any investment strategy.

Note from Towards Data Science’s editors: While we allow independent authors to publish articles in accordance with our rules and guidelines, we do not endorse each author’s contribution. You should not rely on an author’s works without seeking professional advice. See our Reader Terms for details.