I would like to minimize the following function (16)
Note that the phi function is defined as follows:
My Problem I then try to use the
from scipy.optimize import minimize
to minimize function (16). However, (16) has an the infinite sum from (15). How can I implement this in Python? Can the optimize function minimize an infinite sum? Right now I just defined the formula, set the infinite sum to sum only until n = 10.
def formula(x):
return -sum(math.log(sum(1/math.sqrt(
2*math.pi*(x[1]**2/252+n*x[4]**2))*math.exp(
-(y-(x[0]/252+n*x[3]))**2/(2*(x[1]**2/252
+n*x[4]**2)))*math.exp(
-x[2]/252)*(x[2]/252)**n/math.factorial(n)
for n in range(1,10))) for y in difference)
guess = np.array([0.1,0.1,0.1,0.1,1])
results = minimize(formula, guess, method = 'Nelder-Mead', options={'ftol':0.01, 'xtol':0.01})