这段代码可以怎么优化呀
运行计算效率低得离谱,我也找不出问题在哪里
for i in range(0, (endtime - starttime).seconds + 1):
tradingtime = starttime + timedelta(seconds=i)
if str(tradingtime.time()) not in time1:
print(tradingtime)
try:
underlying_510300 = price_data['510300'].get_group(tradingtime).tail(1)['pre_close'].values
underlying_000300 = price_data['000300'].get_group(tradingtime).tail(1)['pre_close'].values
except Exception as e:
underlying_510300 = \
price.get_group('510300')[price.get_group('510300')['inserttime'].dt.time <= tradingtime.time()].tail(
1)['pre_close'].values
underlying_000300 = \
price.get_group('000300')[price.get_group('000300')['inserttime'].dt.time <= tradingtime.time()].tail(
1)['pre_close'].values
MKT_data = {}
for code in code_group:
try:
option_data = price_data[code].get_group(tradingtime).tail(1)
except Exception as e:
option_data = price.get_group(code)[
price.get_group(code)['inserttime'].dt.time <= tradingtime.time()].tail(1)
if INFO_group[code]['underlying'] == '510300':
option_data['underlying_price'] = underlying_510300
else:
option_data['underlying_price'] = underlying_000300
MKT_data[code] = option_data