I want to optimize my function Strategy2(alpha, beta)
, which performs a betting strategy on some data, starting with a wallet value of 20,000, and returns a new wallet value.
So I need to find the optimum alpha
& beta
values that maximize the returned value.
A quick google suggests that scipy is the way to go, but I am struggling to implement it.
Before attempting this optimization approach I took the approach of fixing alpha, and then finding the optimum beta, then doing the same with fixing beta and finding the optimum alpha.
That approach gave an optimum of Strategy2(23,3)
which returned 24,650.
Here is my attempt to implement the minimize method found in the module scipy:
import numpy as np
from scipy.optimize import minimize
bnds = ((None, None), (None, None))
param = [0, 0]
f = lambda param: Strategy2(param[0], param[1])
param_init = 0, 100
param = minimize(f, param_init, method='SLSQP', bounds=bnds).x
print(param)
As you can see, I don't really know what I am doing, indeed this simply just returns
[ 0. 100.]
with a final wallet value of 10,705. Which is clearly less than 24,650. So something is clearly not working.
How can I get it so I maximize Strategy2(alpha, beta)
? Ideally I want to vary alpha from 0 to 100, and vary beta from 1 to 15.
Thanks in advance.
EDIT: My reasoning for the above code was that I was just trying to adapt the following working code:
import numpy as np
from scipy.optimize import lsq_linear, minimize
bnds = ((None, None), (None, None))
fun = lambda param: np.linalg.norm(-np.exp(param[0]) + param[1])
param_init = -4, 4
param = minimize(fun, param_init, method='SLSQP', bounds=bnds).x
which correctly minimise the above function.
If there is a better way to maximise my function then please let me know.