Created
December 20, 2020 22:11
-
-
Save druce/015ff8dd7aa24f0a9ffab176ffce36bb to your computer and use it in GitHub Desktop.
po6.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.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