Skip to content

Commit 760a568

Browse files
committed
- Removed numpy import by casting all numpy.float64 and numpy.int64 types to float and int
1 parent 1c01a41 commit 760a568

1 file changed

Lines changed: 40 additions & 45 deletions

File tree

NSE_Option_Chain_Analyzer.py

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from typing import Union, Optional, List, Dict, Tuple, TextIO, Any
1313

1414
import bs4
15-
import numpy
1615
import pandas
1716
import requests
1817
import streamtologger
@@ -573,7 +572,7 @@ def export(self, event: Optional[Event] = None) -> None:
573572
messagebox.showerror(title="Export Failed",
574573
message="An error occurred while exporting the data.")
575574

576-
def export_row(self, values: Optional[List[Union[str, float, numpy.float64]]]) -> None:
575+
def export_row(self, values: Optional[List[Union[str, float]]]) -> None:
577576
if values is None:
578577
csv_exists: bool = os.path.isfile(
579578
f"NSE-OCA-{self.index if self.option_mode == 'Index' else self.stock}-{self.expiry_date}.csv")
@@ -1067,10 +1066,10 @@ def set_values(self) -> None:
10671066
self.root.title(f"NSE-Option-Chain-Analyzer - {self.index if self.option_mode == 'Index' else self.stock} "
10681067
f"- {self.expiry_date} - {self.sp}")
10691068

1070-
self.old_max_call_oi_sp: numpy.float64
1071-
self.old_max_call_oi_sp_2: numpy.float64
1072-
self.old_max_put_oi_sp: numpy.float64
1073-
self.old_max_put_oi_sp_2: numpy.float64
1069+
self.old_max_call_oi_sp: float
1070+
self.old_max_call_oi_sp_2: float
1071+
self.old_max_put_oi_sp: float
1072+
self.old_max_put_oi_sp_2: float
10741073

10751074
self.max_call_oi_val.config(text=self.max_call_oi)
10761075
self.max_call_oi_sp_val.config(text=self.max_call_oi_sp)
@@ -1261,10 +1260,10 @@ def set_itm_labels(call_change: float, put_change: float) -> str:
12611260
icon_path=self.icon_ico_path if self.load_nse_icon else None)
12621261
self.old_put_exits_label = put_exits_label
12631262

1264-
output_values: List[Union[str, float, numpy.float64]] = [self.str_current_time, self.points, self.call_sum,
1265-
self.put_sum, self.difference,
1266-
self.call_boundary, self.put_boundary, self.call_itm,
1267-
self.put_itm]
1263+
output_values: List[Union[str, float]] = [self.str_current_time, self.points, self.call_sum,
1264+
self.put_sum, self.difference,
1265+
self.call_boundary, self.put_boundary, self.call_itm,
1266+
self.put_itm]
12681267
self.sheet.insert_row(values=output_values)
12691268
if self.live_export:
12701269
self.export_row(output_values)
@@ -1280,7 +1279,7 @@ def set_itm_labels(call_change: float, put_change: float) -> str:
12801279
else:
12811280
self.sheet.highlight_cells(row=last_row, column=1, bg=red)
12821281
self.old_points = self.points
1283-
self.old_call_sum: numpy.float64
1282+
self.old_call_sum: float
12841283
if self.first_run or self.old_call_sum == self.call_sum:
12851284
self.old_call_sum = self.call_sum
12861285
elif self.call_sum > self.old_call_sum:
@@ -1289,7 +1288,7 @@ def set_itm_labels(call_change: float, put_change: float) -> str:
12891288
else:
12901289
self.sheet.highlight_cells(row=last_row, column=2, bg=green)
12911290
self.old_call_sum = self.call_sum
1292-
self.old_put_sum: numpy.float64
1291+
self.old_put_sum: float
12931292
if self.first_run or self.old_put_sum == self.put_sum:
12941293
self.old_put_sum = self.put_sum
12951294
elif self.put_sum > self.old_put_sum:
@@ -1307,7 +1306,7 @@ def set_itm_labels(call_change: float, put_change: float) -> str:
13071306
else:
13081307
self.sheet.highlight_cells(row=last_row, column=4, bg=green)
13091308
self.old_difference = self.difference
1310-
self.old_call_boundary: numpy.float64
1309+
self.old_call_boundary: float
13111310
if self.first_run or self.old_call_boundary == self.call_boundary:
13121311
self.old_call_boundary = self.call_boundary
13131312
elif self.call_boundary > self.old_call_boundary:
@@ -1316,7 +1315,7 @@ def set_itm_labels(call_change: float, put_change: float) -> str:
13161315
else:
13171316
self.sheet.highlight_cells(row=last_row, column=5, bg=green)
13181317
self.old_call_boundary = self.call_boundary
1319-
self.old_put_boundary: numpy.float64
1318+
self.old_put_boundary: float
13201319
if self.first_run or self.old_put_boundary == self.put_boundary:
13211320
self.old_put_boundary = self.put_boundary
13221321
elif self.put_boundary > self.old_put_boundary:
@@ -1325,7 +1324,7 @@ def set_itm_labels(call_change: float, put_change: float) -> str:
13251324
else:
13261325
self.sheet.highlight_cells(row=last_row, column=6, bg=red)
13271326
self.old_put_boundary = self.put_boundary
1328-
self.old_call_itm: numpy.float64
1327+
self.old_call_itm: float
13291328
if self.first_run or self.old_call_itm == self.call_itm:
13301329
self.old_call_itm = self.call_itm
13311330
elif self.call_itm > self.old_call_itm:
@@ -1334,7 +1333,7 @@ def set_itm_labels(call_change: float, put_change: float) -> str:
13341333
else:
13351334
self.sheet.highlight_cells(row=last_row, column=7, bg=red)
13361335
self.old_call_itm = self.call_itm
1337-
self.old_put_itm: numpy.float64
1336+
self.old_put_itm: float
13381337
if self.first_run or self.old_put_itm == self.put_itm:
13391338
self.old_put_itm = self.put_itm
13401339
elif self.put_itm > self.old_put_itm:
@@ -1396,24 +1395,24 @@ def main(self) -> None:
13961395
call_oi_list.append(int_call_oi)
13971396
call_oi_index: int = call_oi_list.index(max(call_oi_list))
13981397
self.max_call_oi: float = round(max(call_oi_list) / self.round_factor, 1)
1399-
self.max_call_oi_sp: numpy.float64 = entire_oc.iloc[call_oi_index]['Strike Price']
1398+
self.max_call_oi_sp: float = float(entire_oc.iloc[call_oi_index]['Strike Price'])
14001399

