@@ -71,8 +71,7 @@ def get_price_oi(data, symbol):
71
71
('date' , '@date' ),
72
72
('combined OI' , '@combined_oi{0 a}' ),
73
73
('expiry_at' , '$name q:@$name{0.0 a}' )
74
- ],
75
- height = 250 )
74
+ ])
76
75
cols , data = get_open_interest (df , 'NIFTY' )
77
76
data ['date' ] = data .timestamp .dt .date .astype (str )
78
77
colors = Spectral6 [:len (cols )]
@@ -86,29 +85,26 @@ def get_price_oi(data, symbol):
86
85
h1 = price_data ['open_int' ].max ()
87
86
l1 = price_data ['open_int' ].min ()
88
87
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 ))
91
89
p2 .line ('timestamp' , 'close' , source = prices )
92
90
p2 .extra_y_ranges = {'foo' : Range1d (l1 ,h1 )}
93
91
p2 .line ('timestamp' , 'open_int' , source = prices , y_range_name = 'foo' )
94
92
p2 .add_layout (LinearAxis (y_range_name = 'foo' ), 'right' )
95
93
96
- pct_change = data [['date' , 'combined_oi' ]]
94
+ pct_change = data [['date' , 'combined_oi' ]]. copy ()
97
95
pct_change ['date' ] = pd .to_datetime (pct_change ['date' ])
98
96
pct_change ['chg' ] = pct_change .combined_oi .pct_change ()
99
- print (pct_change .reset_index ().info ())
100
97
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' )
103
99
p3 .vbar (x = 'index' , top = 'chg' , width = 0.6 , source = pct_chg )
104
100
105
101
106
-
107
102
# setup callbacks
108
103
def update ():
109
104
symbol = select_symbol .value
110
105
cols , data = get_open_interest (df , symbol )
111
106
data ['date' ] = data .timestamp .dt .date .astype (str )
107
+ print (data [cols ].sum ())
112
108
max_val = data [cols ].sum ().max ()
113
109
p .y_range .start = 0
114
110
p .y_range .end = max_val
@@ -125,21 +121,19 @@ def update():
125
121
p2 .y_range .end = h0
126
122
p2 .extra_y_ranges ['foo' ].start = l1
127
123
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 )
129
127
130
128
131
129
# set up event triggers
132
130
button .on_click (update )
133
131
134
-
132
+ grid = gridplot ([ p2 , p , p3 ], ncols = 1 , plot_width = 640 , plot_height = 180 )
135
133
# Display the dashboard
136
134
l = layout (
137
- column (
138
135
row (select_symbol ,button ),
139
- p2 ,
140
- p ,
141
- p3
142
- )
136
+ grid
143
137
)
144
138
145
139
curdoc ().add_root (l )
0 commit comments