I can use cvxopt to calculate the effective border in documents:
http://cvxopt.org/examples/book/portfolio.html
However, I cannot figure out how to add a restriction, so there is an upper bound for a certain allowable weight of the asset. Is cvxopt possible?
Here is my code so far, which creates an efficient border without restrictions, except that I believe b, which sets the maximum sum of weights to 1. I'm not sure what G, h, A and mus do, and the documents really don't explain . Where is 10 ** (5.0 * t / N-1.0) in the formula for mus?
from math import sqrt
from cvxopt import matrix
from cvxopt.blas import dot
from cvxopt.solvers import qp, options
n = 4
S = matrix( [[ 4e-2, 6e-3, -4e-3, 0.0 ],
[ 6e-3, 1e-2, 0.0, 0.0 ],
[-4e-3, 0.0, 2.5e-3, 0.0 ],
[ 0.0, 0.0, 0.0, 0.0 ]] )
pbar = matrix([.12, .10, .07, .03])
G = matrix(0.0, (n,n))
G[::n+1] = -1.0
h = matrix(0.0, (n,1))
A = matrix(1.0, (1,n))
b = matrix(1.0)
N = 100
mus = [ 10**(5.0*t/N-1.0) for t in range(N) ]
options['show_progress'] = False
xs = [ qp(mu*S, -pbar, G, h, A, b)['x'] for mu in mus ]
returns = [ dot(pbar,x) for x in xs ]
risks = [ sqrt(dot(x, S*x)) for x in xs ]
plt.plot(risks, returns)