14011400
put_oi_list: List[int] = []
14021401
for i in range(len(entire_oc)):
14031402
int_put_oi: int = int(entire_oc.iloc[i, [20]][0])
14041403
put_oi_list.append(int_put_oi)
14051404
put_oi_index: int = put_oi_list.index(max(put_oi_list))
14061405
self.max_put_oi: float = round(max(put_oi_list) / self.round_factor, 1)
1407-
self.max_put_oi_sp: numpy.float64 = entire_oc.iloc[put_oi_index]['Strike Price']
1406+
self.max_put_oi_sp: float = float(entire_oc.iloc[put_oi_index]['Strike Price'])
14081407

1409-
sp_range_list: List[numpy.float64] = []
1408+
sp_range_list: List[float] = []
14101409
for i in range(put_oi_index, call_oi_index + 1):
1411-
sp_range_list.append(entire_oc.iloc[i]['Strike Price'])
1410+
sp_range_list.append(float(entire_oc.iloc[i]['Strike Price']))
14121411

14131412
self.max_call_oi_2: float
1414-
self.max_call_oi_sp_2: numpy.float64
1413+
self.max_call_oi_sp_2: float
14151414
self.max_put_oi_2: float
1416-
self.max_put_oi_sp_2: numpy.float64
1415+
self.max_put_oi_sp_2: float
14171416
if self.max_call_oi_sp == self.max_put_oi_sp:
14181417
self.max_call_oi_2 = self.max_call_oi
14191418
self.max_call_oi_sp_2 = self.max_call_oi_sp
@@ -1433,15 +1432,15 @@ def main(self) -> None:
14331432
call_oi_list_2.append(int_call_oi_2)
14341433
call_oi_index_2: int = put_oi_index + call_oi_list_2.index(max(call_oi_list_2))
14351434
self.max_call_oi_2 = round(max(call_oi_list_2) / self.round_factor, 1)
1436-
self.max_call_oi_sp_2 = entire_oc.iloc[call_oi_index_2]['Strike Price']
1435+
self.max_call_oi_sp_2 = float(entire_oc.iloc[call_oi_index_2]['Strike Price'])
14371436

14381437
put_oi_list_2: List[int] = []
14391438
for i in range(put_oi_index + 1, call_oi_index + 1):
14401439
int_put_oi_2: int = int(entire_oc.iloc[i, [20]][0])
14411440
put_oi_list_2.append(int_put_oi_2)
14421441
put_oi_index_2: int = put_oi_index + 1 + put_oi_list_2.index(max(put_oi_list_2))
14431442
self.max_put_oi_2 = round(max(put_oi_list_2) / self.round_factor, 1)
1444-
self.max_put_oi_sp_2 = entire_oc.iloc[put_oi_index_2]['Strike Price']
1443+
self.max_put_oi_sp_2 = float(entire_oc.iloc[put_oi_index_2]['Strike Price'])
14451444

