gpt4 book ai didi

python - 缺少1个必需的位置参数-财务

转载 作者:行者123 更新时间:2023-12-03 08:18:36 26 4
gpt4 key购买 nike

我尝试进行投资组合优化,但随后出现了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']

最佳答案

我认为需要像这样引用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)

关于python - 缺少1个必需的位置参数-财务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62506069/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com