import%20marimo%0A%0A__generated_with%20%3D%20%220.14.17%22%0Aapp%20%3D%20marimo.App()%0A%0Awith%20app.setup%3A%0A%20%20%20%20from%20pathlib%20import%20Path%0A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20pandas%20as%20pd%0A%20%20%20%20import%20plotly.io%20as%20pio%0A%20%20%20%20import%20polars%20as%20pl%0A%0A%20%20%20%20pd.options.plotting.backend%20%3D%20%22plotly%22%0A%0A%20%20%20%20%23%20Ensure%20Plotly%20works%20with%20Marimo%0A%20%20%20%20pio.renderers.default%20%3D%20%22plotly_mimetype%22%0A%0A%20%20%20%20path%20%3D%20Path(__file__).parent%20%2F%20%22public%22%20%2F%20%22prices.csv%22%0A%0A%20%20%20%20%23%20from%20cvxsimulator.builder%20import%20polars2pandas%0A%20%20%20%20date_col%20%3D%20%22date%22%0A%20%20%20%20dframe%20%3D%20pl.read_csv(str(path)%2C%20try_parse_dates%3DTrue)%0A%0A%20%20%20%20dframe%20%3D%20dframe.with_columns(pl.col(date_col).cast(pl.Datetime(%22ns%22)))%0A%20%20%20%20dframe%20%3D%20dframe.with_columns(%5Bpl.col(col).cast(pl.Float64)%20for%20col%20in%20dframe.columns%20if%20col%20!%3D%20date_col%5D)%0A%20%20%20%20prices%20%3D%20dframe.to_pandas().set_index(date_col)%0A%0A%20%20%20%20prices.loc%5B%222022-01-03%22%2C%20%22B%22%5D%20%3D%20np.nan%0A%20%20%20%20prices.loc%5B%222022-01-04%22%2C%20%22B%22%5D%20%3D%20np.nan%0A%0A%20%20%20%20from%20cvxsimulator%20import%20Builder%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%22%22%22Display%20the%20title%20of%20the%20notebook.%0A%0A%20%20%20%20Parameters%0A%20%20%20%20----------%0A%20%20%20%20mo%20%3A%20marimo.Module%0A%20%20%20%20%20%20%20%20The%20marimo%20module%20object%0A%0A%20%20%20%20%22%22%22%0A%20%20%20%20mo.md(r%22%22%22%23%20One%20asset%20fading%20out%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%20Iterate%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%22%22%22Build%20a%20portfolio%20with%20equal%20weights%20that%20adapts%20to%20an%20asset%20fading%20out.%0A%0A%20%20%20%20This%20cell%3A%0A%20%20%20%201.%20Creates%20a%20Builder%20instance%20with%20the%20modified%20price%20data%0A%20%20%20%202.%20Iterates%20through%20time%2C%20setting%20equal%20weights%20for%20all%20available%20assets%0A%20%20%20%20%20%20%20at%20each%20time%20step%20(automatically%20adapting%20when%20asset%20B%20fades%20out)%0A%20%20%20%203.%20Builds%20and%20returns%20the%20final%20portfolio%0A%0A%20%20%20%20Returns%3A%0A%20%20%20%20-------%0A%20%20%20%20tuple%0A%20%20%20%20%20%20%20%20A%20tuple%20containing%20the%20built%20portfolio%0A%0A%20%20%20%20%22%22%22%0A%20%20%20%20_builder%20%3D%20Builder(prices%3Dprices%2C%20initial_aum%3D2000)%0A%0A%20%20%20%20for%20_t%2C%20_state%20in%20_builder%3A%0A%20%20%20%20%20%20%20%20_builder.weights%20%3D%20np.ones(len(_state.assets))%20%2F%20len(_state.assets)%0A%20%20%20%20%20%20%20%20_builder.aum%20%3D%20_state.aum%0A%0A%20%20%20%20portfolio%20%3D%20_builder.build()%0A%20%20%20%20return%20(portfolio%2C)%0A%0A%0A%40app.cell%0Adef%20_(portfolio)%3A%0A%20%20%20%20%22%22%22Display%20the%20prices%20DataFrame%20from%20the%20portfolio.%0A%0A%20%20%20%20This%20cell%20shows%20the%20price%20data%20in%20the%20portfolio%2C%20including%20the%0A%20%20%20%20missing%20values%20for%20asset%20B%20after%20it%20fades%20out.%0A%0A%20%20%20%20Parameters%0A%20%20%20%20----------%0A%20%20%20%20portfolio%20%3A%20Portfolio%0A%20%20%20%20%20%20%20%20The%20portfolio%20object%20built%20by%20the%20previous%20cell%0A%0A%20%20%20%20%22%22%22%0A%20%20%20%20print(portfolio.prices)%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
3d70af28bb06783feaf28156f2d28cccbf78dc3ca68bdba3914939f9c7a2ccf4