How to Predict Ethereum Price using Python and General Brownian Motion

Mohak Malhotra
Coinmonks
9 min readFeb 26, 2022

--

Source: Unsplash

Note: This article does not aim to provide any professional financial/investment advice. It is for educational purposes only.

I spend a lot of time building mathematical and machine learning models to create automated trading systems which generate alpha. This is a beginner-friendly tutorial and my aim with this is to invite people who are new to data science to use this as a learning exercise.

Today we will be using simulated random variables to predict Ethereum price. Consider this approach from a purely mathematical perspective because extremely accurate price predictions require more sophisticated inputs into a model such as market sentiment, socio-economic factors etc.

Before we jump into the math, I want to describe a few terms for those who are new here:

  • Monte Carlo Simulations: These are models which help us predict the probability of different outcomes when the intervention of random variables is present. They allow data scientists to build the distribution of assets that are too complex to model analytically. We will use Monte Carlo simulations in our modelling ( Here is a video explaining this with a simple example).
  • Process (in the context of data science!): A process is an event that evolves over time to achieve a goal, generally with a time period of 0 to T. During this time, events may be happening at various points along the way that may have an effect on the eventual value of the process.
  • Stochastic Process: a process that can be described by the change of some random variable over time, which may be either discrete or continuous.
  • Random Walk: In efficient markets, financial prices should display a random walk pattern. In the simplest terms, a random walk is a stochastic process that starts of with a score of 0. At each discrete event, there is a probability p chance you will increate the score by +1 and a (1-p) chance the score will decrease by 1. The event happens T times. In this case the expected value of T is 0 + T[p(+1) + (1-p)(-1)]
  • Markov Process: More precisely, financial market prices are assumed to follow a Markov process, which is a type of stochastic process where only the present value of a variable is relevant for predicting the future. The past is irrelevant.

Using simulations, we will first create synthetic variables which accurately reflect the risk factors driving the Ethereum price. These factors include crypto prices, stock prices, indexes, exchange rates, risk free returns as well as commodity prices.

The simulating Markov process mentioned above is developed using the following components:

The Wiener process

The Wiener process (also called Brownian motion) is a stochastic process {Wt}t≥0+ indexed by nonnegative real numbers t with the following properties:

In our case, It describes a variable Δz whose change is measured over the interval Δt such that its mean change is zero and variance is proportional to Δt:

If ε is a standard normal variable N(0, 1), this can be written as:

This is followed by the generalised Wiener process which describes a variable Δx built up from a Wiener process, with in addition a constant trend a per unit time and volatility b:

Next we have the Ito process which is an adapted stochastic process that can be expressed as the sum of an integral with respect to Brownian motion and an integral with respect to time like such:

A particular example of Ito process is the geometric Brownian motion (GBM), which is described for the variable S as:

GBM is useful in the modelling of stock prices over time when you feel that the percentage changes are independent and identically distributed. For instance, suppose that Xn is the price of some stock at time n.Then, it might be reasonable to suppose that Xn/Xn−1, n ≥ 1, are independent and identically distributed. The process is geometric because the trend and volatility terms are proportional to the current value of ΔS. This is generally applicable to Ethereum prices, which which rates of returns appear to be more stationary than raw dollar returns, S.

That’s most of the theory needed for our model. Before jumping into the python code, I want to show you a sample calculation.

In 2021, Ethereum had a return of 404.2%. In 2020 it was 464.1%, in 2019 it was -8.0% and in 2018 it was -82.7%. The average return is ~194%.

At the date publishing this article, the current ETH price is $2,708.11 USD. What is the process for the change in the bitcoin price over the next week?

The process is as follows:

where ε is a random draw from a standard normal distribution. If the interval is one week, or Δt = 1/52 = 0.01923, the mean is

μΔt = 1.94 × 0.01923 = 0.0373062

Ethereum currently has an average volatility of 72%, so:

σ√Δt= 0.72 × √0.01923 = 0.09984403837

This gives us:

ΔS = $2,708.11 x (0.0373062 + 0.09984403837 x ε)

For the process, we finally get:

ΔS = 101.029 + 270.389 × ε

Predicting Ethereum Price in Python

Now that we have our process equations, let’s start coding. I recommend having Python3+ for this. For our simulation, the process is approximated by small steps with a normal distribution with mean and variance given by:

To predict the future price of Ethereum, we will begin from the current price St and generate a sequence of independent standard normal variables ε, for i = 1, 2, . . . , n.

From the above equation, we get St +1 as

For St +n we get St which should have a log-like distribution.

We are setting up the drift (μ) as 0 percentage. In data science, drift is referred to statistical properties of the target variable changing over time. We have our volatility as ~70% which will be divided into 100 steps.

Therefore, The local expected return is μΔt = 0.0/100 = 0.0 and the volatility is 0.70 × √(1/100) = 0.07

Below is my python script set up. After initialisation, we will define 2 functions, the first one called RAND() which generates evenly distributed random numbers between 0 and 1. The next one is NORMINV, this calculates the inverse of the Cumulative Normal Distribution Function for x, and a supplied distribution mean & standard deviation.

When we print S, we get:

We are now initialising our pandas dataframe which looks like:

Now, let’s create the second column, which will be the realization of a uniform U(0, 1) variable, with the corresponding RAND() function.

Our next column will transform this variable into a normal variable with mean 0.0 and volatility of 0.07.

St+i price at step 0 is our initial Ethereum price: $2,708.11. Now we will create the General Brownian Motion process:

Using the above dataframe, we can simply get the price increment by multiplying the random variable by the previous price like such.

Finally, we will build the posteriori column for the Price St+i.

The process is repeated until the final price of Ethereum is reached at the 100th step.

This experiment can be repeated as often as needed. Define K as the number of replications, or random trials.

X axis is Steps into the future and the Y axis is the price of Ethereum

In the figure above, we see the first 10 trials. Each leads to a simulated final value SkT. This generates a distribution of simulated prices ST.

With an atomic simulation, the distribution is always normal, however, the more simulations we have the distribution tends to become logarithmic.

As you can see this model is great for modelling the future price of ethereum, however, there are a few issues with this approach.

Drawbacks of this approach:

  • Monte Carlo simulations heavily depend on the assumptions made which include the parameters, the type and shape of the distribution and the pricing functions
  • We assume the drift to be zero which is often not the case
  • We did not take into additional data vectors influencing an asset price such as news, public sentiment, financial activity etc.

This article was inspired by the works of Roi Polanitzer. I hope this was a good learning exercise and provided some good insights. On a daily basis, I’m heavily involved in research and development of creating machine learning models and algorithmic approaches to generate alpha. I’ve also been working on web3 and De-fi projects behind the scenes so expect more content on those topics soon!

Join Coinmonks Telegram Channel and Youtube Channel learn about crypto trading and investing

Also, Read

--

--