Skip to content

Commit 2f19d1c

Browse files
committed
grid layout added and percent change chart updated
1 parent 91fb051 commit 2f19d1c

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

oi_graph/futures_oi.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ def get_price_oi(data, symbol):
7171
('date', '@date'),
7272
('combined OI', '@combined_oi{0 a}'),
7373
('expiry_at', '$name q:@$name{0.0 a}')
74-
],
75-
height=250)
74+
])
7675
cols, data = get_open_interest(df, 'NIFTY')
7776
data['date'] = data.timestamp.dt.date.astype(str)
7877
colors = Spectral6[:len(cols)]
@@ -86,29 +85,26 @@ def get_price_oi(data, symbol):
8685
h1 = price_data['open_int'].max()
8786
l1 = price_data['open_int'].min()
8887
p2 = figure(title='Price vs Open Interest',
89-
x_axis_type='datetime', y_range=(l0,h0),
90-
height=250)
88+
x_axis_type='datetime', y_range=(l0,h0))
9189
p2.line('timestamp', 'close', source=prices)
9290
p2.extra_y_ranges = {'foo': Range1d(l1,h1)}
9391
p2.line('timestamp', 'open_int', source=prices, y_range_name='foo')
9492
p2.add_layout(LinearAxis(y_range_name='foo'), 'right')
9593

96-
pct_change = data[['date', 'combined_oi']]
94+
pct_change = data[['date', 'combined_oi']].copy()
9795
pct_change['date'] = pd.to_datetime(pct_change['date'])
9896
pct_change['chg'] = pct_change.combined_oi.pct_change()
99-
print(pct_change.reset_index().info())
10097
pct_chg.data = pct_chg.from_df(pct_change)
101-
p3 = figure(title='Change in open_interest',
102-
height=250, x_axis_type='datetime')
98+
p3 = figure(title='Change in open_interest')
10399
p3.vbar(x='index', top='chg', width=0.6, source=pct_chg)
104100

105101

106-
107102
# setup callbacks
108103
def update():
109104
symbol = select_symbol.value
110105
cols, data = get_open_interest(df, symbol)
111106
data['date'] = data.timestamp.dt.date.astype(str)
107+
print(data[cols].sum())
112108
max_val = data[cols].sum().max()
113109
p.y_range.start = 0
114110
p.y_range.end = max_val
@@ -125,21 +121,19 @@ def update():
125121
p2.y_range.end = h0
126122
p2.extra_y_ranges['foo'].start = l1
127123
p2.extra_y_ranges['foo'].end = h1
128-
124+
pct_change = data[['date', 'combined_oi']].copy()
125+
pct_change['chg'] = pct_change.combined_oi.pct_change()
126+
pct_chg.data = pct_chg.from_df(pct_change)
129127

130128

131129
# set up event triggers
132130
button.on_click(update)
133131

134-
132+
grid = gridplot([p2,p,p3], ncols=1, plot_width=640, plot_height=180)
135133
# Display the dashboard
136134
l = layout(
137-
column(
138135
row(select_symbol,button),
139-
p2,
140-
p,
141-
p3
142-
)
136+
grid
143137
)
144138

145139
curdoc().add_root(l)

0 commit comments

Comments
 (0)