In this Article, I will show you the power of pandas and the data analytics of historical prices of multiple cryptocurrencies. Unfortunately, the data does not represent the recent exponential rise of these stock prices. The purpose of this exersice is to see if more recent cryptocurrencies will rise similar to Bitcoin
Bitccoin, Ethereum, Litecoin, and Monero
import numpy as np
import pandas as pd
import plotly
import plotly.plotly as py
import plotly.graph_objs as go
import plotly.graph_objs as go
This is an example of loading a data frame from a csv file and indexing it by the Date
btc_df = pd.read_csv('/Users/troy/Github/courses/crypto-pirates/cryptocurrencypricehistory/bitcoin_price.csv')
btc_df.set_index('Date',inplace=True)
btc_df.head()
Here I am adding a new column to the data frame where the value takes in an operation of two columns.
btc_df['Daily Range'] = btc_df['High'] - btc_df['Low']
btc_df.head()
This is the mean of Daily Range for Bitcoin
btc_df['Daily Range'].mean()
'''
1. Add new column. 2. Define Conditions. 3. Change necessary value to the column that meets the condition.
'''
btc_df['Significant'] = ''
cond1 = btc_df['Daily Range'] > btc_df['Daily Range'].mean()
cond2 = btc_df['Daily Range'] < btc_df['Daily Range'].mean()
yes = btc_df[cond1]
no = btc_df[cond2]
column = 'Significant'
btc_df.loc[cond1, column] = 'Yes'
btc_df.loc[cond2, column] = 'No'
btc_df.set_index('Significant')
btc = pd.read_csv('/Users/troy/Github/courses/crypto-pirates/cryptocurrencypricehistory/bitcoin_price.csv')
mon = pd.read_csv('/Users/troy/Github/courses/crypto-pirates/cryptocurrencypricehistory/monero_price.csv')
lit = pd.read_csv('/Users/troy/Github/courses/crypto-pirates/cryptocurrencypricehistory/litecoin_price.csv')
eth = pd.read_csv('/Users/troy/Github/courses/crypto-pirates/cryptocurrencypricehistory/ethereum_price.csv')
Before I concatenate multiple data frames, I first added a new column to each data frame which is going to be used for map reducing later.
btc['CC'] = 'Bitcoin'
mon['CC'] = 'Monero'
lit['CC'] = 'Litecoin'
eth['CC'] = 'Ethereum'
Now, I will add another column with the Moving averages of each CC
btc['MA'] = btc['Close'].rolling(10).mean()
mon['MA'] = mon['Close'].rolling(10).mean()
lit['MA'] = lit['Close'].rolling(10).mean()
eth['MA'] = lit['Close'].rolling(10).mean()
btc['SMA'] = btc['Close'].rolling(50).mean()
mon['SMA'] = mon['Close'].rolling(50).mean()
lit['SMA'] = lit['Close'].rolling(50).mean()
eth['SMA'] = lit['Close'].rolling(50).mean()
eth['Close'].max()
Discover Iterations of Trends
# btc[['Date', 'Close', 'MA']]
# onUp = (btc['MA'] > btc['Close']) & (btc[])
# btc[onUp][['Date','Close']]
iteration = (btc['Close']>0) & (btc['Close']<1000)
iteration2 = (btc['Close']>1000) & (btc['Close']<2000)
iteration3 = (btc['Close']>2000) & (btc['Close']<3000)
iteration4 = (btc['Close']>3000) & (btc['Close']<4000)
iteration5 = (btc['Close']>4000) & (btc['Close']<5000)
column = 'Iteration'
btc.loc[iteration, column] = '0-1000'
btc.loc[iteration2, column] = '1000-2000'
btc.loc[iteration3, column] = '2000-000'
btc.loc[iteration4, column] = '3000-4000'
btc.loc[iteration5, column] = '4000-5000'
btc.set_index(['CC','Iteration','Date'])
master = pd.concat([btc,mon,lit,eth])
master.set_index(['CC','Iteration','Date'])
Since Bitcoin's price is significantly higher, we gave the other 3 newer CCs a scalar of 10 in order to make cleaner plot.
import plotly
import plotly.plotly as py
import plotly.graph_objs as go
trace1 = go.Scatter(
x = btc['Date'],
y = btc['Close'],
mode = 'Lines',
name = 'Bitcoin Close Price'
)
trace2 = go.Scatter(
x = mon['Date'],
y = 10*mon['Close'],
mode = 'Lines',
name = 'Monero Close Price'
)
trace3 = go.Scatter(
x = lit['Date'],
y = 10*lit['Close'],
mode = 'Lines',
name = 'Litecoin Close Price'
)
trace4 = go.Scatter(
x = eth['Date'],
y = 10*eth['Close'],
mode = 'Lines',
name = 'Ethereum Close Price'
)
data = [trace1,trace2,trace3,trace4]
py.iplot(data, filename='basic-scatter')
The goal here is to aggregate data by cryptocurrency. We can approach this by creating a multi-level index that will map a new numerical index for each cc. In order to start the index hierarchy, we need to find the total number of tuples associated with eact cc and then use that number to index the tuples.
master.groupby('CC').mean()
master.groupby('CC').min()
master.groupby('CC').max()
# Count number of interations
master.groupby('CC').count()
master.groupby('CC').describe()
master.groupby('CC').describe().transpose()
master.groupby('CC').describe().transpose()['Bitcoin']
Merging works like SQL Join logic. We combine multiple dataframes with an index key to form a relational table.
# define left and right data fr
# master_df.merge(left, right, on=['Key1','Key2])
# left = btc_df['Daily Range'] < btc_df['']
master.to_csv('data.csv', index=False)
I have found that these four cryptocurrencies are very correlated with each other. They rise and fall around the same time. Uptrends and Downtrends are common among one another. Howerver, the stocks are very volatile. It is difficult to predict trends. In addtion, I have found that many current events are correlated with specific inclines and declines. Initial Coin Offerings (ICO) have a strong correlation with the data. ICOs publicly announce their launches. If you are interested to invest, make sure you also watch out for ICO launches.
ICO Schedules: https://tokenmarket.net/ico-calendar/upcoming