看起来我不能在 JuMP 中的目标搜索代码的目标中使用向量/矩阵的转置。我收到此问题标题中所述的错误。任何人都可以提出解决这个问题的方法吗?
代码:
using JuMP, ECOS
Supertech = [-.2, .1, .3, .5];
Slowpoke = [.05, .2, -.12, .09];
A = reshape([vec(Supertech); vec(Slowpoke)],length(Slowpoke),2)
mlen = size(A)[1]
R = vec(mean(A,1))
n=rank(A)
λ = .100
items = [λ; 1-λ]
m = Model(solver=ECOSSolver())
@variable(m, 0 <= take[items] <= 1) # Define a variable for each item
sharpe_ratio = vec(sqrt(mlen) * (take' * R) / sqrt(sum(vec(take' .* take) .* vec(cov(A,1,false)))))[1]
@objective(m, Max, sharpe_ratio)
@constraint(m, sum(take) == 1)
solve(m)
println(getvalue(take))