I am trying to optimize a function. But this function takes a pandas data frame as an argument. So when I run the code, I get this error:
TypeError: 'DataFrame' objects are mutable, thus they cannot be hashed
My evaluation function:
def calc_sr(prices, allocs):
cum_ret_prices = prices / prices.iloc[0]
all_adj_prices = allocs * cum_ret_prices
daily_value = all_adj_prices.sum(1)
sr = daily_value.mean()/daily_value.std()
return(sr)
def eval_fn(allocs, prices):
return 1/calc_sr(prices,allocs)
allocs = optimize.minimize(eval_fn,allocs,args={prices},method = 'Nelder-Mead', options={'maxiter':10000})
Prices is a pandas data frame.
How do I optimize this? Also one more question is that my optimization function needs the array of initial guesses to be passed in as well. SO how do I account for that when I set the args parameter?