-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlot_MidPrice.py
43 lines (34 loc) · 1.16 KB
/
Plot_MidPrice.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
# Plot Midprice
import matplotlib.pyplot as pl
import seaborn as sns
sns.set()
sns.set_context("talk")
sns.set_style("ticks")
sns.axes_style(rc={'axes.grid': True})
import matplotlib.dates as mdates
import pytz
import pandas as pd
def MakeMidPricePlot(SimOrderBooks, time_window=None):
if time_window == None:
time_window = [pd.to_datetime("2017-10-02 9:30:00 -4"),
pd.to_datetime("2017-10-02 16:00:00 -4")]
fig,ax = pl.subplots()
DayTicks = []
offset = 0
DayTicks.append(offset)
for SimOrderBook in SimOrderBooks:
x, y = SimOrderBook.get_midprice(get_timestamps=True)
dates = pd.to_datetime(x, unit = SimOrderBook._time_tick_unit)
ax.plot(dates,y, '-', alpha=1.)
xfmt = mdates.DateFormatter('%H:%M' , tz = pytz.timezone("America/New_York"))
ax.xaxis.set_major_formatter(xfmt)
ax.set_xlim(time_window)
fig.autofmt_xdate()
ax.yaxis.grid()
ax.set_title("Midprice of %i runs"%(len(SimOrderBooks)))
ax.set_ylabel("Midprice, \$")
ax.set_xlabel("Time")
ax.legend()
sns.despine(left=True)
fig.show()
return fig