Passing definition parameters - strange results?
I am learning Python and CQ API at the same time, and have run across something I don't understand...
Below is the simple code to show the problem.
The function "mean2", which ignores the unexpected first parameter, will work; but I don't understand where the first parameter is coming from, and will this always be the case, so I can always disregard that first parameter?
Thank you for any assistance!
# TW - Calculate mean of list def mean(numbers): #Intended code return sum(float(i) for i in numbers)/len(numbers) def mean2(numbers,other): # Created for debugging print 'numbers: ' + str(numbers) +'\n' print 'other: ' + str(other)+'\n' return sum(float(i) for i in other)/len(other)
# called at the beginning of each instance def on_start(self, md, order, service, account): print('On Start: Current Symbols:\t' + self.symbol + '\n') # Breadcrumb to see where we are self.bar_data_5d = md.bar.daily(start=-5) # Get 5 days of data print 'count of highs: ' + str(len(self.bar_data_5d.high)) # Verify how many are returned # Brute force calculation average_highs = (self.bar_data_5d.high+self.bar_data_5d.high+self.bar_data_5d.high+self.bar_data_5d.high+self.bar_data_5d.high)/5 print 'average_highs1: '+ str(average_highs) # More elegant calculation for generalized use average_highs2 = sum(float(i) for i in self.bar_data_5d.high)/len(self.bar_data_5d.high) print 'average_highs2: '+ str(average_highs2) # Now lets use a function print 'mean_Func:' + str(self.mean2(self.bar_data_5d.high)) # Get Strange error that 2 parameters were passed to function !!??!! # Created debug version of funciton - it created output, below
########### Console Output
On Strategy_Start: ...
On Start: Current Symbols: SPY
count of highs: 5
numbers: ' CQ80b5f3a805994ab3b218ce8771378606 object at 0x7f1c090a99d0' <-- Where does this come from (originally enclosed in angle brackets)?
other: [ 242.71000671 243.38000488 243.00999451 242.02999878 242.27999878] <-- this is all I expected to be passed!
On Finish: Current Symbols: SPY
On Strategy_Finish: ...