0

我尝试进行投资组合优化,但随后TypeError: minimize_sharpe() missing 1 required positional argument: 'log_returns'出现:请在下面找到摘录。

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

“minimize_sharpe”的定义自带如下代码

def minimize_sharpe(weights, log_returns):  
return -portfolio_stats(weights)['Sharpe']
4

1 回答 1

1

我认为 args 需要像这样引用。您所指的示例也可能不会将返回值传递给portfolio_stats 函数。

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)
于 2020-09-11T13:20:46.053 回答