Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. import numpy as np
  2. from numpy import *
  3. from scipy.optimize import minimize
  4.  
  5. def getBestStrategyOn2Day2(firstDay, secondDay):
  6.    
  7.     def f(moneyDistr):
  8.         result = 0.
  9.         for i in range(len(firstDay)):
  10.             if( firstDay[i] == 0 ):
  11.                 result += 0
  12.             else:
  13.                 result += (secondDay[i] / firstDay[i])*moneyDistr[i]
  14.         return result
  15.    
  16.    
  17.     def rosen(x):
  18.         x = x / x.sum()
  19.         return 1/f(x)
  20.  
  21.     result = np.zeros((len(firstDay)))
  22.    
  23.    
  24.     bnd = tuple(np.ones(len(firstDay)))
  25.    
  26.     bnd2 = tuple(np.ones(len(firstDay))*100)
  27.    
  28.     bnd3 = list(zip(bnd,bnd2))
  29.                      
  30.     res = minimize(rosen, result, method='TNC', bounds = bnd3)
  31.    
  32.  
  33.     return res.x / res.x.sum()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement