Skip to content

Commit 2fc0410

Browse files
committed
- Added 2nd Highest Call Open Interest and Strike Price
- Added 2nd Highest Put Open Interest and Strike Price
1 parent c7abd25 commit 2fc0410

File tree

1 file changed

+55
-19
lines changed

1 file changed

+55
-19
lines changed

NSE_Option_Chain_Analyzer.py

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def main_win(self) -> None:
353353
window_height: int = self.root.winfo_reqheight()
354354
position_right: int = int(self.root.winfo_screenwidth() / 3 - window_width / 2)
355355
position_down: int = int(self.root.winfo_screenheight() / 3 - window_height / 2)
356-
self.root.geometry("815x510+{}+{}".format(position_right, position_down))
356+
self.root.geometry("815x560+{}+{}".format(position_right, position_down))
357357
self.root.rowconfigure(0, weight=1)
358358
self.root.columnconfigure(0, weight=1)
359359

@@ -396,6 +396,7 @@ def main_win(self) -> None:
396396
bottom_frame.rowconfigure(2, weight=1)
397397
bottom_frame.rowconfigure(3, weight=1)
398398
bottom_frame.rowconfigure(4, weight=1)
399+
bottom_frame.rowconfigure(5, weight=1)
399400
bottom_frame.columnconfigure(0, weight=1)
400401
bottom_frame.columnconfigure(1, weight=1)
401402
bottom_frame.columnconfigure(2, weight=1)
@@ -409,7 +410,7 @@ def main_win(self) -> None:
409410
oi_ub_label: Label = Label(bottom_frame, text="Open Interest Upper Boundary", relief=RIDGE,
410411
font=("TkDefaultFont", 10, "bold"))
411412
oi_ub_label.grid(row=0, column=0, columnspan=4, sticky=N + S + W + E)
412-
max_call_oi_sp_label: Label = Label(bottom_frame, text="Strike Price:", relief=RIDGE,
413+
max_call_oi_sp_label: Label = Label(bottom_frame, text="Strike Price 1:", relief=RIDGE,
413414
font=("TkDefaultFont", 9, "bold"))
414415
max_call_oi_sp_label.grid(row=1, column=0, sticky=N + S + W + E)
415416
self.max_call_oi_sp_val: Label = Label(bottom_frame, text="", relief=RIDGE)
@@ -422,7 +423,7 @@ def main_win(self) -> None:
422423
oi_lb_label: Label = Label(bottom_frame, text="Open Interest Lower Boundary", relief=RIDGE,
423424
font=("TkDefaultFont", 10, "bold"))
424425
oi_lb_label.grid(row=0, column=4, columnspan=4, sticky=N + S + W + E)
425-
max_put_oi_sp_label: Label = Label(bottom_frame, text="Strike Price:", relief=RIDGE,
426+
max_put_oi_sp_label: Label = Label(bottom_frame, text="Strike Price 1:", relief=RIDGE,
426427
font=("TkDefaultFont", 9, "bold"))
427428
max_put_oi_sp_label.grid(row=1, column=4, sticky=N + S + W + E)
428429
self.max_put_oi_sp_val: Label = Label(bottom_frame, text="", relief=RIDGE)
@@ -432,32 +433,55 @@ def main_win(self) -> None:
432433
max_put_oi_label.grid(row=1, column=6, sticky=N + S + W + E)
433434
self.max_put_oi_val: Label = Label(bottom_frame, text="", relief=RIDGE)
434435
self.max_put_oi_val.grid(row=1, column=7, sticky=N + S + W + E)
436+
max_call_oi_sp_2_label: Label = Label(bottom_frame, text="Strike Price 2:", relief=RIDGE,
437+
font=("TkDefaultFont", 9, "bold"))
438+
max_call_oi_sp_2_label.grid(row=2, column=0, sticky=N + S + W + E)
439+
self.max_call_oi_sp_2_val: Label = Label(bottom_frame, text="", relief=RIDGE)
440+
self.max_call_oi_sp_2_val.grid(row=2, column=1, sticky=N + S + W + E)
441+
max_call_oi_2_label: Label = Label(bottom_frame, text="OI (in K):", relief=RIDGE,
442+
font=("TkDefaultFont", 9, "bold"))
443+
max_call_oi_2_label.grid(row=2, column=2, sticky=N + S + W + E)
444+
self.max_call_oi_2_val: Label = Label(bottom_frame, text="", relief=RIDGE)
445+
self.max_call_oi_2_val.grid(row=2, column=3, sticky=N + S + W + E)
446+
oi_lb_2_label: Label = Label(bottom_frame, text="Open Interest Lower Boundary", relief=RIDGE,
447+
font=("TkDefaultFont", 10, "bold"))
448+
oi_lb_2_label.grid(row=2, column=4, columnspan=4, sticky=N + S + W + E)
449+
max_put_oi_sp_2_label: Label = Label(bottom_frame, text="Strike Price 2:", relief=RIDGE,
450+
font=("TkDefaultFont", 9, "bold"))
451+
max_put_oi_sp_2_label.grid(row=2, column=4, sticky=N + S + W + E)
452+
self.max_put_oi_sp_2_val: Label = Label(bottom_frame, text="", relief=RIDGE)
453+
self.max_put_oi_sp_2_val.grid(row=2, column=5, sticky=N + S + W + E)
454+
max_put_oi_2_label: Label = Label(bottom_frame, text="OI (in K):", relief=RIDGE,
455+
font=("TkDefaultFont", 9, "bold"))
456+
max_put_oi_2_label.grid(row=2, column=6, sticky=N + S + W + E)
457+
self.max_put_oi_2_val: Label = Label(bottom_frame, text="", relief=RIDGE)
458+
self.max_put_oi_2_val.grid(row=2, column=7, sticky=N + S + W + E)
435459

436460
oi_label: Label = Label(bottom_frame, text="Open Interest:", relief=RIDGE, font=("TkDefaultFont", 9, "bold"))
437-
oi_label.grid(row=2, column=0, columnspan=2, sticky=N + S + W + E)
461+
oi_label.grid(row=3, column=0, columnspan=2, sticky=N + S + W + E)
438462
self.oi_val: Label = Label(bottom_frame, text="", relief=RIDGE)
439-
self.oi_val.grid(row=2, column=2, columnspan=2, sticky=N + S + W + E)
463+
self.oi_val.grid(row=3, column=2, columnspan=2, sticky=N + S + W + E)
440464
pcr_label: Label = Label(bottom_frame, text="PCR:", relief=RIDGE, font=("TkDefaultFont", 9, "bold"))
441-
pcr_label.grid(row=2, column=4, columnspan=2, sticky=N + S + W + E)
465+
pcr_label.grid(row=3, column=4, columnspan=2, sticky=N + S + W + E)
442466
self.pcr_val: Label = Label(bottom_frame, text="", relief=RIDGE)
443-
self.pcr_val.grid(row=2, column=6, columnspan=2, sticky=N + S + W + E)
467+
self.pcr_val.grid(row=3, column=6, columnspan=2, sticky=N + S + W + E)
444468
call_exits_label: Label = Label(bottom_frame, text="Call Exits:", relief=RIDGE,
445469
font=("TkDefaultFont", 9, "bold"))
446-
call_exits_label.grid(row=3, column=0, columnspan=2, sticky=N + S + W + E)
470+
call_exits_label.grid(row=4, column=0, columnspan=2, sticky=N + S + W + E)
447471
self.call_exits_val: Label = Label(bottom_frame, text="", relief=RIDGE)
448-
self.call_exits_val.grid(row=3, column=2, columnspan=2, sticky=N + S + W + E)
472+
self.call_exits_val.grid(row=4, column=2, columnspan=2, sticky=N + S + W + E)
449473
put_exits_label: Label = Label(bottom_frame, text="Put Exits:", relief=RIDGE, font=("TkDefaultFont", 9, "bold"))
450-
put_exits_label.grid(row=3, column=4, columnspan=2, sticky=N + S + W + E)
474+
put_exits_label.grid(row=4, column=4, columnspan=2, sticky=N + S + W + E)
451475
self.put_exits_val: Label = Label(bottom_frame, text="", relief=RIDGE)
452-
self.put_exits_val.grid(row=3, column=6, columnspan=2, sticky=N + S + W + E)
476+
self.put_exits_val.grid(row=4, column=6, columnspan=2, sticky=N + S + W + E)
453477
call_itm_label: Label = Label(bottom_frame, text="Call ITM:", relief=RIDGE, font=("TkDefaultFont", 9, "bold"))
454-
call_itm_label.grid(row=4, column=0, columnspan=2, sticky=N + S + W + E)
478+
call_itm_label.grid(row=5, column=0, columnspan=2, sticky=N + S + W + E)
455479
self.call_itm_val: Label = Label(bottom_frame, text="", relief=RIDGE)
456-
self.call_itm_val.grid(row=4, column=2, columnspan=2, sticky=N + S + W + E)
480+
self.call_itm_val.grid(row=5, column=2, columnspan=2, sticky=N + S + W + E)
457481
put_itm_label: Label = Label(bottom_frame, text="Put ITM:", relief=RIDGE, font=("TkDefaultFont", 9, "bold"))
458-
put_itm_label.grid(row=4, column=4, columnspan=2, sticky=N + S + W + E)
482+
put_itm_label.grid(row=5, column=4, columnspan=2, sticky=N + S + W + E)
459483
self.put_itm_val: Label = Label(bottom_frame, text="", relief=RIDGE)
460-
self.put_itm_val.grid(row=4, column=6, columnspan=2, sticky=N + S + W + E)
484+
self.put_itm_val.grid(row=5, column=6, columnspan=2, sticky=N + S + W + E)
461485

462486
self.root.after(100, self.main)
463487

@@ -517,8 +541,12 @@ def set_values(self) -> None:
517541

518542
self.max_call_oi_val.config(text=self.max_call_oi)
519543
self.max_call_oi_sp_val.config(text=self.max_call_oi_sp)
544+
self.max_call_oi_2_val.config(text=self.max_call_oi_2)
545+
self.max_call_oi_sp_2_val.config(text=self.max_call_oi_sp_2)
520546
self.max_put_oi_val.config(text=self.max_put_oi)
521547
self.max_put_oi_sp_val.config(text=self.max_put_oi_sp)
548+
self.max_put_oi_2_val.config(text=self.max_put_oi_2)
549+
self.max_put_oi_sp_2_val.config(text=self.max_put_oi_sp_2)
522550

523551
red: str = "#e53935"
524552
green: str = "#00e676"
@@ -695,15 +723,21 @@ def main(self) -> None:
695723
for i in range(len(df)):
696724
int_call_oi: int = int(df.iloc[i, [0]][0])
697725
call_oi_list.append(int_call_oi)
698-
call_oi_index: int = call_oi_list.index(max(call_oi_list))
699-
self.max_call_oi: float = round(max(call_oi_list) / 1000, 1)
726+
call_oi_list_sorted: List[int] = sorted(call_oi_list)
727+
call_oi_index: int = call_oi_list.index(call_oi_list_sorted[-1])
728+
call_oi_index_2: int = call_oi_list.index(call_oi_list_sorted[-2])
729+
self.max_call_oi: float = round(call_oi_list_sorted[-1] / 1000, 1)
730+
self.max_call_oi_2: float = round(call_oi_list_sorted[-2] / 1000, 1)
700731

701732
put_oi_list: List[int] = []
702733
for i in range(len(df)):
703734
int_put_oi: int = int(df.iloc[i, [20]][0])
704735
put_oi_list.append(int_put_oi)
705-
put_oi_index: int = put_oi_list.index(max(put_oi_list))
706-
self.max_put_oi: float = round(max(put_oi_list) / 1000, 1)
736+
put_oi_list_sorted: List[int] = sorted(put_oi_list)
737+
put_oi_index: int = put_oi_list.index(put_oi_list_sorted[-1])
738+
put_oi_index_2: int = put_oi_list.index(put_oi_list_sorted[-2])
739+
self.max_put_oi: float = round(put_oi_list_sorted[-1] / 1000, 1)
740+
self.max_put_oi_2: float = round(put_oi_list_sorted[-2] / 1000, 1)
707741

708742
total_call_oi: int = sum(call_oi_list)
709743
total_put_oi: int = sum(put_oi_list)
@@ -714,7 +748,9 @@ def main(self) -> None:
714748
self.put_call_ratio = 0
715749

716750
self.max_call_oi_sp: numpy.float64 = df.iloc[call_oi_index]['Strike Price']
751+
self.max_call_oi_sp_2: numpy.float64 = df.iloc[call_oi_index_2]['Strike Price']
717752
self.max_put_oi_sp: numpy.float64 = df.iloc[put_oi_index]['Strike Price']
753+
self.max_put_oi_sp_2: numpy.float64 = df.iloc[put_oi_index_2]['Strike Price']
718754

719755
try:
720756
index: int = int(df[df['Strike Price'] == self.sp].index.tolist()[0])

0 commit comments

Comments
 (0)