I have a function an objective function which takes a data frame of time series data which it uses to calculate an estimated return on investment over the time data. This function is shown below:
def bwp(x, processed):
pred,real = x
money = 1000
for i in range(0, len(processed)):
if processed[i, 3] > pred and processed[i-1,4] > real:
money = money (money * processed[i, 4])
return money * -1
I want to minimize this function, it is a cheap and discontinuous so I want to use a brute method to optimize this.
I am trying to optimize this with the following code:
def opt_2(processed):
bounds = (slice(-1, 1), slice(-1, 1))
resbrute = optimize.brute(bwp, ranges=bounds, args=processed, full_output=True, finish=optimize.fmin)
print(resbrute[0])
print(resbrute[1])
the dataframe 'proceessed' is a dataset containing 3757 rows. The error I get when running this is:
TypeError: bwp() takes 2 positional arguments but 3757 were given
I am not sure why this doesn't work as I have run another function with Scipy using the 'nelder-mead' method and provided the dataframe to 'args' in the same way as I did above and it was able to pass the dataframe through to the function.
Does anyone have experience with this?
CodePudding user response:
Shouldn't the signature of bwp
be:
# HERE ----v
def bwp(x, *processed):
...
rather than:
def bwp(x, processed):
...