Skip to content

Instantly share code, notes, and snippets.

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

  • Save druce/73d83ee614979c45b4e8e62e0011fc88 to your computer and use it in GitHub Desktop.

Select an option

Save druce/73d83ee614979c45b4e8e62e0011fc88 to your computer and use it in GitHub Desktop.
po5.py
vol_limit = cp.Parameter(nonneg=True)
prob = cp.Problem(cp.Maximize(ret),
[cp.sum(w) == 1,
w >= 0,
vol <= vol_limit # new constraint: vol <= vol_limit parameter
]
)
# define helper function
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 over vl_vals
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