Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- from numpy import *
- from scipy.optimize import minimize
- def getBestStrategyOn2Day2(firstDay, secondDay):
- def f(moneyDistr):
- result = 0.
- for i in range(len(firstDay)):
- if( firstDay[i] == 0 ):
- result += 0
- else:
- result += (secondDay[i] / firstDay[i])*moneyDistr[i]
- return result
- def rosen(x):
- x = x / x.sum()
- return 1/f(x)
- result = np.zeros((len(firstDay)))
- bnd = tuple(np.ones(len(firstDay)))
- bnd2 = tuple(np.ones(len(firstDay))*100)
- bnd3 = list(zip(bnd,bnd2))
- res = minimize(rosen, result, method='TNC', bounds = bnd3)
- return res.x / res.x.sum()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement