Last active
August 23, 2020 08:43
-
-
Save moondancecrypto/2402e4c67832b6548f1be69817bd17aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#%% | |
import glob | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import pandas as pd | |
import seaborn as sns | |
sns.set_style('whitegrid') | |
sns.set_context("paper", 1.5, {"lines.linewidth": 4}) | |
#%% | |
# load MOVE data | |
flist = glob.glob('data/FTX_OHCLV_2020_BTC-MOVE-0[1-8]*_1min.csv') | |
# plot | |
sumdf = pd.DataFrame() | |
fig, ax = plt.subplots(figsize=(12,8)) | |
for fname in flist: | |
#print(fname) | |
df = pd.read_csv(fname) | |
fdate = fname.replace('data/FTX_OHCLV_2020_BTC-MOVE-', '').replace('_1min.csv','') | |
tmpdf = pd.DataFrame({f'Close_{fdate}':(df.Close.values - df.Close.values[0])}, | |
index=((df.TimeStamp - df.TimeStamp.values[0])/60000).astype(int)) | |
sumdf = pd.concat([sumdf, tmpdf[f'Close_{fdate}']], axis=1) | |
tmpdf.reset_index().plot(x='TimeStamp', y=f'Close_{fdate}', | |
style='-', color='#aaaaaa', lw=1, ax=ax, legend=False) | |
#display(sumdf) | |
# interporate | |
sumdf = sumdf.interpolate() | |
# calculate median and mean | |
sumdf['median'] = sumdf.T.median() | |
sumdf['mean'] = sumdf.T.mean() | |
#sumdf['std'] = sumdf.T.std() | |
sumdf.reset_index().plot(x='index', y=['median', 'mean'], style='-', lw=3, color=['blue', 'orange'], ax=ax) | |
#sumdf.reset_index().plot(x='index', y=['median', 'mean', 'std'], style='-', lw=3, color=['blue', 'orange', 'green'], ax=ax) | |
# house keeping | |
plt.xlabel('Time [min]') | |
plt.ylabel('Deviation from close price at t=0') | |
plt.xlim([0, 2880]) | |
plt.ylim([-500, 500]) | |
plt.savefig('FTX-BTCMOVE-analysisplot1.png') | |
#%% | |
############### | |
# plot in chronological order | |
sumdf = pd.DataFrame() | |
fig, ax = plt.subplots(figsize=(16,8)) | |
for i, fname in enumerate(flist): | |
#fname = flist[0] | |
df = pd.read_csv(fname) | |
df['tsmin'] = df.TimeStamp/600000 | |
df['CloseDiff'] = df.Close.values - df.Close.values[0] | |
colors = ['tab:red', 'tab:purple', 'tab:brown', 'tab:pink', 'tab:blue', 'tab:orange', 'tab:green'] | |
df.plot(x='tsmin', y=f'CloseDiff', style='-', color=colors[i%7], lw=1, ax=ax, legend=False) | |
plt.xlabel('TimeStamp [min]') | |
plt.ylabel('Deviation from close price at t=0') | |
plt.savefig('FTX-BTCMOVE-analysisplot2.png') | |
# %% | |
# make a histgram of final price | |
tmplist = [] | |
for i, fname in enumerate(flist): | |
#fname = flist[0] | |
df = pd.read_csv(fname) | |
df['tsmin'] = df.TimeStamp/600000 | |
df['CloseDiff'] = df.Close.values - df.Close.values[0] | |
colors = ['tab:red', 'tab:purple', 'tab:brown', 'tab:pink', 'tab:blue', 'tab:orange', 'tab:green'] | |
tmplist += [df.CloseDiff.values[-1]] | |
tmplist | |
histdf = pd.DataFrame(tmplist, columns=['Final diff price']) | |
bins = np.linspace(-200, 200, num=30) | |
fig, ax = plt.subplots(figsize=(12,8)) | |
sns.distplot(histdf, ax=ax, bins=bins) | |
plt.title('') | |
plt.xlim([-200, 200]) | |
plt.xlabel('Final diff price (USD)', fontsize=20) | |
plt.ylabel('Frequency', fontsize=20) | |
plt.savefig('FTX-BTCMOVE-histplot.png') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment