Created
June 30, 2019 02:40
-
-
Save bharddwaj/de9d598730389c1a5e0c71f712c29adc to your computer and use it in GitHub Desktop.
finds the bid-ask spread for each row and records the frequency of each different size spread and graphs them at the end. Used this for liquidity research on 64 million rows of data!
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 pandas as pd | |
import numpy as np | |
import csv | |
import seaborn as sns | |
import matplotlib.pyplot as plt | |
import math | |
data = pd.read_csv("CL_June_2019.csv") | |
print(type(data)) | |
#new_data = data[59528000:59800000] | |
#print(new_data) | |
#new_data.to_csv("new_file.csv") | |
count = 0 | |
spread = [] | |
frequency = {} | |
spread.append( data['Bid Size']) | |
spread.append(data['Ask Size']) | |
for i in range(len(spread[0])): | |
count += 1 | |
bid = spread[0][i] | |
ask = spread[1][i] | |
if not math.isnan(bid) and not math.isnan(ask): | |
difference = int(bid-ask) | |
print(difference) | |
if difference in frequency: | |
frequency[difference] += 1 | |
else: | |
frequency[difference] = 1 | |
print(count) | |
k = [keys for keys in frequency] | |
sns.barplot(x = ,y = [frequency[keys] for keys in frequency]) | |
plt.xlabel("Spread") | |
plt.ylabel('Frequency') | |
plt.title("Bid-Ask Size Spread") | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment