Sirwin
Sirwin
Gemini

Analysing Cryptocurrency Using the Gemini API - Part III

By yyknosekai | yyknosekai | 22 Sep 2021


(This is Part III of an ongoing series on how to analyse cryptocurrency trends using Python and the Gemini API - read Part I and Part II if you haven't yet!)

If you've been following the series thus far, you should now have at least a year of daily price data for BTC in USD, all ready for analysis in a convenient Excel file. Let's remember that the end goal is to come up with an investment approach (e.g. buy into momentumbuy only on red days, a-dollar-a-day) for the coin of your choice and also to be able to generate key technical indicators about the coin you're interested in. In Part III of this series, we get our hands dirty with the various charts, technical indicators and summative statistics we can obtain from the daily price data.

101: Basic Interactive Charts

The most basic thing you could do with your daily price data is to plot a chart of Price vs Time, a simple time-series; but why stop at a static chart when Python allows you to plot an interactive chart? That would be a good base for us to start off our crypto-analysis - so just paste the following code snippet (remember that the script follows on from Part II):

## Importing new packages for data visualisation
import plotly.express as px

## Resetting the index of the "btc_prices" dataframe such that "time" is now a column...
btc_prices = btc_prices.reset_index()

## Generating the interactive BTC Price vs Time graph...
fig = px.line(btc_prices, x='time', y='high')
fig.show()

Once you execute the last statement, you'll end up with a pop-up that gives you an interactive chart - you can now mouseover the chart to view prices, and even zoom in on critical portions to examine the patterns in greater detail. This chart is obviously limited - it only shows the "high" BTC prices, but not the low or even the average - but it's a start.

I Like to Move It, Move It!

We can now build on the dataset to obtain more technical indicators that we can use to boost our chart. A common technical indicator is the 20 Day Simple Moving Average (20SMA), which folks tend to like to use to decide whether the price has dipped or risen beyond a certain support point. In order to obtain the 20SMA, we can simply use the rolling mean function on the closing prices to add a new column to our BTC price dataframe:

## Generating a 20-day rolling average...
btc_prices['20 SMA'] = btc_prices.close.rolling(20).mean()

 

Light Those Candles Like a Pro!

Also, no self-respecting technical analysis would ever just plot a chart of "high" prices against time. It's more common to plot candlestick charts where you see the typical greens and reds that show how the markets open and close on each day, and then superimpose the 20SMA against the candlesticks to see whether support has been broken or not.

Python supports this as well, with the Plotly package:

## Generating a candlestick chart...
fig = go.Figure(data=[go.Candlestick(x=btc_prices['time'], open=btc_prices['open'], high=btc_prices['high'], low=btc_prices['low'], close=btc_prices['close']), go.Scatter(x=btc_prices['time'], y=btc_prices['20 SMA'], line=dict(color='black', width=2))])

This generates a nice chart which you could use as a first barometer of when to first enter the market - if you assume that the 20SMA is a good gauge of a support region, then you shouldn't really be calling any drops a dip unless it drops past the 20SMA. (Of course, there are other ways to calculate a good support area, stick around for more!)

I suppose that's it for now - you've learnt quite a bit, so it's good to review and see if you can at least replicate the results. Next up, we'll be looking at how to calculate other important technical indicators, so hang around for more!

How do you rate this article?

8


yyknosekai
yyknosekai

Just a Secondary School Physics teacher in Singapore, interested in cryptocurrency.


yyknosekai
yyknosekai

I'm a Physics teacher living in Singapore. Interested in Python, data analytics and putting it to good use in analysing cryptocurrency trends and movements. Excited about the potential of blockchain technology and cryptocurrency, and glad to have an opportunity to share more on Publish0X!

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.