In [1]:
import pandas as pd
import numpy as np
from price import Price
from coin import Coin
import config
import crosscoin
import plot
In [2]:
# Analyze prices of 37 altcoins
prices = [Price(ticker) for ticker in config.ALL_TICKERS]
price_df = crosscoin.create_price_frame(prices, normalize='z_score')
In [3]:
plot.plot_timeseries('Z-Score Normalized Prices', price_df, legend=False)
In [4]:
# Cutoff at later date for better presentation
start = pd.datetime(2013, 8, 25)
price_df_trunc = price_df[start:]
plot.plot_timeseries('Z-Score Normalized Prices', price_df_trunc, legend=False)
In [5]:
# Calculate price correlations
price_corr = price_df.corr()
print price_corr.head()
In [65]:
# Find any outliers in correlation
print "Mean coefficients (ascending order)"
print "-" * 30
weak = price_corr.mean().order()
print weak.head()
In [7]:
# Calculate mean of correlation coefficient without outliers
drop = weak[weak < 0.5].index.values
coin_to_coeff = {}
for coin in prices:
ticker = coin.ticker.upper()
if ticker in drop:
continue
c = price_corr[ticker].drop(ticker)
for d in drop:
c = c.drop(d)
coin_to_coeff[ticker] = c.mean()
top_coeff = pd.Series(coin_to_coeff)
print "Mean coefficients without outliers (descending order)"
print "-" * 30
print top_coeff.order(ascending=False).head(10)
In [54]:
# Calculate BTC correlation
btc_corr = price_corr['BTC'].drop('BTC').drop('DRK').drop('QRK')
print "BTC correlation"
print "-" * 30
print btc_corr.order(ascending=False).head(10)
print "Mean coefficient: {}".format(btc_corr.mean())
In [58]:
# Calculate LTC correlation
ltc_corr = price_corr['LTC'].drop('LTC').drop('DRK').drop('QRK')
print "LTC correlation"
print "-" * 30
print ltc_corr.order(ascending=False).head(10)
print "Mean coefficient: {}".format(ltc_corr.mean())
In [36]:
# Graph top 4 coins with highest LTC correlation
ltc_top = ltc_corr.order(ascending=False)[:4]
ltc_tickers = ltc_top.index.tolist()
ltc_tickers.insert(0, 'LTC')
ltc_coins = filter(lambda x : x.ticker in ltc_tickers, prices)
ltc_df = crosscoin.create_price_frame(ltc_coins, normalize='z_score')
start = ltc_df.index.searchsorted(pd.datetime(2013, 10, 1))
plot.plot_timeseries('Z-Score Normalized Prices', ltc_df[start:])
print "Mean coefficient: {}".format(ltc_top.mean())
In [33]:
# Find the two coins that are most highly correlated
corr = price_corr
# Remove correlation between a coin and itself
for col in corr.columns:
corr[col] = corr[col].drop(col)
top_two = price_corr.max().order(ascending=False).head(2).index.tolist()
top_coins = filter(lambda x : x.ticker in top_two, prices)
frame = crosscoin.create_price_frame(top_coins, normalize='z_score')
start = frame.index.searchsorted(pd.datetime(2013, 10, 1))
frame = frame[start:]
plot.plot_timeseries('Z-Score Normalized Prices', frame)
print "Corr coefficient: {}".format(price_corr[top_two[0]][top_two[1]])
In [63]:
big = ['LTC', 'BTC']
big_coins = filter(lambda x : x.ticker in big, prices)
frame = crosscoin.create_price_frame(big_coins, normalize='z_score')
start = frame.index.searchsorted(pd.datetime(2013, 10, 1))
frame = frame.fillna(method='pad')
frame = frame[start:]
plot.plot_timeseries('Z-Score Normalized Prices', frame)
print "Corr coefficient: {}".format(price_corr[big[0]][big[1]])
In [83]:
big = ['DRK', 'BTC']
big_coins = [Price(ticker) for ticker in big]
frame = crosscoin.create_price_frame(big_coins, normalize='z_score')
start = frame.index.searchsorted(pd.datetime(2014, 4, 1))
frame = frame.fillna(method='pad')
frame = frame[start:]
plot.plot_timeseries('Z-Score Normalized Prices', frame)
print "Corr coefficient: {}".format(price_corr[big[0]][big[1]])
In [12]:
# Let's remove all the coins that are below the average coefficient
mean_coeff = price_corr.mean().mean()
good_tickers = []
for ticker in price_corr:
if price_corr[ticker].mean() >= mean_coeff:
good_tickers.append(ticker)
# We now have a set of coins that should correlate very strongly
good_price_df = price_df[good_tickers]
corr = good_price_df.corr()
# NOTE: BTC is not in this list!
# Remove correlation between a coin and itself
for col in corr.columns:
corr[col] = corr[col].drop(col)
good_mean_corr = corr.mean().mean()
print 'Subset of', len(good_tickers), 'coins exists with mean correlation:', good_mean_corr
for ticker in good_tickers:
print ticker,
In [43]:
# Load all data for a subset of altcoins
coins = [Coin(ticker) for ticker in config.TICKERS]
btc = Coin('btc')
coins.append(btc)
(ppc, dgc, mec, anc, nvc, nmc, mnc, gld, ftc, ltc, drk, lky, btc) = coins
In [21]:
# Analyze difficulty
diff_df = crosscoin.create_coin_frame(coins, 'block_chain_work', normalize='z_score')
In [79]:
diff_corr = diff_df.corr()
print diff_corr.head()
In [41]:
# Plot difficulty
# Need to pad before graphing to fill in NA values; otherwise, smoothing breaks
diff_df_padded = diff_df.fillna(method='pad')
plot.plot_timeseries('Z-Score Normalized, Smoothed Work', diff_df_padded, window=10000)
In [80]:
# Show difficulty correlation with BTC
print "Difficulty correlation with BTC"
print "-" * 30
btc_corr = diff_corr['btc'].drop('btc').order(ascending=False)
print btc_corr
In [39]:
# Graph top 4 coins with highest BTC difficulty correlation
btc_top = btc_corr.order(ascending=False)[:5]
btc_tickers = btc_top.index.tolist()
btc_df = diff_df[btc_tickers]
btc_coins = filter(lambda x : x.ticker in btc_tickers, coins)
btc_df = crosscoin.create_coin_frame(btc_coins, 'block_chain_work', normalize='z_score')
# Need to pad before graphing to fill in NA values; otherwise, smoothing breaks
btc_df_padded = btc_df.fillna(method='pad')
start = btc_df_padded.index.searchsorted(pd.datetime(2013, 10, 1))
end = btc_df_padded.index.searchsorted(pd.datetime(2014, 12, 30))
plot.plot_timeseries('Z-Score Normalized, Smoothed Work', btc_df_padded[start:end], window=10000)
print "Mean coefficient: {}".format(btc_top.mean())
In [42]:
# Analyze number of transactions
tx_df = crosscoin.create_coin_frame(coins, 'block_num_tx', normalize='z_score')
tx_df_padded = tx_df.fillna(method='pad')
plot.plot_timeseries('Z-Score Normalized, Smoothed Tx. Volume', tx_df_padded, window=10000)
In [46]:
tx_df = crosscoin.create_coin_frame(coins, 'block_num_tx', normalize='z_score')
corr = tx_df.corr()
print corr
In [ ]: