I have a portfolio or $N$ assets in $t=10$ days.
import numpy as np
import pandas as pd
n= 10
A = pd.DataFrame([np.random.randn(5) for i in range(n)],columns=['a', 'b', 'c', 'd', 'e'])
A
T = A.shape[0]
k = A.shape[1]
print(T,k)
The covariance matrix
Σ = A.cov().to_numpy()
Sigma = Σ
print(Sigma)
I want to minimize the variance with convex optimization in Python.
Actually I want to solve the
$$\min \quad (1/2) w^T \Sigma w$$ s.t $$w_{i}\geq 0,\sum_{i=1}^{n}w_{I} =1$$
So I do :
import cvxpy as cp
w = cp.Variable(n)
# Defining risk objective
risk = cp.quad_form(w,Sigma)
objective = cp.Minimize((1/2)*risk)
# Budget and weights constraints
constraints = [cp.sum(w) == 1,
w >= 0]
# Solver
prob = cp.Problem(objective, constraints)
prob.solve()
but I receive an error:
Exception: Invalid dimensions for arguments.
what is my mistake here ? Anybody ?