14461445
total_call_oi: int = sum(call_oi_list)
14471446
total_put_oi: int = sum(put_oi_list)
@@ -1462,46 +1461,42 @@ def main(self) -> None:
14621461

14631462
a: pandas.DataFrame = entire_oc[['Change in Open Interest']][entire_oc['Strike Price'] == self.sp]
14641463
b1: pandas.Series = a.iloc[:, 0]
1465-
c1: numpy.int64 = b1.get(index)
1464+
c1: int = int(b1.get(index))
14661465
b2: pandas.Series = entire_oc.iloc[:, 1]
1467-
c2: numpy.int64 = b2.get((index + 1), 'Change in Open Interest')
1466+
c2: int = int(b2.get((index + 1), 'Change in Open Interest'))
14681467
b3: pandas.Series = entire_oc.iloc[:, 1]
1469-
c3: numpy.int64 = b3.get((index + 2), 'Change in Open Interest')
1468+
c3: int = int(b3.get((index + 2), 'Change in Open Interest'))
14701469
if isinstance(c2, str):
1471-
# noinspection PyTypeChecker
14721470
c2 = 0
14731471
if isinstance(c3, str):
1474-
# noinspection PyTypeChecker
14751472
c3 = 0
1476-
self.call_sum: numpy.float64 = round((c1 + c2 + c3) / self.round_factor, 1)
1473+
self.call_sum: float = round((c1 + c2 + c3) / self.round_factor, 1)
14771474
if self.call_sum == -0:
14781475
self.call_sum = 0.0
1479-
self.call_boundary: numpy.float64 = round(c3 / self.round_factor, 1)
1476+
self.call_boundary: float = round(c3 / self.round_factor, 1)
14801477

14811478
o1: pandas.Series = a.iloc[:, 1]
1482-
p1: numpy.int64 = o1.get(index)
1479+
p1: int = int(o1.get(index))
14831480
o2: pandas.Series = entire_oc.iloc[:, 19]
1484-
p2: numpy.int64 = o2.get((index + 1), 'Change in Open Interest')
1485-
p3: numpy.int64 = o2.get((index + 2), 'Change in Open Interest')
1486-
self.p4: numpy.int64 = o2.get((index + 4), 'Change in Open Interest')
1481+
p2: int = int(o2.get((index + 1), 'Change in Open Interest'))
1482+
p3: int = int(o2.get((index + 2), 'Change in Open Interest'))
1483+
self.p4: int = int(o2.get((index + 4), 'Change in Open Interest'))
14871484
o3: pandas.Series = entire_oc.iloc[:, 1]
1488-
self.p5: numpy.int64 = o3.get((index + 4), 'Change in Open Interest')
1489-
self.p6: numpy.int64 = o3.get((index - 2), 'Change in Open Interest')
1490-
self.p7: numpy.int64 = o2.get((index - 2), 'Change in Open Interest')
1485+
self.p5: int = int(o3.get((index + 4), 'Change in Open Interest'))
1486+
self.p6: int = int(o3.get((index - 2), 'Change in Open Interest'))
1487+
self.p7: int = int(o2.get((index - 2), 'Change in Open Interest'))
14911488
if isinstance(p2, str):
1492-
# noinspection PyTypeChecker
14931489
p2 = 0
14941490
if isinstance(p3, str):
1495-
# noinspection PyTypeChecker
14961491
p3 = 0
14971492
if isinstance(self.p4, str):
14981493
self.p4 = 0
14991494
if isinstance(self.p5, str):
15001495
self.p5 = 0
1501-
self.put_sum: numpy.float64 = round((p1 + p2 + p3) / self.round_factor, 1)
1502-
self.put_boundary: numpy.float64 = round(p1 / self.round_factor, 1)
1503-
self.difference: float = float(round(self.call_sum - self.put_sum, 1))
1504-
self.call_itm: numpy.float64
1496+
self.put_sum: float = round((p1 + p2 + p3) / self.round_factor, 1)
1497+
self.put_boundary: float = round(p1 / self.round_factor, 1)
1498+
self.difference: float = round(self.call_sum - self.put_sum, 1)
1499+
self.call_itm: float
15051500
if self.p5 == 0:
15061501
self.call_itm = 0.0
15071502
else:
@@ -1512,7 +1507,7 @@ def main(self) -> None:
15121507
self.p6 = 0
15131508
if isinstance(self.p7, str):
15141509
self.p7 = 0
1515-
self.put_itm: numpy.float64
1510+
self.put_itm: float
15161511
if self.p7 == 0:
15171512
self.put_itm = 0.0
15181513
else:

0 commit comments

Comments
 (0)