I have tick data containing symbols, bid prices, and ask prices. I was able to find the average spread and standard deviation of each symbol.
I'd like to create a confidence interval for each symbol and have the final DataFrame output have the columns
- ticker symbol
- average spread
- lower bound 95% confidence
- upper bound 95% confidence
How can I do that? This is how far I've been able to get:
df = pd.read_csv('C:\Users\William\Desktop\tickdata.csv',
dtype={'ticker': str, 'bidPrice': np.float64, 'askPrice': np.float64, 'afterHours': str},
usecols=['ticker', 'bidPrice', 'askPrice', 'afterHours'],
nrows=3000000
)
df = df[df.afterHours == "False"]
df = df[df.bidPrice != 0]
df = df[df.askPrice != 0]
df['spread'] = (df.askPrice - df.bidPrice)
print(df.groupby(['ticker'])['spread'].mean())
print(df.groupby(['ticker'])['spread'].std(ddof=0) * 1.96)
