I am working in python 2.6. Can anyone figure out why my variable squared does not calculate properly when it is inside a min() function? To illustrate, I show the variable**2 performed by itself, works fine. Here is the code, followed by some results:
from __future__ import with_statement
import csv, re, time
timestr = time.strftime("%Y%m%d_%H%M%S")
fileinput = 'mp_20130822.csv'
out = open('output2.csv',"wb")
writer = csv.writer(out, delimiter = ',')
ESPmax = 100.00
dynmax = "enabled"
def config():
global argument
if z>30:
argument = "T"
else:
argument = "F"
with open(fileinput,'rU') as inputfile:
reader = csv.reader(inputfile, delimiter = ';')
for line in reader:
line = re.split(",| ",line[0])
side = str(line[4]) #is "Bid" or "Ask"
e = float(line[5])
z = float(line[6])
t = float(line[33])
FW = float(line[34])
FS = max(float(line[35]),200)
if FW == 0:
continue
if (FS == 0) or (FS == 1):
continue
if side == "Ask":
LE = t-e
else:
LE = e-t
LEP = LE/(FW/2)
ESP = z/(FS/2)
if dynmax == "enabled":
ESPmax = min(LEP**2,ESPmax)
config()
if (argument == "T"):
print ('side, e, z, t, FW, FS')
print ('LEP,LEP,ESPmax')
print (side, '%.2f'%e, '%.2f'%z, '%.2f'%t, '%.2f'%FW, '%.2f'%FS)
print ('%.3f'%LEP,'%.3f'%LEP,'%.5f'%ESPmax)
print '%.5f'%(LEP*LEP)
RESULTS:
side, e, z, t, FW, FS
LEP,LEP,ESPmax
('Ask', '1.90', '50.00', '1.95', '0.24', '651.00')
('0.423', '0.423', '0.00130')
0.17880
side, e, z, t, FW, FS
LEP,LEP,ESPmax
('Ask', '8.40', '40.00', '8.43', '0.17', '4933.00')
('0.348', '0.348', '0.00130')
0.12145
side, e, z, t, FW, FS
LEP,LEP,ESPmax
('Ask', '8.40', '40.00', '8.43', '0.17', '4919.00')
('0.370', '0.370', '0.00130')
0.13667