import%20marimo%0A%0A__generated_with%20%3D%20%220.13.15%22%0Aapp%20%3D%20marimo.App()%0A%0Awith%20app.setup%3A%0A%20%20%20%20import%20cvxpy%20as%20cvx%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20plotly.graph_objects%20as%20go%0A%20%20%20%20from%20plotly.subplots%20import%20make_subplots%0A%0A%0A%40app.cell%0Adef%20_()%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%20Regression%0A%20%20%20%20%23%23%23%20Thomas%20Schmelzer%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%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%20Linear%20Regression%0A%0A%20%20%20%20Let%20%24%5Cmathbf%7BA%7D%20%5Cin%20%5Cmathbb%7BR%7D%5E%7Bn%20%5Ctimes%20m%7D%24%20and%20%24%5Cmathbf%7Bb%7D%20%5Cin%20%5Cmathbb%7BR%7D%5En%24.%0A%20%20%20%20Solve%20the%20unconstrained%20least%20squares%20problem%3A%0A%0A%20%20%20%20%5Cbegin%7Balign%7D%0A%20%20%20%20%5Cmathbf%7Bx%7D%5E%7B*%7D%3D%5Carg%5Cmin_%7B%5Cmathbf%7Bx%7D%20%5Cin%20%5Cmathbb%7BR%7D%5Em%7D%26%20%5CrVert%7B%5Cmathbf%7BA%7D%5Cmathbf%7Bx%7D-%5Cmathbf%7Bb%7D%7D%5ClVert_2%0A%20%20%20%20%5Cend%7Balign%7D%0A%0A%20%20%20%20The%20%24i%24th%20column%20of%20%24%5Cmathbf%7BA%7D%24%20may%20represent%20the%20time%20series%20of%20returns%20for%20asset%20%24i%24.%0A%0A%20%20%20%20Portfolio%20Optimisation%20is%20about%20all%20about%20clever%20(linear)%20combinations%20of%20assets.%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%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%20Examples%3A%0A%20%20%20%20-%20Tracking%20an%20index%20(index%20in%20%24%5Cmathbf%7Bb%7D%24%2C%20assets%20in%20%24%5Cmathbf%7BA%7D%24)%0A%20%20%20%20-%20Constructing%20an%20indicator%2C%20factor%20analysis%2C%20...%0A%20%20%20%20-%20Approximation...%0A%20%20%20%20-%20...%0A%0A%20%20%20%20Regression%20is%20the%20**Swiss%20army%20knife**%20of%20professional%20quant%20finance.%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%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%20The%20normal%20equations%0A%0A%20%20%20%20As%20we%20(probably)%20all%20know%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cmathbf%7Bx%7D%5E%7B*%7D%3D%5Cleft(%5Cmathbf%7BA%7D%5ET%20%5Cmathbf%7BA%7D%5Cright)%5E%7B-1%7D%5Cmathbf%7BA%7D%5E%7BT%7D%5Cmathbf%7Bx%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20solves%0A%0A%20%20%20%20%5Cbegin%7Balign%7D%5Cmathbf%7Bx%7D%5E%7B*%7D%3D%5Carg%5Cmin_%7B%5Cmathbf%7Bx%7D%20%5Cin%20%5Cmathbb%7BR%7D%5Em%7D%26%20%5CrVert%7B%5Cmathbf%7BA%7D%5Cmathbf%7Bx%7D-%5Cmathbf%7Bb%7D%7D%5ClVert_2%0A%20%20%20%20%5Cend%7Balign%7D%0A%0A%20%20%20%20You%20may%20see%20here%20already%0A%0A%20%20%20%20%20%2B%20The%20matrix%20%24%5Cmathbf%7BA%7D%5ET%20%5Cmathbf%7BA%7D%24%20is%20a%20scaled%20covariance%20matrix%20(if%20the%20columns%20of%20%24%5Cmathbf%7BA%7D%24%20are%20centered).%0A%20%20%20%20%20%20%20Run%20into%20problems%20with%20small%20eigenvalues%20here...%0A%0A%20%20%20%20**Nerd%20alarm**%3A%20Being%20a%20numerical%20analyst%20I%20recommend%20to%20use%20the%20SVD%20or%20QR-decomposition%0A%20%20%20%20to%20solve%20the%20unconstrained%20least%20squares%20problem.%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%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%20Constrained%20regression%0A%0A%20%20%20%20Let%20%24%5Cmathbf%7BA%7D%20%5Cin%20%5Cmathbb%7BR%7D%5E%7Bn%20%5Ctimes%20m%7D%24%20and%20%24%5Cmathbf%7Bb%7D%20%5Cin%20%5Cmathbb%7BR%7D%5En%24.%0A%20%20%20%20We%20solve%20the%20constrained%20least%20squares%20problem%3A%0A%0A%20%20%20%20%5Cbegin%7Balign%7D%5Cmathbf%7Bx%7D%5E%7B*%7D%3D%5Carg%5Cmin_%7B%5Cmathbf%7Bx%7D%20%5Cin%20%5Cmathbb%7BR%7D%5Em%7D%26%20%5CrVert%7B%5Cmathbf%7BA%7D%5Cmathbf%7Bx%7D-%5Cmathbf%7Bb%7D%7D%5ClVert_2%0A%20%20%20%20%5C%5C%0A%20%20%20%20%5Ctext%7Bs.t.%20%7D%20%26%5CSigma%5C%2Cx_i%3D1%5C%5C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%26%5Cmathbf%7Bx%7D%5Cgeq%200%0A%20%20%20%20%5Cend%7Balign%7D%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%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%20The%20Sculptor%20method%0A%20%20%20%20%3Cdiv%3E%0A%20%20%20%20%3Cimg%20src%3D%22talk%2Fthales.jpg%22%20style%3D%22margin-left%3Aauto%3B%20margin-right%3Aauto%3B%20display%3Ablock%22%3E%0A%20%20%20%20Thales%20of%20Miletus%20(c.%20624%20BC%20-%20%20c.%20546%20BC)%0A%20%20%20%20%3C%2Fdiv%3E%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%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20Shall%20we%20apply%20the%20sculptor%20method%3F%0A%0A%20%20%20%20-%20We%20could%20delete%20the%20negative%20entries%20(really%20bad%20if%20they%20are%20all%20negative)%0A%20%20%20%20-%20We%20could%20scale%20the%20surviving%20entries%20to%20enforce%20the%20%24%5CSigma%5C%2Cx_i%3D1%24.%0A%0A%20%20%20%20Done%3F%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%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%3Cdiv%3E%0A%20%20%20%20%3Cimg%20src%3D%22talk%2Fcone.png%22%20style%3D%22margin-left%3Aauto%3B%20margin-right%3Aauto%3B%20display%3Ablock%22%3E%0A%20%20%20%20%24%24y%20%5Cgeq%20%5Csqrt%7Bx_1%5E2%20%2B%20x_2%5E2%7D%3D%5CrVert%7B%5Cmathbf%7Bx%7D%7D%5ClVert_2%24%24%0A%20%20%20%20%3C%2Fdiv%3E%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%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%20Conic%20Programming%0A%0A%20%20%20%20We%20introduce%20an%20auxiliary%20scalar%20%24z%24%3A%0A%0A%20%20%20%20%5Cbegin%7Balign%7D%5Cmin_%7Bz%20%5Cin%20%5Cmathbb%7BR%7D%2C%20%5Cmathbf%7Bx%7D%20%5Cin%20%5Cmathbb%7BR%7D%5Em%7D%20%26%20z%5C%5C%0A%20%20%20%20%5Ctext%7Bs.t.%20%7D%26z%20%5Cgeq%20%5CrVert%7B%5Cmathbf%7BA%7D%5Cmathbf%7Bx%7D-%5Cmathbf%7Bb%7D%7D%5ClVert_2%5C%5C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%26%5CSigma%5C%2Cx_i%3D1%5C%5C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%26%5Cmathbf%7Bx%7D%5Cgeq%200%0A%20%20%20%20%5Cend%7Balign%7D%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%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20We%20introduce%20an%20auxiliary%20vector%20%24%5Cmathbf%7By%7D%20%5Cin%20%5Cmathbb%7BR%7D%5En%24%3A%0A%0A%20%20%20%20%5Cbegin%7Balign%7D%5Cmin_%7Bz%20%5Cin%20%5Cmathbb%7BR%7D%2C%20%5Cmathbf%7Bx%7D%20%5Cin%20%5Cmathbb%7BR%7D%5Em%2C%20%5Cmathbf%7By%7D%20%5Cin%20%5Cmathbb%7BR%7D%5En%7D%20%26%20z%5C%5C%0A%20%20%20%20%5Ctext%7Bs.t.%20%7D%26z%20%5Cgeq%20%5CrVert%7By%7D%5ClVert_2%5C%5C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%26%5Cmathbf%7By%7D%20%3D%20%5Cmathbf%7BA%7D%5Cmathbf%7Bx%7D-%5Cmathbf%7Bb%7D%5C%5C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%26%5CSigma%5C%2Cx_i%3D1%5C%5C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%26%5Cmathbf%7Bx%7D%5Cgeq%200%0A%20%20%20%20%5Cend%7Balign%7D%0A%0A%20%20%20%20We%20**lifted**%20the%20problem%20from%20a%20%24m%24%20dimensional%20space%20into%20a%20%24m%20%2B%20n%20%2B%201%24%20dimensional%20space.%0A%0A%20%20%20%20**Nerd%20alarm**%3A%20%24%24z%20%5Cgeq%20%5CrVert%7By%7D%5ClVert_2%20%5C%2C%5CLeftrightarrow%5C%2C%20%5Bz%2Cy%5D%20%5Cin%20%5Cmathcal%7BQ%7D_%7Bn%2B1%7D%24%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_()%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%20Application%3A%20Implementing%20a%20minimum%20variance%20portfolio%0A%20%20%20%20The%20%24i%24th%20column%20of%20%24%5Cmathbf%7BA%7D%24%20is%20the%20time%20series%20of%20returns%20for%20the%20%24i%24th%20asset.%0A%20%20%20%20Hence%20to%20minimize%20the%20variance%20of%20a%20portfolio%20(a%20linear%20combination%20of%20assets)%20we%20solve%3A%0A%0A%20%20%20%20%5Cbegin%7Balign%7D%5Cmathbf%7Bw%7D%5E%7B*%7D%3D%5Carg%5Cmin_%7B%5Cmathbf%7Bw%7D%20%5Cin%20%5Cmathbb%7BR%7D%5Em%7D%26%20%5CrVert%7B%5Cmathbf%7BA%7D%5Cmathbf%7Bw%7D-%5Cmathbf%7B0%7D%7D%5ClVert_2%0A%20%20%20%20%5C%5C%0A%20%20%20%20%5Ctext%7Bs.t.%20%7D%20%26%5CSigma%5C%2Cw_i%3D1%5C%5C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%26%5Cmathbf%7Bw%7D%5Cgeq%200%0A%20%20%20%20%5Cend%7Balign%7D%0A%0A%20%20%20%20**Nerd%20alarm**%3A%20This%20is%20strictly%20speaking%20not%20a%20Minimum%20Variance%20portfolio%20as%20we%20use%20squared%20deviations%0A%20%20%20%20from%20%240%24%20rather%20than%20from%20the%20mean.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.function%0Adef%20minimize(objective%2C%20constraints%3DNone)%3A%0A%20%20%20%20%22%22%22Minimizes%20a%20given%20objective%20function%20subject%20to%20optional%20constraints.%0A%0A%20%20%20%20This%20function%20creates%20and%20solves%20a%20convex%20optimization%20problem%20to%20find%20the%0A%20%20%20%20minimum%20value%20of%20the%20provided%20objective%20function%2C%20subject%20to%20any%20specified%0A%20%20%20%20constraints.%0A%0A%20%20%20%20Args%3A%0A%20%20%20%20%20%20%20%20objective%3A%20The%20objective%20function%20to%20minimize.%0A%20%20%20%20%20%20%20%20constraints%3A%20Optional%20list%20of%20constraints%20for%20the%20optimization%20problem.%0A%0A%20%20%20%20Returns%3A%0A%20%20%20%20%20%20%20%20The%20optimal%20value%20of%20the%20objective%20function.%0A%20%20%20%20%22%22%22%0A%20%20%20%20return%20cvx.Problem(cvx.Minimize(objective)%2C%20constraints).solve()%0A%0A%0A%40app.function%0Adef%20min_var(matrix%2C%20lamb%3D0.0)%3A%0A%20%20%20%20%22%22%22Min%202-norm%20(matrix*w)%20%2B%20lamb*2-norm(w)%20subject%20to%20constraints.%0A%0A%20%20%20%20s.t.%20e'w%20%3D%201%2C%20w%20%3E%3D%200.%0A%0A%20%20%20%20Args%3A%0A%20%20%20%20%20%20%20%20matrix%3A%20Matrix%20of%20asset%20returns.%0A%20%20%20%20%20%20%20%20lamb%3A%20Regularization%20parameter.%20Defaults%20to%200.0.%0A%0A%20%20%20%20Returns%3A%0A%20%20%20%20%20%20%20%20Optimal%20portfolio%20weights.%0A%20%20%20%20%22%22%22%0A%20%20%20%20w%20%3D%20cvx.Variable(matrix.shape%5B1%5D)%0A%20%20%20%20minimize(%0A%20%20%20%20%20%20%20%20objective%3Dcvx.norm(matrix%20%40%20w%2C%202)%20%2B%20lamb%20*%20cvx.norm(w%2C%202)%2C%0A%20%20%20%20%20%20%20%20constraints%3D%5Bw%20%3E%3D%200%2C%20cvx.sum(w)%20%3D%3D%201%5D%2C%0A%20%20%20%20)%0A%20%20%20%20return%20w.value%0A%0A%0A%40app.function%0Adef%20plot_bar(data%2C%20width%3D0.35%2C%20title%3D%22%22)%3A%0A%20%20%20%20%22%22%22Create%20a%20bar%20chart%20visualization%20of%20portfolio%20weights.%0A%0A%20%20%20%20This%20function%20creates%20a%20plotly%20bar%20chart%20to%20visualize%20portfolio%20weights%0A%20%20%20%20or%20similar%20data.%0A%0A%20%20%20%20Args%3A%0A%20%20%20%20%20%20%20%20data%3A%20The%20data%20to%20plot%20(typically%20portfolio%20weights).%0A%20%20%20%20%20%20%20%20width%3A%20Width%20of%20the%20bars.%20Defaults%20to%200.35.%0A%20%20%20%20%20%20%20%20title%3A%20Title%20for%20the%20plot.%20Defaults%20to%20empty%20string.%0A%0A%20%20%20%20Returns%3A%0A%20%20%20%20%20%20%20%20A%20plotly%20Figure%20object%20containing%20the%20bar%20chart.%0A%20%20%20%20%22%22%22%0A%20%20%20%20_fig%20%3D%20go.Figure()%0A%20%20%20%20_fig.add_trace(go.Bar(x%3Dnp.arange(5)%20%2B%201%2C%20y%3Ddata%2C%20width%3D2%20*%20width))%0A%20%20%20%20_fig.update_layout(title%3Dtitle%2C%20xaxis_title%3D%22index%22%2C%20yaxis_title%3D%22Weight%22%2C%20yaxis_range%3D%5B0%2C%201%5D)%0A%20%20%20%20return%20_fig%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20random_data%20%3D%20np.dot(np.random.randn(250%2C%205)%2C%20np.diag(%5B1%2C%202%2C%203%2C%204%2C%205%5D))%0A%20%20%20%20_data%20%3D%20min_var(random_data)%0A%0A%20%20%20%20_fig%20%3D%20plot_bar(_data)%0A%20%20%20%20_fig%0A%20%20%20%20return%20(random_data%2C)%0A%0A%0A%40app.cell%0Adef%20_()%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%20Balance%3F%0A%0A%20%20%20%20-%20Bounds%0A%20%20%20%20-%20**Tikhonov%20regularization**%20(penalty%20by%20the%20%242%24-norm%20of%20the%20weights%20in%20the%20objective)%2C%0A%20%20%20%20%20%20also%20known%20as%20**Ridge%20Regression**%20or%20**Shrinkage%20to%20the%20mean**%0A%0A%0A%20%20%20%20%5Cbegin%7Balign%7D%5Cmathbf%7Bw%7D%5E%7B*%7D%3D%5Carg%5Cmin_%7B%5Cmathbf%7Bw%7D%20%5Cin%20%5Cmathbb%7BR%7D%5Em%7D%26%20%5CrVert%7B%5Cmathbf%7BA%7D%5Cmathbf%7Bw%7D%7D%5ClVert_2%20%2B%0A%20%20%20%20%5Clambda%20%5CrVert%7B%5Cmathbf%7Bw%7D%7D%5ClVert_2%5C%5C%0A%20%20%20%20%5Ctext%7Bs.t.%20%7D%20%26%5CSigma%5C%2Cw_i%3D1%5C%5C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%26%5Cmathbf%7Bw%7D%5Cgeq%200%0A%20%20%20%20%5Cend%7Balign%7D%0A%0A%20%20%20%20-%20The%20%241%2FN%24%20portfolio%20is%20the%20limit%20for%20%24%5Clambda%20%5Cto%20%5Cinfty%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_(random_data)%3A%0A%20%20%20%20%23%20Create%20subplot%20layout%20with%20specified%20width%2Fheight%20via%20%60update_layout%60%20later%0A%20%20%20%20_fig%20%3D%20make_subplots(rows%3D1%2C%20cols%3D2%2C%20subplot_titles%3D%5B%220%22%2C%20%2210%22%5D%2C%20horizontal_spacing%3D0.05)%0A%0A%20%20%20%20%23%20Add%20first%20subplot%0A%20%20%20%20_fig1%20%3D%20plot_bar(min_var(random_data%2C%20lamb%3D0))%0A%20%20%20%20_fig.add_trace(_fig1.data%5B0%5D%2C%20row%3D1%2C%20col%3D1)%0A%0A%20%20%20%20%23%20Add%20second%20subplot%0A%20%20%20%20_fig2%20%3D%20plot_bar(min_var(random_data%2C%20lamb%3D10))%0A%20%20%20%20_fig.add_trace(_fig2.data%5B0%5D%2C%20row%3D1%2C%20col%3D2)%0A%0A%20%20%20%20%23%20Update%20layout%20(width%2Fheight%20here)%0A%20%20%20%20_fig.update_layout(%0A%20%20%20%20%20%20%20%20width%3D1000%2C%0A%20%20%20%20%20%20%20%20height%3D400%2C%0A%20%20%20%20%20%20%20%20showlegend%3DFalse%2C%0A%20%20%20%20%20%20%20%20yaxis_range%3D%5B0%2C%201%5D%2C%0A%20%20%20%20%20%20%20%20yaxis2_range%3D%5B0%2C%201%5D%2C%0A%20%20%20%20)%0A%0A%20%20%20%20_fig%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(random_data)%3A%0A%20%20%20%20_fig%20%3D%20make_subplots(rows%3D1%2C%20cols%3D2%2C%20subplot_titles%3D%5B%2220%22%2C%20%2250%22%5D%2C%20horizontal_spacing%3D0.05)%0A%0A%20%20%20%20%23%20Add%20the%20first%20subplot%0A%20%20%20%20_fig1%20%3D%20plot_bar(min_var(random_data%2C%20lamb%3D20))%0A%20%20%20%20_fig.add_trace(_fig1.data%5B0%5D%2C%20row%3D1%2C%20col%3D1)%0A%0A%20%20%20%20%23%20Add%20the%20second%20subplot%0A%20%20%20%20_fig2%20%3D%20plot_bar(min_var(random_data%2C%20lamb%3D50))%0A%20%20%20%20_fig.add_trace(_fig2.data%5B0%5D%2C%20row%3D1%2C%20col%3D2)%0A%0A%20%20%20%20%23%20Update%20layout%0A%20%20%20%20_fig.update_layout(showlegend%3DFalse%2C%20yaxis_range%3D%5B0%2C%201%5D%2C%20yaxis2_range%3D%5B0%2C%201%5D)%0A%0A%20%20%20%20_fig%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(random_data)%3A%0A%20%20%20%20fig%20%3D%20make_subplots(rows%3D1%2C%20cols%3D2%2C%20subplot_titles%3D%5B%22100%22%2C%20%22200%22%5D%2C%20horizontal_spacing%3D0.05)%0A%0A%20%20%20%20%23%20Add%20the%20first%20subplot%0A%20%20%20%20fig1%20%3D%20plot_bar(min_var(random_data%2C%20lamb%3D100))%0A%20%20%20%20fig.add_trace(fig1.data%5B0%5D%2C%20row%3D1%2C%20col%3D1)%0A%0A%20%20%20%20%23%20Add%20the%20second%20subplot%0A%20%20%20%20fig2%20%3D%20plot_bar(min_var(random_data%2C%20lamb%3D200))%0A%20%20%20%20fig.add_trace(fig2.data%5B0%5D%2C%20row%3D1%2C%20col%3D2)%0A%0A%20%20%20%20%23%20Update%20layout%0A%20%20%20%20fig.update_layout(showlegend%3DFalse%2C%20yaxis_range%3D%5B0%2C%201%5D%2C%20yaxis2_range%3D%5B0%2C%201%5D)%0A%0A%20%20%20%20fig.show()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%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%20Summary%0A%0A%20%20%20%20-%20Although%20the%20Sculptor%20method%20(or%20variants%20thereof)%20are%20heavily%20used%20in%20practice%20such%20approaches%20are%20usually%0A%20%20%20%20%20%20inefficient%20ways%20to%20construct%20feasible%20but%20not%20optimal%20solutions.%0A%0A%20%20%20%20-%20It's%20usually%20more%20effective%20to%20combine%20all%20constraints%20into%20one%20(conic)%20program.%0A%0A%20%20%20%20-%20Modern%20regularization%20techniques%20offer%20extreme%20flexibility%20(linear%20constraints%20on%20weights%2C%0A%20%20%20%20%20%20level%20of%20trading%20activity%2C%20bounds%20on%20leverage%2C%20trading%20costs%2C%20...)%0A%0A%20%20%20%20-%20Example%20given%3A%20Using%20Tikhonov%20regularization%20we%20can%20interpolate%20between%20the%20Minimum%20Variance%20portfolio%0A%20%20%20%20%20%20and%20the%20%241%2FN%24%20portfolio.%0A%0A%20%20%20%20**Recommended%20read**%3A%20Regression%20techniques%20for%20Portfolio%20Optimisation%20using%20MOSEK%2C%20Schmelzer%20et%20al.%2C%20see%20https%3A%2F%2Farxiv.org%2Fabs%2F1310.3397%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
f72c5c535446adb6519ceaf24d3428b9d6c6de942926d9420ce0d39c04dbb50c