-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLOB_clean_up.py
63 lines (32 loc) · 1.41 KB
/
LOB_clean_up.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# -*- coding: utf-8 -*-
"""
Created on Sat May 11 14:56:36 2024
@author: TedLove
"""
import pandas as pd
import numpy as np
def clean_up_order_book(order_book, LOB):
order_book['price'] = order_book['price'] * 1e-4
order_book.index = order_book.index - order_book.index.min()
LOB.index = order_book.index
order_book['midPrice'] = LOB['midPrice']
order_book_filtered = order_book.loc[order_book['type']>=4]
order_book_filtered = order_book_filtered.loc[order_book_filtered['type']>=4]
X = -order_book_filtered['direction'] *( order_book_filtered['price']-order_book_filtered['midPrice'] )
X = X.rename('X')
order_book_filtered = pd.concat([order_book_filtered,X],axis=1)
return order_book_filtered, LOB
def clean_up_LOB(LOB):
col_names = []
for i in range(1,3):
col_names.append('ask ' + str(i))
col_names.append('ask vol ' + str(i))
col_names.append('bid ' + str(i))
col_names.append('bid vol ' + str(i))
LOB.columns = col_names
for column in LOB.columns:
if 'vol' not in column:
LOB[column] = LOB[column] * 1e-4
LOB['midPrice'] = ((LOB['ask 1'] + LOB['bid 1']) / 2 )
LOB.index = (LOB.index - LOB.index[0])
return LOB