Bitcoin price analysis
In this topic, we will try to analyze Bitcoin data. There are many ways to view Bitcoin data; for example, it can be viewed on the Yahoo Finance website at https://finance.yahoo.com.
In this example, we use the Python programming language and Jupyter Notebook.
Here I will try to be brief and focus more on the sequence of the code without much explanation. The goal is to focus on the main idea.
Import libraries
from datetime import datetime
import os
import numpy as np
import pandas as pd
import seaborn as sns
import plotly.graph_objects as pob
import plotly.express as pex
import matplotlib.pyplot as plt #to deal with graphic charts
Data upload
df = pd.read_csv('BTC-USD.csv')
df.head(5)
Date | Open | High | Low | Close | Adj Close | Volume | |
---|---|---|---|---|---|---|---|
0 | 2014-09-17 | 465.864014 | 468.174011 | 452.421997 | 457.334015 | 457.334015 | 21056800.0 |
1 | 2014-09-18 | 456.859985 | 456.859985 | 413.104004 | 424.440002 | 424.440002 | 34483200.0 |
2 | 2014-09-19 | 424.102997 | 427.834991 | 384.532013 | 394.795990 | 394.795990 | 37919700.0 |
3 | 2014-09-20 | 394.673004 | 423.295990 | 389.882996 | 408.903992 | 408.903992 | 36863600.0 |
4 | 2014-09-21 | 408.084991 | 412.425995 | 393.181000 | 398.821014 | 398.821014 | 26580100.0 |
df.tail(5)
Date | Open | High | Low | Close | Adj Close | Volume | |
---|---|---|---|---|---|---|---|
3175 | 2023-05-28 | 26871.158203 | 28193.449219 | 26802.751953 | 28085.646484 | 28085.646484 | 1.454523e+10 |
3176 | 2023-05-29 | 28075.591797 | 28432.039063 | 27563.876953 | 27745.884766 | 27745.884766 | 1.518131e+10 |
3177 | 2023-05-30 | 27745.123047 | 28044.759766 | 27588.501953 | 27702.349609 | 27702.349609 | 1.325108e+10 |
3178 | 2023-05-31 | NaN | NaN | NaN | NaN | NaN | NaN |
3179 | 2023-06-01 | 27236.576172 | 27326.533203 | 27235.039063 | 27301.021484 | 27301.021484 | 1.596423e+10 |
#Description of the data
df.describe()
Open | High | Low | Close | Adj Close | Volume | |
---|---|---|---|---|---|---|
count | 3179.000000 | 3179.000000 | 3179.000000 | 3179.000000 | 3179.000000 | 3.179000e+03 |
mean | 13432.217640 | 13763.078443 | 13068.545810 | 13439.410714 | 13439.410714 | 1.659098e+10 |
std | 16028.349128 | 16432.296940 | 15565.365494 | 16025.439960 | 16025.439960 | 1.962819e+10 |
min | 176.897003 | 211.731003 | 171.509995 | 178.102997 | 178.102997 | 5.914570e+06 |
25% | 741.108002 | 750.089508 | 733.108490 | 741.312989 | 741.312989 | 1.219535e+08 |
50% | 7500.700195 | 7680.430176 | 7349.120117 | 7514.470215 | 7514.470215 | 9.744636e+09 |
75% | 19510.696289 | 20034.084961 | 19129.965821 | 19545.489258 | 19545.489258 | 2.776349e+10 |
max | 67549.734375 | 68789.625000 | 66382.062500 | 67566.828125 | 67566.828125 | 3.509679e+11 |
# to know more more information about the data
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 3180 entries, 0 to 3179
Data columns (total 7 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Date 3180 non-null object
1 Open 3179 non-null float64
2 High 3179 non-null float64
3 Low 3179 non-null float64
4 Close 3179 non-null float64
5 Adj Close 3179 non-null float64
6 Volume 3179 non-null float64
dtypes: float64(6), object(1)
memory usage: 174.0+ KB
# find null values
df.isnull().sum()
Date 0
Open 1
High 1
Low 1
Close 1
Adj Close 1
Volume 1
dtype: int64
#find duplicate values
df.duplicated().sum()
0
df = df.dropna()
Bitcoin Candle
fig = pob.Figure(data=[pob.Candlestick(x=df['Date'],open=df['Open'],
high=df['High'],low=df['Low'],
close=df['Close'],increasing_line_color= '#FF0000',
decreasing_line_color= '#00FF00')])
Correlation
#We will display heatmap

#We will display heatmap
corr = df.corr()
sns.set(rc = {'figure.figsize':(15,10)})
sns.heatmap(df.corr(), annot=True)
plt.show()
Open and Close Prices
fig = pex.line(df, x="Date", y=["Open","Close"],template = 'plotly',title='Open and Close Prices')
fig.data[0].line.color = "#00ff00"
fig.data[1].line.color = "#FF0000"
fig.show()
High and Low Prices
fig = pex.line(df, x="Date", y=["High","Low"],template = 'plotly',title='High and Low Prices')
fig.data[0].line.color = "#00FF00"
fig.data[1].line.color = "#FF0000"
fig.show()
Close and Adj closefig = pex.line(df, x="Date", y=["Close","Adj Close"],template = 'plotly',title='High and Low Prices')

fig = pex.line(df, x="Date", y=["Close","Adj Close"],template = 'plotly',title='High and Low Prices')
fig.data[0].line.color = "#00FF00"
fig.data[1].line.color = "#FF0000"
fig.show()
Volume traded by day
fig = pex.line(df, x="Date", y='Volume',template = 'plotly',title='Volume in by day')
fig.data[0].line.color = "#0000FF"
fig.show()

The full example is on my Kaggle account. This is the link.
https://www.kaggle.com/code/mixmore/bitcoin-price-analysis
Here is just an explanation of the example on Kaggle.