In [11]:
import numpy as np # Linear Alg
import pandas as pd # CSV file I/O & data processing
# Visualization
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import seaborn as sns
import warnings
from matplotlib import style
from matplotlib.finance import candlestick_ohlc
warnings.filterwarnings("ignore")
style.use('ggplot')
%matplotlib inline
plt.rcParams['figure.figsize'] = (12.0, 8.0)
from subprocess import check_output
We are using the Cryptocurrency Historical Prices dataset from Kaggle.
In [2]:
data_dir = '../../input'
# Check what files our dataset contain
print('Our dataset contains the following files: \n')
print(check_output(["ls", data_dir]).decode("utf8"))
In [24]:
# Reading in bitcoin price file
bitcoin_price = pd.read_csv('{}/bitcoin_price.csv'.format(data_dir), parse_dates=['Date'], index_col=0)
bitcoin_price.dtypes
Out[24]:
In [4]:
# Lets look at the first 10 rows
bitcoin_price.head(10)
Out[4]:
In [5]:
bitcoin_price.tail(10)
Out[5]:
In [6]:
print('Date of newest data: {}'.format(bitcoin_price.index[0]))
print('Date of oldest data: {}'.format(bitcoin_price.index[-1]))
In [25]:
btc_ohlc = ['Open', 'High', 'Low', 'Close']
for feat in btc_ohlc:
print('---------------------------------------------')
print('Statistics for Bitcoin {} values:'.format(feat))
print(bitcoin_price[feat].describe())
In [26]:
# Lets plot the Open, Close, High, Low values on a line plot
for feat in btc_ohlc:
plt.plot(bitcoin_price[feat], label=feat)
plt.xlabel('Time(Yr-M)')
plt.ylabel('Value(USD)')
plt.legend()
plt.show()
In [27]:
# Lets looks at the more recent data
n_days = 365 # number of recent days
for feature in btc_ohlc:
plt.plot(bitcoin_price[feature].iloc[:n_days], label=feature)
plt.title('Pricing Trend(last year)')
plt.xlabel('Time(Yr-M)')
plt.ylabel('Value(USD)')
plt.legend()
plt.show()
In [29]:
# Candlestick graph for Bitcoin Closing Price
btc_close_ohlc = bitcoin_price['Close'][:n_days].resample('10D').ohlc()
btc_close_ohlc.reset_index(inplace=True)
btc_close_ohlc['Date'] = btc_close_ohlc['Date'].map(mdates.date2num)
fig, ax = plt.subplots()
candlestick_ohlc(ax, btc_close_ohlc.values, width=2, colorup='g')
ax.xaxis_date()
plt.title('Candlestick Chart')
plt.xlabel('Time(Yr-M)')
plt.ylabel('Value(USD)')
plt.legend()
plt.show()