Created
December 20, 2020 22:09
-
-
Save druce/73d83ee614979c45b4e8e62e0011fc88 to your computer and use it in GitHub Desktop.
po5.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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