Bitcoin Madness: How to Simulate Bitcoin Prices in Google Sheets by spreadstreet

View this thread on steempeak.com
· @spreadstreet · (edited)
Bitcoin Madness: How to Simulate Bitcoin Prices in Google Sheets
https://i.imgsafe.org/9d/9d384bd213.png

You know the scenario...

[Bitcoin had another huge increase](https://www.cnbc.com/2017/11/01/bitcoin-price-hits-6500-to-new-record-high-after-cme-futures-plan.html), but you missed the opportunity. You wanted to get in, but your gut instinct told you no. And rightfully so...no one knows where the price is going to go. What if you invested, and it had another 20% loss? These sort of price movements are common in the volatile world of cryptocurrencies.

Seriously...how far can this Bitcoin price really go?

## BITCOIN IS A VOLATILE BEAST

Risk analysis must be a part of every decision you make. 

You are constantly faced with uncertainty, ambiguity, and variability. Variability, in the case of Bitcoin, unlike anything we have ever seen before. And even though we have unprecedented access to information, we can’t accurately predict the future. 

Luckily, we have methods that enable you to see all the possible outcomes of your decisions, and assess the impact of risk.

## WHERE TO START?

Running simulations can prepare us for the worst.

![girlfriend simulator](//images.contentful.com/7dugnl5p37zn/4oJVJf8f2oUGuUMmIs8CY2/e31cfa36738f115d91773e2ce5f6046d/girlfriend_simulator.png)

Monte Carlo simulation (also known as the Monte Carlo Method) allows for better decision making under uncertainty.

One of the most common ways to estimate risk is the use of a Monte Carlo simulation (MCS). From Investopedia:

> For example, to calculate the value at risk (VaR) of a portfolio, we can run a Monte Carlo simulation that attempts to predict the worst likely loss for a portfolio given a confidence interval over a specified time horizon - we always need to specify two conditions for VaR: confidence and horizon. (For related reading, see The Uses And Limits Of Volatility and Introduction To Value At Risk (VAR) - Part 1 and Part 2.)
> 

A MCS can be run with many different models. Our own process will be:

1. Specify a model (for here, we will use geometric Brownian motion)
2. Get historical daily bitcoin prices
3. Calculate daily returns
4. Name the daily return range
5. Summary statistics
6. Simulate a year
7. Simulate a year many times
8. Multi-year summary statistics
9. Quick analysis of results

## STEP 1. WTF IS GEOMETRIC BROWNIAN MOTION?

The geometric Brownian motion (GBM) is a statistical method that is used heavily in the forecasting of stock prices. The reason the process is so attractive for this is because of the following:

- The change in price over one period of time is unrelated to the change in price over a disjoint period of time.
- The change in log(price) over any period of time is normally distributed with a distribution depending only on the length of the period.
- Samples of the distribution are continuous, with probability 100%.

The GBM is technically a Markov process, which is a fancy way of saying "A random process whose future probabilities are determined by its most recent values." Said another way, past price information is already incorporated and the next price movement is "conditionally independent" of past price movements.

Math geeks have a habit of making things infinitely more complicated than they have to be. I will do my best to make this as simple as possible.

The formula for GBM is as follows:

![gBm formula](//images.contentful.com/7dugnl5p37zn/LrTDGmxvAOQeMYgeaYqic/30e9e540b7bc2f18251cb5c5eda180d1/gBm_formula.png)

Where:
- B is the bitcoin price
- m or "mu" is the expected return
- s or "sigma" is the standard deviation of returns
- t is time
- e or "epsilon" is the random variable

This formula can be broken down into two very important terms: "drift" and "shock".

For each time period, our model assumes the price will "drift" up by the expected return. But the drift will be shocked (added or subtracted) by a random shock. The random shock will be the standard deviation "s" multiplied by a random number "e". This is simply a way of scaling the standard deviation.

## STEP 1A. THE THUNDER GOD ELI5

__The ELI5 version:__ The thunder god Zeus is a great god. A just god. 

But Zeus is subject to wild mood swings. 

Every day Zeus can shoot his magic lightning into the price of Bitcoin, and cause it to go up or down. 

Some days he is in such a good mood, that he shocks the price up by a random amount. On other days, he is in such a poor mood that he shocks the price down for opposing him. 

![Zeus Striking Down the Price](//images.contentful.com/7dugnl5p37zn/4RSAalRVews6gmGIQ6qyIS/26485672b8093aa0812da83c41f4d824/Zeus_Striking_Down_the_Price.png)

And thus, we have the essence of GBM: a series of steps with an expected upward drift, where each step is hit with a plus/minus shock (which is a function of the stock's standard deviation).

## STEP 2. HISTORICAL DAILY BITCOIN PRICES

[Copy the raw data scores from coinmarketcap](https://coinmarketcap.com/currencies/bitcoin/historical-data/). Paste the data into your own spreadsheet. 

For this exercise, your columns will be: Time, Open, Close, High, Low, Volume.

![Columns Setup OHLCV](//images.contentful.com/7dugnl5p37zn/10jP56H9pwOA84aUGkQCI2/a4fc36280df042514b832d7e831aaeea/Columns_Setup_OHLCV.png)

Want to automatically pull in Bitcoin prices? [Use the Spreadstreet Google Sheets Add-in](https://medium.com/spreadstreet/an-easy-way-to-connect-digital-currency-services-to-google-sheets-21f18301f881).

## STEP 3. CALCULATE DAILY RETURNS
Calculate daily returns from the "Close" price. in H2 put the formula:

    =LN(C2/B2)

Drag it all the way down to the end of the prices to fill the entire __Returns__ column

![Calculate Daily Returns](//images.contentful.com/7dugnl5p37zn/4j6Z64CEO4AQmwIsC6OMAk/e5eeba544f05e36b9d4cc12725c0e1c0/Calculate_Daily_Returns.png)

## STEP 4. NAME THE DAILY RETURNS RANGE

Create a named range from the returns column, called __returns__, to make our life easier. Highlight all the data in column H, i.e. cells H1:H1000, then click on the menu Data > Named ranges… and call the range __returns__:

![Name the range returns](//images.contentful.com/7dugnl5p37zn/31FBUkZCooEiuyUA8GQ8U8/cf055bf7aaaa7fa50ec403617afd19ad/Name_the_range_returns.png)

## STEP 5. SUMMARY STATISTICS

Set up a small summary table with the close, daily volatility, annual volatility, daily drift, annual drift, and mean drift of our population. The formulas are:

In K1, enter:

    =C2

and name it __close__.

In K2, enter:

    =STDEV(returns)

and name it __dailyVolatility__

In K3, enter:

    =dailyVolatility*SQRT(365)

and name it __annualVolatility__

In K4, enter:

    =AVERAGE(returns)

and name it __dailyDrift__

In K5, enter:

    =dailyDrift*365

and name it __annualDrift__

In K6, enter:

    =dailyDrift-0.5*dailyVolatility^2

and name it __meanDrift__

![Create Summary Statistics Table](//images.contentful.com/7dugnl5p37zn/66tFP39GYoouSAekiq8OMW/448ff1811f21a720683de38bd0961b98/Create_Summary_Statistics_Table.png)

## STEP 6. SIMULATE A YEAR

Setup the yearly simulation table with Time, Normdist, Log Return, and Simulated Price

### Time
In J12 put 0, and in J13 put:

    =J12+1

Drag it all the way down to your preferred forecast timeframe. Here I simulated a year (365 days), so I copied down to J377

![Time](//images.contentful.com/7dugnl5p37zn/2vst5P5dCg26qcIgwyiSMO/14637739ef5a52b12bc9fc95f57c0688/Time.png)

### Normdist

Let’s set up the normal distribution curve values.

Google Sheets has a formula NORMDIST which calculates the value of the normal distribution function for a given value, mean and standard deviation. Since we ascribe to the random walk theory, we want to use a mean of 0, and a standard deviation of 1.

In K13, put the formula:

    =NORMINV(RAND(),0,1)

Drag it all the way down to K377 to fill the whole __Normdist__ column:

![Normdist](//images.contentful.com/7dugnl5p37zn/66S0tGvf0WOoakkM0O24gC/a2112d9debeea813a95848ae17667163/Normdist.png)

### Log Return

To get the percentage of daily stock movement, we will calculate log return.

In L13, put the formula:

    =meanDrift+dailyVolatility*K13

Copy the formula all the way down to L377:

![Log Return](//images.contentful.com/7dugnl5p37zn/3lgtv92L3qCCgM0s6msmOK/5286ea3fb2514a7612241da504ab4b88/Log_Return.png)

### Simulated Price

Now to the real meat. Let's calculate the simulated Bitcoin price.

In M12 put the Close price, and in M13, put:

    =M12*EXP(L13)

Copy the formula all the way down to M377:

![Simulated Price](//images.contentful.com/7dugnl5p37zn/3XlCqDcJ9ussqsWQcgkicm/539b3791f0fede29f6c0b9ccd84d78d7/Simulated_Price.png)

### Forecasted Bitcoin price for one year

Let's see what the pricing data looks like. 

Select from M12 to M377, then Insert - Chart and select line chart:

![Simulated Price for One Year](//images.contentful.com/7dugnl5p37zn/5YzfLXLRks6aiI8oyiwIic/858a6d66affcd7661c53046dcceaf490/Simulated_Price_for_One_Year.png)

We have now successfully completed one simulation. And depending on your results, they could look normal...or downright crazy.

## STEP 7. SIMULATE A YEAR MANY TIMES

We completed one simulation, but we want to run many different trials. 

Create a scenario tab, setup a table to simulate 1,000 different one-year trials. In A3 to A1003, put the numbers 1 through 1000. 

In B3, put the formula:

    =Close*EXP((annualDrift-0.5*annualVolatility^2)+annualVolatility*norminv(rand(),0,1))

Copy the formula down all the way. Name this range "scores":

![Simulate Bitcoin Prices for Many Years](//images.contentful.com/7dugnl5p37zn/4TbShYFeRy8q0aMOq6Qcuo/5286ea3fb2514a7612241da504ab4b88/Simulate_Bitcoin_Prices_for_Many_Years.png)

## STEP 8. MULTI-YEAR SUMMARY STATISTICS

Set up a small summary table with the mean, median, standard deviation, min, max, and range of our new population. The formulas are:

    =AVERAGE(scores)

    =STDEVP(scores)

    =MIN(scores)

    =MAX(scores)

    =E6-E5

![Multiyear Summary Statistics](//images.contentful.com/7dugnl5p37zn/5sZ33tUsFiQIQkWeCg2cWY/37752cda5c3e5e650c96537f55216dd2/Multiyear_Summary_Statistics.png)

## STEP 9. QUICK ANALYSIS OF RESULTS

My results will look different than yours (due to the random nature of NORMDIST and the time you pulled the Bitcoin prices). But let's take a look at the results:

__Mean__	27,147.09
__Median__	16,097.74
__St. Dev__	37,243.84
__Min__	556.60
__Max__	479,586
__Range__	479,029
	
__3sd__	$1,486
__2sd__	$3,005
__1sd__	$5,850
__Current__	$16,098
__1sd__	$43,896
__2sd__	$81,998
__3sd__	$190,129

__How to read:__ We can be 95% certain that the price of Bitcoin will fall between $3,005, and $81,998 in one year.

__Wait really? Should I buy?__ No, this is not telling you to buy. This should be one tool of many to help you in your buying and risk decisions.

![Lognormal Distribution of Bitcoin Prices](//images.contentful.com/7dugnl5p37zn/1vQRO9FkgowIU220w4qM0A/6cd966edc5ac81be4445a376ab03d3df/Lognormal_Distribution_of_Bitcoin_Prices.png)

## CONCLUSION

You now know how to complete a geometric Brownian motion analysis of Bitcoin prices. Congratulations!

Good statistical analysis methods can be scary, but they don't have to be. Here we covered off on a great method for estimating future Bitcoin prices, which can also be applied to other cryptocurrencies.

With this new tool in place, you can be confident in your risk analysis methods by seeing all the possible outcomes of your decisions, and assess the impact of risk. 

Deliberate. Analytical. Intelligent.

## WANT YOUR OWN COPY?
[![Simulate Bitcoin Prices Download](//images.contentful.com/7dugnl5p37zn/1OKChLKXNq4e2oMUUkOgCE/59b42974c03d402a360919dda0ddd1a2/Simulate_Bitcoin_Prices_Download.png)](https://docs.google.com/spreadsheets/d/1LRPPLxzRhYiAbTVwltqMLIW_3Z2KXfD7SOPXWt3aI5g/edit?usp=sharing)

## RELATED POSTS

[High-Flyers and Shitcoins: What I Learned from Analyzing CoinMarketCap Data in Google Sheets](https://medium.com/@spreadstreet/high-flyers-and-shitcoins-what-i-learned-from-analyzing-coinmarketcap-data-in-google-sheets-d581dde5e225)

[7 Smart Ethereum Price Prediction Methods for HODL’ers](https://medium.com/@spreadstreet/7-smart-ethereum-price-prediction-methods-for-hodlers-7f08aad60cb1)

![Bio for Spreadstreet](//images.contentful.com/7dugnl5p37zn/5NgBYpFXH26o0u8UYCYs2W/41fa9a809d76cd635f7d9d99b066ce4d/Bio_for_Spreadstreet.png)
👍  , ,
properties (23)
post_id16,621,048
authorspreadstreet
permlinkbitcoin-madness-how-to-simulate-bitcoin-prices-in-google-sheets
categorybitcoin
json_metadata"{"app": "steemit/0.1", "format": "markdown", "links": ["https://www.cnbc.com/2017/11/01/bitcoin-price-hits-6500-to-new-record-high-after-cme-futures-plan.html", "https://coinmarketcap.com/currencies/bitcoin/historical-data/", "https://medium.com/spreadstreet/an-easy-way-to-connect-digital-currency-services-to-google-sheets-21f18301f881", "https://docs.google.com/spreadsheets/d/1LRPPLxzRhYiAbTVwltqMLIW_3Z2KXfD7SOPXWt3aI5g/edit?usp=sharing", "https://medium.com/@spreadstreet/high-flyers-and-shitcoins-what-i-learned-from-analyzing-coinmarketcap-data-in-google-sheets-d581dde5e225", "https://medium.com/@spreadstreet/7-smart-ethereum-price-prediction-methods-for-hodlers-7f08aad60cb1"], "image": ["https://i.imgsafe.org/9d/9d384bd213.png"], "tags": ["bitcoin", "bitcoinprices", "bitcoinpriceprediction"]}"
created2017-11-01 13:57:03
last_update2017-11-01 14:01:24
depth0
children1
net_rshares9,701,806,210
last_payout2017-11-08 13:57:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length12,313
author_reputation1,077,016,166
root_title"Bitcoin Madness: How to Simulate Bitcoin Prices in Google Sheets"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (3)
@steemitboard ·
Congratulations @spreadstreet! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

[![](https://steemitimages.com/70x80/http://steemitboard.com/notifications/firstcommented.png)](http://steemitboard.com/@spreadstreet) You got a First Reply

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click [here](https://steemit.com/@steemitboard)

If you no longer want to receive notifications, reply to this comment with the word `STOP`

> By upvoting this notification, you can help all Steemit users. Learn how [here](https://steemit.com/steemitboard/@steemitboard/http-i-cubeupload-com-7ciqeo-png)!
properties (22)
post_id16,637,428
authorsteemitboard
permlinksteemitboard-notify-spreadstreet-20171101t174353000z
categorybitcoin
json_metadata"{"image": ["https://steemitboard.com/img/notifications.png"]}"
created2017-11-01 17:43:51
last_update2017-11-01 17:43:51
depth1
children0
net_rshares0
last_payout2017-11-08 17:43:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length693
author_reputation38,705,954,145,809
root_title"Bitcoin Madness: How to Simulate Bitcoin Prices in Google Sheets"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000