0

I tried to do Portfolio optimization, but then the TypeError: minimize_sharpe() missing 1 required positional argument: 'log_returns' appeared: Please find the extract below.

import scipy.optimize as optimize 
optimal_sharpe=optimize.minimize(minimize_sharpe,
                                 initializer,
                                 method = 'SLSQP',
                                 bounds = bounds,
                                 constraints = constraints)
print(optimal_sharpe)

The definition of "minimize_sharpe comes with the following code

def minimize_sharpe(weights, log_returns):  
return -portfolio_stats(weights)['Sharpe']
pppery
  • 3,434
  • 13
  • 24
  • 37

1 Answers1

1

I think args needs to be referenced like this. The example that you are referring to may also not be passing returns to the portfolio_stats function.

def minimize_sharpe(weights, returns):  
    return -portfolio_stats(weights,returns)['sharpe'] 

import scipy.optimize as optimize
optimal_sharpe=optimize.minimize(minimize_sharpe,
                                 initializer,
                                 args = (returns,),
                                 method = 'SLSQP',
                                 bounds = bounds,
                                 constraints = constraints)
Charles
  • 380
  • 3
  • 15