Skip to content

Instantly share code, notes, and snippets.

@druce
Created December 20, 2020 22:11
Show Gist options
  • Select an option

  • Save druce/015ff8dd7aa24f0a9ffab176ffce36bb to your computer and use it in GitHub Desktop.

Select an option

Save druce/015ff8dd7aa24f0a9ffab176ffce36bb to your computer and use it in GitHub Desktop.
po6.py
vol_limit = cp.Parameter(nonneg=True)
prob = cp.Problem(cp.Maximize(ret),
[cp.norm1(w) <= 1.5, # 1-norm <= 1.5, i.e. gross exposure < 150%
cp.sum(w) == 1,
vol <= vol_limit]
)
# define function so we can solve many in parallel
def solve_vl(vl_val):
vol_limit.value = vl_val
result = prob.solve()
return (ret.value, np.sqrt(vol.value), w.value)
# number of points on the frontier
NPOINTS = 200
vl_vals = np.linspace(minvol, maxretvol, NPOINTS)
# iterate in-process
results_dict = {}
for vl_val in vl_vals:
results_dict[vl_val] = solve_vl(vl_val)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment