Created
July 6, 2019 02:26
-
-
Save bharddwaj/b9de8eaf377c4d10d2712189c86f2607 to your computer and use it in GitHub Desktop.
top 15 most frequent bid ask spread percentages. the bid ask spread percentage is ((bid - ask)/ask)*10000
This file contains 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 | |
from collections import OrderedDict | |
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 Price']) | |
spread.append(data['Ask Price']) | |
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_percentage = round(((bid - ask)/ask)*10000,2) | |
#print(difference_percentage) | |
if difference_percentage in frequency: | |
frequency[difference_percentage] += 1 | |
else: | |
frequency[difference_percentage] = 1 | |
print(count) | |
frequency = OrderedDict(sorted(frequency.items(), key=lambda t: t[1])) | |
keys = list(frequency.keys()) | |
k = keys[len(keys)-15:len(keys)] | |
sns.barplot(x = k ,y =[frequency[i] for i in k ]) | |
plt.xlabel("Spread %") | |
plt.ylabel('Frequency') | |
plt.title(f"Bid-Ask Spread") | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment