import%20marimo%0A%0A__generated_with%20%3D%20%220.14.13%22%0Aapp%20%3D%20marimo.App()%0A%0Awith%20app.setup%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20numpy%20as%20np%0A%0A%20%20%20%20from%20cvxcla%20import%20CLA%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%20Critical%20Line%20Algorithm%0A%20%20%20%20We%20compute%20an%20efficient%20frontier%20using%20the%20critical%20line%20algorithm%20(cla).%0A%20%20%20%20The%20method%20was%20introduced%20by%20Harry%20M%20Markowitz%20in%201956.%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%20slider%20%3D%20mo.ui.slider(4%2C%20100%2C%20step%3D1%2C%20value%3D10%2C%20label%3D%22Size%20of%20the%20problem%22)%0A%20%20%20%20%23%20display%20the%20slider%0A%20%20%20%20slider%0A%20%20%20%20return%20(slider%2C)%0A%0A%0A%40app.function(hide_code%3DTrue)%0Adef%20cla(n)%3A%0A%20%20%20%20%22%22%22Compute%20using%20the%20Critical%20Line%20Algorithm%20(CLA)%20an%20efficient%20frontier.%0A%0A%20%20%20%20Args%3A%0A%20%20%20%20%20%20%20%20n%20(int)%3A%20The%20dimension%20size%20of%20the%20mean%20vector%2C%20lower%20and%20upper%20bounds%0A%20%20%20%20%20%20%20%20%20%20%20%20arrays%2C%20and%20covariance%20matrix%20used%20in%20the%20computation.%0A%0A%20%20%20%20Returns%3A%0A%20%20%20%20%20%20%20%20numpy.ndarray%3A%20The%20efficient%20frontier%20generated%20by%20the%20CLA%20based%20on%20the%0A%20%20%20%20%20%20%20%20%20%20%20%20provided%20parameters.%0A%20%20%20%20%22%22%22%0A%20%20%20%20mean%20%3D%20np.random.randn(n)%0A%20%20%20%20lower_bounds%20%3D%20np.zeros(n)%0A%20%20%20%20upper_bounds%20%3D%20np.ones(n)%0A%0A%20%20%20%20factor%20%3D%20np.random.randn(n%2C%20n)%0A%20%20%20%20covariance%20%3D%20factor%20%40%20factor.T%0A%0A%20%20%20%20f1%20%3D%20CLA(%0A%20%20%20%20%20%20%20%20mean%3Dmean%2C%0A%20%20%20%20%20%20%20%20covariance%3Dcovariance%2C%0A%20%20%20%20%20%20%20%20lower_bounds%3Dlower_bounds%2C%0A%20%20%20%20%20%20%20%20upper_bounds%3Dupper_bounds%2C%0A%20%20%20%20%20%20%20%20a%3Dnp.ones((1%2C%20len(mean)))%2C%0A%20%20%20%20%20%20%20%20b%3Dnp.ones(1)%2C%0A%20%20%20%20).frontier%0A%20%20%20%20return%20f1%0A%0A%0A%40app.cell%0Adef%20_(slider)%3A%0A%20%20%20%20frontier%20%3D%20cla(slider.value)%0A%20%20%20%20frontier.interpolate(2).plot(volatility%3DTrue%2C%20markers%3DTrue)%0A%20%20%20%20frontier.plot()%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
072cca9f3dc823c136b710bdc9cf83ee45582c007f5686a4d388863e286f0eff