-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmodel.py
46 lines (32 loc) · 976 Bytes
/
model.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
import numpy as np
from utils import random_init_X
from utils import simulate_order_book
import random
import matplotlib.pyplot as plt
import sys
import json
n=500
random.seed(0)
np.random.seed(0)
X=random_init_X(n)
#X=np.zeros((n))
print(X)
(all_states, Q_i, RV) = simulate_order_book(pow(10,6), X)
all_tau = sum(all_states.values())
states_with_highest_p_num = 5
states_with_highest_p = [(0,0)]*states_with_highest_p_num
for state in all_states:
print('state %s probability %s' %(state, all_states[state]/all_tau))
if states_with_highest_p[0][1] < all_states[state]/all_tau:
states_with_highest_p.pop()
states_with_highest_p.insert( 0, (state, all_states[state]/all_tau) )
# state = np.array(json.loads(state))
print('Q_i %s' %Q_i)
print('RV %s' %RV)
print('states_with_highest_p')
for s in states_with_highest_p:
print(s)
sys.stdout.flush()
plt.plot(range(1,len(Q_i)), Q_i[1:])
plt.title('average number of orders')
plt.show()