import%20marimo%0A%0A__generated_with%20%3D%20%220.15.2%22%0Aapp%20%3D%20marimo.App()%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22!%5BMOSEK%20ApS%5D(https%3A%2F%2Fwww.mosek.com%2Fstatic%2Fimages%2Fbranding%2Fwebgraphmoseklogocolor.png%20)%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%20Risk%20measures%0A%0A%20%20%20%20The%20value-at-risk%20(VaR)%20of%20a%20random%20variable%20%24X%24%20at%20risk%20level%20%24%5Calpha%24%20is%20defined%20as%0A%20%20%20%20%24%24%5Ctextrm%7BVaR%7D_%5Calpha(X)%20%3D%20%5Cmin_%5Ceta%5Cleft(%5Cmathbb%7BP%7D%5BX%5Cgeq%5Ceta%5D%5Cleq%201-%5Calpha%5Cright)%24%24%0A%20%20%20%20and%20the%20conditional%20value-at-risk%20(CVaR)%20is%20the%20conditional%20expected%20value%0A%20%20%20%20%24%24%5Ctextrm%7BCVaR%7D_%5Calpha(X)%3D%5Cmathbb%7BE%7D(X~%7C~X%5Cgeq%5Ctextrm%7BVaR%7D_%5Calpha(X)).%24%24%0A%20%20%20%20In%20the%20standard%20setting%20where%20the%20random%20variable%20%24X%24%20represents%20a%20loss%20(on%20an%20investment)%20and%20we%20take%20%24%5Calpha%3D0.9%24%2C%20CVaR%20can%20be%20interpreted%20as%20the%20expected%20loss%20assuming%20we%20end%20up%20in%20the%20%2410%5C%25%24%20worst%20scenarios.%20The%20concept%20was%20studied%20in%20the%20paper%20%3Ca%20href%3D%22https%3A%2F%2Fsites.math.washington.edu%2F~rtr%2Fpapers%2Frtr179-CVaR1.pdf%22%3EOptimization%20of%20Conditional%20Value-at-Risk%3C%2Fa%3E%2C%20Rockafellar%20and%20Uryasev%2C%20Journal%20of%20Risk%2C%202002%2C%20where%20we%20also%20find%20an%20equivalent%20formula%0A%20%20%20%20%24%24%5Ctextrm%7BCVaR%7D_%5Calpha(X)%3D%5Cmin_%5Ceta%5Cleft(%5Ceta%2B(1-%5Calpha)%5E%7B-1%7D%5Cmathbb%7BE%7D(%5BX-%5Ceta%5D%5E%2B)%5Cright)%24%24%0A%20%20%20%20where%20%24%5Bx%5D%5E%2B%3D%5Cmax(x%2C0)%24.%0A%0A%20%20%20%20Some%20authors%20consider%20generalizations%0A%20%20%20%20%24%24%5Crho%5Ef_%5Calpha(X)%3D%5Cmin_%5Ceta%5Cleft(%5Ceta%2B(1-%5Calpha)%5E%7B-1%7Df%5E%7B-1%7D%5Cleft(%5Cmathbb%7BE%7D(f(X-%5Ceta))%5Cright)%5Cright)%2C%24%24%0A%20%20%20%20where%20%24f%24%20is%20any%20increasing%2C%20convex%20function%20on%20%24%5Cmathbb%7BR%7D_%2B%24%20which%20is%20identically%20zero%20on%20%24%5Cmathbb%7BR%7D_-%24.%20Examples%20include%3A%0A%20%20%20%20*%20%24f(x)%3D%5Bx%5D%5E%2B%24%2C%20recovering%20the%20previous%20definition%20of%20CVaR%2C%0A%20%20%20%20*%20%24f(x)%3D%5Cexp(%5Bt%5D%5E%2B)-1%24%2C%20log-exponential%20convex%20risk%20measure%20(LogExpCR)%2C%20%3Ca%20href%3D%22https%3A%2F%2Fdoi.org%2F10.1016%2Fj.disopt.2016.07.002%22%3E(Vinel%2C%20Krokhmal%202017)%3C%2Fa%3E%2C%0A%20%20%20%20*%20%24f(x)%3D(%5Bx%5D%5E%2B)%5Eq%24%2C%20higher%20moment%20coherent%20risk%20measures%20(HMCR)%20%3Ca%20href%3D%22https%3A%2F%2Fdoi.org%2F10.1080%2F14697680701458307%22%3E(Krokhmal%202007)%3C%2Fa%3E.%0A%0A%20%20%20%20%23%20Stochastic%20portfolio%20optimization%0A%0A%20%20%20%20In%20this%20notebook%20we%20implement%20the%20models%20described%20in%20Section%205%20of%20%3Ca%20href%3D%22https%3A%2F%2Fdoi.org%2F10.1016%2Fj.disopt.2016.07.002%22%3E(Vinel%2C%20Krokhmal%202017)%3C%2Fa%3E%20with%20various%20risk%20measures.%20We%20consider%20the%20problem%20of%20investing%20in%20%24n%24%20stocks%20given%20%24m%24%20historical%20return%20vectors%20%24r_1%2C%5Cldots%2Cr_m%5Cin%5Cmathbb%7BR%7D%5En%24%20%20taken%20with%20probabilities%20%24p_1%2C%5Cldots%2Cp_m%24.%20We%20consider%20the%20following%20conditions%3A%0A%0A%20%20%20%20*%20total%20budget%20constraint%3A%0A%20%20%20%20%20%20%24%241%5ETx%5Cleq%201%24%24%0A%20%20%20%20*%20minimal%20expected%20return%3A%0A%20%20%20%20%20%20%24%24x%5ET%5Cmathbb%7BE%7D(%5Cmu)%5Cgeq%20%5Cbar%7Br%7D%24%24%0A%20%20%20%20%20%20where%20%24%5Cmu%24%20is%20the%20uncertain%20vector%20of%20returns%2C%20%24%5Cmathbb%7BE%7D(%5Cmu)%3D%5Csum_j%20p_jr_j%24%20is%20its%20expected%20value%20averaged%20over%20the%20historical%20scenarios%2C%20and%20%24%5Cbar%7Br%7D%24%20is%20the%20minimal%20required%20expected%20return%20level.%0A%20%20%20%20*%20no%20short-selling%3A%0A%20%20%20%20%20%20%24%24x%5Cgeq%200%24%24%0A%20%20%20%20*%20the%20objective%20represents%20minimization%20of%20CVaR%20%24%5Crho%5Ef_%5Calpha(-%5Cmu%5ETx)%24%20of%20the%20loss%20%24-%5Cmu%5ETx%24%2C%20that%20is%0A%20%20%20%20%20%20%24%24%5Ctextrm%7Bminimize%7D_%7B%5Ceta%2Cx%7D%5Cleft(%5Ceta%2B(1-%5Calpha)%5E%7B-1%7Df%5E%7B-1%7D(%5Csum_%7Bj%3D1%7D%5Emp_jf(-r_j%5ETx-%5Ceta))%5Cright)%24%24%0A%0A%20%20%20%20We%20used%20a%20preprocessed%20file%20with%20closing%20prices%20from%20NYSE%20for%201675%20assets%20over%202050%20trading%20days.%20Each%20historical%20scenario%20is%20defined%20by%20computing%20returns%20of%20all%20assets%20over%20some%20period%20of%2010%20trading%20days%20They%20are%20returned%20in%20a%20martix%20%24r%24%20with%20%24n%24%20rows%20and%20%24m%24%20columns.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20'%25matplotlib%20inline'%20command%20supported%20automatically%20in%20marimo%0A%20%20%20%20import%20matplotlib%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20from%20mosek.fusion%20import%20Model%2C%20Domain%2C%20Expr%2C%20ObjectiveSense%2C%20Matrix%2C%20Var%2C%20SolutionStatus%0A%0A%20%20%20%20import%20mosek.fusion.pythonic%0A%20%20%20%20import%20numpy%20as%20np%20%0A%20%20%20%20import%20sys%2C%20os%2C%20csv%0A%0A%20%20%20%20allPrices%20%3D%20np.array(list(csv.reader(open(%22allPrices.txt%22)%2C%20lineterminator%3D'%5Cn'%2C%20quoting%3Dcsv.QUOTE_NONNUMERIC)))%0A%20%20%20%20n%2Cm%20%3D%20allPrices.shape%0A%20%20%20%20p1%20%20%3D%20allPrices%5B%3A%2C0%3Am-10%5D%0A%20%20%20%20p2%20%20%3D%20allPrices%5B%3A%2C10%3Am%5D%0A%20%20%20%20r%20%20%20%3D%20(p2-p1)%2Fp1%0A%20%20%20%20print(r.shape)%0A%20%20%20%20return%20Domain%2C%20Expr%2C%20Model%2C%20ObjectiveSense%2C%20Var%2C%20np%2C%20plt%2C%20r%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%20CVaR%0A%0A%20%20%20%20We%20first%20implement%20the%20linear%20CVaR%20model%20with%20%24f(x)%3D%5Bx%5D%5E%2B%24.%20We%20can%20then%20write%20the%20problem%20as%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Bll%7D%0A%20%20%20%20%5Ctext%7Bminimize%7D%20%26%20%20%5Ceta%20%2B%20(1-%5Calpha)%5E%7B-1%7D%20p%5ETw%5C%5C%0A%20%20%20%20%5Ctext%7Bsubject%20to%7D%20%26%201%5ETx%5Cleq%201%2C%20%5C%5C%0A%20%20%20%20%20%26%20x%5ETrp%5Cgeq%20%5Cbar%7Br%7D%2C%20%5C%5C%0A%20%20%20%20%20%26%20w_j%5Cgeq%20%5Cmax%5C%7B0%2C%20-r_j%5ETx-%5Ceta%20%5C%7D%2C%20%5Cquad%20j%3D1%2C%5Cldots%2Cm%2C%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20with%20variables%20%24x%5Cin%5Cmathbb%7BR%7D%5En%2C%20w%5Cin%5Cmathbb%7BR%7D%5Em%2C%20%5Ceta%5Cin%5Cmathbb%7BR%7D%24.%20Below%20is%20the%20Fusion%20implementation.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Domain%2C%20Expr%2C%20Model%2C%20ObjectiveSense%2C%20Var)%3A%0A%20%20%20%20def%20modelCVaR(alpha%2C%20rbar%2C%20p%2C%20r%2C%20m%2C%20n)%3A%20%20%20%0A%20%20%20%20%20%20%20%20M%20%3D%20Model(%22CVaR%22)%0A%0A%20%20%20%20%20%20%20%20%23%20Variables%0A%20%20%20%20%20%20%20%20X%20%20%20%3D%20M.variable('X'%2C%20n%2C%20Domain.greaterThan(0.0))%0A%20%20%20%20%20%20%20%20W%20%20%20%3D%20M.variable('W'%2C%20m%2C%20Domain.greaterThan(0.0))%0A%20%20%20%20%20%20%20%20eta%20%3D%20M.variable('eta')%0A%0A%20%20%20%20%20%20%20%20%23%20The%20bounds%20w_j%20%2B%20r_j%5ETx%20%2B%20eta%20%5Cgeq%200%0A%20%20%20%20%20%20%20%20M.constraint(W%20%2B%20r.T%20%40%20X%20%2B%20Var.vrepeat(eta%2C%20m)%20%3E%3D%200)%0A%20%20%20%20%20%20%20%20%23%20Minimal%20risk%0A%20%20%20%20%20%20%20%20M.constraint(X.T%20%40%20(r%20%40%20p)%20%3E%3D%20rbar)%20%0A%20%20%20%20%20%20%20%20%23%20Budget%0A%20%20%20%20%20%20%20%20M.constraint(Expr.sum(X)%20%3C%3D%201.0)%0A%0A%20%20%20%20%20%20%20%20%23%20Set%20the%20objective%20%0A%20%20%20%20%20%20%20%20M.objective(ObjectiveSense.Minimize%2C%20eta%20%2B%20W.T%20%40%20p%20%2F%20(1-alpha))%0A%0A%20%20%20%20%20%20%20%20return%20M%0A%20%20%20%20return%20(modelCVaR%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%20LogExpCR%0A%0A%20%20%20%20Next%20we%20have%20%24f(x)%3D%5Cexp(%5Bx%5D%5E%2B)-1%24.%20Since%20%24%5Csum_j%20p_j%3D1%24%2C%20the%20model%20can%20equivalently%20be%20formulated%20as%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Bll%7D%0A%20%20%20%20%5Ctext%7Bminimize%7D%20%26%20%20%5Ceta%20%2B%20(1-%5Calpha)%5E%7B-1%7D%20t%5C%5C%0A%20%20%20%20%5Ctext%7Bsubject%20to%7D%20%26%201%5ETx%5Cleq%201%2C%20%5C%5C%0A%20%20%20%20%20%26%20x%5ETrp%5Cgeq%20%5Cbar%7Br%7D%2C%20%5C%5C%0A%20%20%20%20%20%26%20w_j%5Cgeq%20%5Cmax%5C%7B0%2C%20-r_j%5ETx-%5Ceta%20%5C%7D%2C%20%5Cquad%20j%3D1%2C%5Cldots%2Cm%2C%20%5C%5C%0A%20%20%20%20%20%26%20t%5Cgeq%20%5Clog%5Cleft(%5Csum_j%20p_j%5Cexp(w_j)%5Cright).%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20last%20bound%20(log-sum-exp%20constraint)%20can%20be%20expressed%20using%20an%20auxiliary%20variable%20%24%5Cxi%5Cin%5Cmathbb%7BR%7D%5Em%24%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Bl%7D%0A%20%20%20%20p%5ET%5Cxi%20%5Cleq%201%2C%20%5C%5C%0A%20%20%20%20%5Cxi_j%5Cgeq%20%5Cexp(w_j-t)%2C%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20where%20the%20last%20inequality%20is%20conic-representable%20as%20%24(%5Cxi_j%2C1%2Cw_j-t)%5Cin%20K_%5Cmathrm%7Bexp%7D%24.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Domain%2C%20Expr%2C%20Model%2C%20ObjectiveSense%2C%20Var)%3A%0A%20%20%20%20def%20modelLogExpCR(alpha%2C%20rbar%2C%20p%2C%20r%2C%20m%2C%20n)%3A%20%20%20%0A%20%20%20%20%20%20%20%20M%20%3D%20Model(%22LogExpCR%22)%0A%0A%20%20%20%20%20%20%20%20%23%20Variables%0A%20%20%20%20%20%20%20%20X%20%20%20%3D%20M.variable('X'%2C%20n%2C%20Domain.greaterThan(0.0))%0A%20%20%20%20%20%20%20%20W%20%20%20%3D%20M.variable('W'%2C%20m%2C%20Domain.greaterThan(0.0))%0A%20%20%20%20%20%20%20%20eta%20%3D%20M.variable('eta')%0A%20%20%20%20%20%20%20%20xi%20%20%3D%20M.variable('xi'%2C%20m)%20%0A%20%20%20%20%20%20%20%20t%20%20%20%3D%20M.variable('t')%20%0A%0A%20%20%20%20%20%20%20%20%23%20The%20log-sum-exp%20constraint%0A%20%20%20%20%20%20%20%20M.constraint(xi.T%20%40%20p%20%3C%3D%201.0)%20%0A%20%20%20%20%20%20%20%20%23%20Stack%20allcones%20together%20-%20every%20row%20has%20the%20form%20(xi_j%2C%201%2C%20w_j-t)%0A%20%20%20%20%20%20%20%20%23%20The%20matrix%20notation%20means%20that%20every%20row%20belongs%20to%20the%20cone%0A%20%20%20%20%20%20%20%20M.constraint(Expr.hstack(xi%2C%20Expr.constTerm(m%2C%201.0)%2C%20W%20-%20Var.vrepeat(t%2C%20m))%2C%20Domain.inPExpCone())%0A%0A%20%20%20%20%20%20%20%20%23%20Continue%20with%20the%20linear%20constraints%0A%20%20%20%20%20%20%20%20M.constraint(W%20%2B%20r.T%20%40%20X%20%2B%20Var.vrepeat(eta%2C%20m)%20%3E%3D%200)%0A%20%20%20%20%20%20%20%20M.constraint(X.T%20%40%20(r%20%40%20p)%20%3E%3D%20rbar)%20%0A%20%20%20%20%20%20%20%20M.constraint(Expr.sum(X)%20%3C%3D%201.0)%0A%0A%20%20%20%20%20%20%20%20%23%20Set%20the%20objective%20%0A%20%20%20%20%20%20%20%20M.objective(ObjectiveSense.Minimize%2C%20eta%20%2B%20t%20%2F%20(1-alpha))%0A%0A%20%20%20%20%20%20%20%20return%20M%0A%20%20%20%20return%20(modelLogExpCR%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%20HMCR%0A%0A%20%20%20%20The%20model%20using%20%24f(x)%3D(%5Bx%5D%5E%2B)%5Eq%24%20is%20the%20same%20as%20LogExpCR%2C%20except%20that%20the%20last%20constraint%20becomes%0A%0A%20%20%20%20%24%24t%5Cgeq%5Cleft(%5Csum_j%20p_jw_j%5Eq%5Cright)%5E%7B1%2Fq%7D.%24%24%0A%0A%20%20%20%20This%20%24q%24-norm%20cone%20constraint%20is%20equivalent%20to%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Bl%7D%0A%20%20%20%20t%20%3D%201%5ET%5Cxi%2C%5C%5C%0A%20%20%20%20t%5E%7B1-1%2Fq%7D%5Cxi_j%5E%7B1%2Fq%7D%5Cgeq%20%7Cp_j%5E%7B1%2Fq%7Dw_j%7C%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20where%20the%20last%20row%20is%20precisely%20a%20conic%20constraint%20involving%20the%20%243%24-dimenional%20power%20cone%20with%20parameters%20%24(1-1%2Fq%2C1%2Fq)%24.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Domain%2C%20Expr%2C%20Model%2C%20ObjectiveSense%2C%20Var%2C%20np)%3A%0A%20%20%20%20def%20modelHMCR(alpha%2C%20rbar%2C%20p%2C%20r%2C%20m%2C%20n%2C%20q)%3A%20%20%20%0A%20%20%20%20%20%20%20%20M%20%3D%20Model(%22HMCR%22)%0A%0A%20%20%20%20%20%20%20%20%23%20Variables%0A%20%20%20%20%20%20%20%20X%20%20%20%3D%20M.variable('X'%2C%20n%2C%20Domain.greaterThan(0.0))%0A%20%20%20%20%20%20%20%20W%20%20%20%3D%20M.variable('W'%2C%20m%2C%20Domain.greaterThan(0.0))%0A%20%20%20%20%20%20%20%20eta%20%3D%20M.variable('eta')%0A%20%20%20%20%20%20%20%20xi%20%20%3D%20M.variable('xi'%2C%20m)%20%0A%20%20%20%20%20%20%20%20t%20%20%20%3D%20M.variable('t')%20%0A%0A%20%20%20%20%20%20%20%20%23%20The%20power%20cones%20representing%20the%20q-norm%20constraint%0A%20%20%20%20%20%20%20%20M.constraint(t%20%3D%3D%20Expr.sum(xi))%20%0A%20%20%20%20%20%20%20%20M.constraint(Expr.hstack(Var.vrepeat(t%2C%20m)%2C%20xi%2C%20Expr.mulElm(np.power(p%2C%201.0%2Fq)%2C%20W))%2C%20Domain.inPPowerCone(1.0-1.0%2Fq))%0A%0A%20%20%20%20%20%20%20%20%23%20Continue%20with%20the%20linear%20constraints%0A%20%20%20%20%20%20%20%20M.constraint(W%20%2B%20r.T%20%40%20X%20%2B%20Var.vrepeat(eta%2C%20m)%20%3E%3D%200)%0A%20%20%20%20%20%20%20%20M.constraint(X.T%20%40%20(r%20%40%20p)%20%3E%3D%20rbar)%20%0A%20%20%20%20%20%20%20%20M.constraint(Expr.sum(X)%20%3C%3D%201.0)%0A%0A%20%20%20%20%20%20%20%20%23%20Set%20the%20objective%20%0A%20%20%20%20%20%20%20%20M.objective(ObjectiveSense.Minimize%2C%20eta%20%2B%20t%20%2F%20(1-alpha))%0A%0A%20%20%20%20%20%20%20%20return%20M%0A%20%20%20%20return%20(modelHMCR%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%20Example%0A%0A%20%20%20%20We%20solve%20a%20few%20problems%20with%20%24n%3D100%24%20stocks%20and%20%24m%3D2000%24%20sample%20historical%20scenarios.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(modelCVaR%2C%20modelHMCR%2C%20modelLogExpCR%2C%20plt%2C%20r)%3A%0A%20%20%20%20def%20_()%3A%0A%20%20%20%20%20%20%20%20n%2C%20m%20%20%20%20%3D%20100%2C2000%0A%20%20%20%20%20%20%20%20alpha%20%20%20%3D%200.9%0A%20%20%20%20%20%20%20%20rbar%20%20%20%20%3D%200.005%0A%20%20%20%20%20%20%20%20p%20%20%20%20%20%20%20%3D%20%5B1.0%2Fm%5D*m%20%20%20%23%20Uniform%20probability%0A%0A%20%20%20%20%20%20%20%20MCVaR%20%20%20%20%20%3D%20modelCVaR(alpha%2C%20rbar%2C%20p%2C%20r%5B0%3An%2C0%3Am%5D%2C%20m%2C%20n)%0A%20%20%20%20%20%20%20%20MLogExpCR%20%3D%20modelLogExpCR(alpha%2C%20rbar%2C%20p%2C%20r%5B0%3An%2C0%3Am%5D%2C%20m%2C%20n)%0A%20%20%20%20%20%20%20%20MHMCR%20%20%20%20%20%3D%20modelHMCR(alpha%2C%20rbar%2C%20p%2C%20r%5B0%3An%2C0%3Am%5D%2C%20m%2C%20n%2C%20q%3D5.9)%0A%0A%20%20%20%20%20%20%20%20for%20M%20in%20%5BMCVaR%2C%20MLogExpCR%2C%20MHMCR%5D%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20M.setSolverParam(%22numThreads%22%2C%204)%0A%20%20%20%20%20%20%20%20%20%20%20%20M.solve()%0A%20%20%20%20%20%20%20%20%20%20%20%20print('%7B0%3A%20%3E8%7D%3A%20status%3D%7B1%7D%20time%3D%7B2%3A.2f%7Ds'.format(M.getName()%2C%20M.getProblemStatus()%2C%20M.getSolverDoubleInfo(%22optimizerTime%22)))%0A%20%20%20%20%20%20%20%20%20%20%20%20plt.plot(M.getVariable('X').level()%2C%20'o')%0A%20%20%20%20%20%20%20%20%20%20%20%20plt.show()%0A%0A%20%20%20%20_()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%3Ca%20rel%3D%22license%22%20href%3D%22http%3A%2F%2Fcreativecommons.org%2Flicenses%2Fby%2F4.0%2F%22%3E%3Cimg%20alt%3D%22Creative%20Commons%20License%22%20style%3D%22border-width%3A0%22%20src%3D%22https%3A%2F%2Fi.creativecommons.org%2Fl%2Fby%2F4.0%2F80x15.png%22%20%2F%3E%3C%2Fa%3E%3Cbr%20%2F%3EThis%20work%20is%20licensed%20under%20a%20%3Ca%20rel%3D%22license%22%20href%3D%22http%3A%2F%2Fcreativecommons.org%2Flicenses%2Fby%2F4.0%2F%22%3ECreative%20Commons%20Attribution%204.0%20International%20License%3C%2Fa%3E.%20The%20**MOSEK**%20logo%20and%20name%20are%20trademarks%20of%20%3Ca%20href%3D%22http%3A%2F%2Fmosek.com%22%3EMosek%20ApS%3C%2Fa%3E.%20The%20code%20is%20provided%20as-is.%20Compatibility%20with%20future%20release%20of%20**MOSEK**%20or%20the%20%60Fusion%20API%60%20are%20not%20guaranteed.%20For%20more%20information%20contact%20our%20%5Bsupport%5D(mailto%3Asupport%40mosek.com).%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20return%20(mo%2C)%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
fa6a9dfd89e902bc2326a221d0514f9567f361e953e3e3b12a7a312a1b268a0c