hi whats wrong with my coding , it runs successfully but taking too much time to finish the task , it is taking 40 min to 2 hrs , i have laptop with configuration of i7 and 8gb ram THE FOLLOWING ARE MY CODE rom nsepy import get_history
import pandas as pd
import numpy as np import kiteconnect from datetime import datetime, date, timedelta from kiteconnect import KiteConnect
def write_log(text): f = open(r'log.txt', 'a') f.write("{}\n".format(text))
cash_df = pd.DataFrame() # this variable will contain fetched cash data
print('CASH DATA EXTRACTION BEGINS:', datetime.today().time()) write_log(text=['CASH DATA EXTRACTION BEGINS:', datetime.today().time()])
# Connecting To Zerodha API (Kite) self.kite = KiteConnect(api_key='crpko3b6x4nw47ym') self.kite.set_access_token(kite_token)
# Fetching Derivatives data from API derivative_data = self.kite.instruments(exchange='NFO') derivative_data = pd.DataFrame(derivative_data) derivative_data.expiry = derivative_data.expiry.astype('datetime64[ns]').dt.date
# Slicing options data from derivative data self.pc_data = derivative_data[derivative_data['instrument_type'] != 'FUT'] self.pc_data.reset_index(drop=True, inplace=True)
if chance < 5: if ans > 2.5: # this loop is for replacing PCR value, when we get PCR greater than 2.5 ans = 2.5
if len(expiry) == 1 and index == 0: ratio = {'Symbol': j, 'PCR': ans, 'Weekly PCR': np.nan} pcr.append(ratio) elif len(expiry) == 2 and index == 0: ratio = {'Symbol': j, 'PCR': ans, 'Weekly PCR': np.nan} pcr.append(ratio) elif len(expiry) == 2 and index == 1: pcr[-1]['Weekly PCR'] = ans
pcr_df = pd.DataFrame(pcr) # this dataframe will now contain PCR of different tickers
print('FUTURE OI CALCULATION BEGINS:', datetime.today().time()) write_log(text=['FUTURE OI CALCULATION BEGINS:', datetime.today().time()])
# Slicing futures data from derivative data futures_expiry_date = self.get_expiry(self.start_date, symbol='RELIANCE', w_m='MONTHLY') future_data = derivative_data[derivative_data['instrument_type'] == 'FUT'] future_data = future_data[future_data['expiry'] == futures_expiry_date]
oi_data = [] # this variable will contain OI
print('CREATION OF FINAL DF FOR CSV FILE BEGINS:', datetime.today().time()) write_log(text=['CREATION OF FINAL DF FOR CSV FILE BEGINS:', datetime.today().time()])