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(r%22%22%22%23%20Utility%20based%20option%20pricing%20with%20transaction%20costs%20and%20diversification%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(r%22%22%22In%20this%20notebook%2C%20we%20present%20the%20%3Ci%3EFusion%3C%2Fi%3E%20implementation%20of%20the%20utility%20based%20option%20pricing%20model%2C%20presented%20by%20%5BAndersen%20et.%20al.%20(1999)%5D(https%3A%2F%2Fwww.sciencedirect.com%2Fscience%2Farticle%2Fpii%2FS0168927498001044).%20The%20purpose%20of%20the%20model%20is%20to%20estimate%20the%20reservation%20purchase%20price%20of%20a%20European%20call%20option%2C%20written%20on%20a%20risky%20security%20when%20there%20is%20proportional%20transaction%20costs%20in%20the%20market.%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(r%22%22%22%23%23%20The%20Model%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%20Consider%20an%20economy%20evolving%20over%20T%20periods%2C%20%24%7B0%2Ct_1%2Ct_2%2Ct_3%2C...%2Ct_T%20%3D%20%5Coverline%7BT%7D%7D%24%20where%20%24%5Coverline%7BT%7D%24%20is%20the%20time%20horizon%20in%20years.%20We%20consider%20that%20the%20investor%20has%20one%20risk-free%20security%2C%20such%20as%20a%20bond%2C%20that%20pays%20at%20a%20constant%20interest%20rate%20of%20%24r%5Cgeq%200%24%2C%20and%20%24m%24%20risky%20securities%20with%20price%20processes%20denoted%20by%20%24(S_1%2CS_2%2C...%2CS_m)%24.%20The%20price%20of%20the%20risky%20securities%20evolves%20in%20an%20event%20tree%20such%20that%3A%20%0A%0A%20%20%20%20%24%24(S_%7B1%2Cn%7D%2CS_%7B2%2Cn%7D%2C..%2CS_%7Bm%2Cn%7D)%20%3D%20%5Cbegin%7Bcases%7D%0A%20%20%20%20(a_1%20S_%7B1%2Cn-1%7D%2C%20a_2%20S_%7B2%2Cn-1%7D%2C..%2Ca_m%20S_%7Bm%2Cn-1%7D)%2C%20%5C%2C%5C%2C%20%5Ctext%7Bwith%20probability%20%7D%20q_1%2C%20%5C%5C%0A%20%20%20%20(b_1%20S_%7B1%2Cn-1%7D%2C%20b_2%20S_%7B2%2Cn-1%7D%2C..%2Cb_m%20S_%7Bm%2Cn-1%7D)%2C%20%5C%2C%5C%2C%20%5Ctext%7Bwith%20probability%20%7D%20q_2%2C%20%5C%5C%0A%20%20%20%20(c_1%20S_%7B1%2Cn-1%7D%2C%20c_2%20S_%7B2%2Cn-1%7D%2C..%2Cc_m%20S_%7Bm%2Cn-1%7D)%2C%20%5C%2C%5C%2C%20%5Ctext%7Bwith%20probability%20%7D%20q_3%20%3D%20(1-q_1-q_2)%0A%20%20%20%20%5Cend%7Bcases%7D%0A%20%20%20%20%24%24%0A%0A%0A%20%20%20%20where%20the%20three%20possibilities%20lead%20to%20an%20event%20tree%20of%20splitting%20index%203%20(In%20the%20fusion%20model%20presented%20below%2C%20we%20have%20considered%20a%20general%20case%20where%20one%20can%20have%20a%20different%20splitting%20index).%20The%20event%20tree%20for%20two%20risky%20securities%20can%20be%20visualized%20as%20shown%20in%20the%20figure%20below.%0A%20%20%20%20%22%22%22%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(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20Let%2C%20%24%5Cmathbf%7B%5Calpha_%7Bn%7D%7D%20%3D%20(%5Calpha_1%2C%5Calpha_2%2C...%2C%5Calpha_m)%24%20denote%20the%20number%20of%20units%20of%20the%20risky%20security%20held%20by%20the%20investor%20at%20time%20%24t_n%24%2C%20and%20%24%5Cbeta_n%24%20denote%20the%20dollar%20amount%20held%20by%20the%20investor%20in%20bonds%20at%20the%20same%20time.%20Then%2C%20the%20%3Ci%3E'budget%20constraint'%3C%2Fi%3E%20on%20the%20bonds%20an%20investor%20can%20buy%20in%20the%20next%20period%20is%20given%20by%3A%0A%0A%0A%20%20%20%20%24%24%5Cbeta_n(I_n)%20%5Cleq%20(1%2Br)%5Cbeta_%7Bn-1%7D(I_n)%20%2B%20%5Csum_%7Bi%3D1%7D%5E%7Bm%7D%20S_%7Bi%2Cn%7D(I_n)%5B%5Calpha_%7Bi%2Cn-1%7D(I_n)%20-%20%5Calpha_%7Bi%2Cn%7D(I_n)%20-%20%5Ctheta_i%20%7C%5Calpha_%7Bi%2Cn-1%7D(I_n)%20-%20%5Calpha_%7Bi%2Cn%7D(I_n)%7C%5D%24%24%0A%0A%0A%20%20%20%20where%20%24%5Ctheta_i%24%20is%20the%20transaction%20cost%20for%20trading%20of%20risky%20security%20%24i%24%20and%20%24I_n%24%20denotes%20the%20path%20being%20considered%20(in%20other%20words%2C%20the%20sequence%20of%20events%20in%20the%20event%20tree).%20The%20total%20number%20of%20paths%20possible%20for%20a%20tree%20of%20splitting%20index%20%24s%24%2C%20over%20%24n%24%20time%20periods%20is%20%24s%5En%24.%20Initially%2C%20if%20we%20consider%20that%20the%20wealth%20of%20the%20investor%20is%20%24W_0%24%2C%20then%20of%20course%20the%20first%20budget%20constraint%20becomes%3A%0A%0A%20%20%20%20%24%24%5Cbeta_0%20%5Cleq%20W_0%20-%20%5Csum_%7Bi%3D1%7D%5E%7Bm%7D%20S_%7Bi%2C0%7D%5B%5Calpha_%7Bi%2C0%7D%20%2B%20%7C%5Calpha_%7Bi%2C0%7D%7C%5D%24%24%0A%0A%0A%20%20%20%20Additionally%2C%20in%20the%20final%20period%20the%20investor%20will%20sell%20all%20of%20the%20risky%20securities%2C%20thus%20ending%20up%20with%20a%20wealth%20%24W_T(I_T)%24%20for%20path%20%24I_T%24%2C%20such%20that%3A%0A%0A%20%20%20%20%24%24W_T(I_T)%20%5Cleq%20(1%2Br)%5Cbeta_%7BT-1%7D(I_T)%20%2B%20%5Csum_%7Bi%3D1%7D%5E%7Bm%7D%20S_%7Bi%2CT%7D(I_T)%5B%5Calpha_%7Bi%2CT-1%7D(I_T)%20-%20%5Ctheta_i%20%7C%5Calpha_%7Bi%2CT-1%7D(I_T)%7C%5D%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(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%201.)%20Portfolio%20choice%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%20The%20goal%20of%20the%20investor%20is%20to%20choose%20a%20portfolio%20strategy%20(i.e.%20the%20sequence%20%7B%24%7B%5Cmathbf%7B%5Calpha_n(I_n)%7D%2C%5Cbeta_n(I_n)%7D%24%7D)%20that%20maximizes%20the%20expected%20utility.%20The%20expected%20utility%20is%20given%20by%3A%0A%0A%20%20%20%20%24%24E%5BU(W_T)%5D%20%3D%20%5Csum_%7BI_%7BT%7D%5Cin%20F_T%7D%20q_1%5E%7BA(I_T)%7Dq_2%5E%7BB(I_T)%7D(1-q_1-q_2)%5E%7BT-A(I_T)-B(I_T)%7DU(W_T(I_T))%24%24%0A%0A%0A%20%20%20%20Note%20that%20the%20summation%20is%20over%20all%20the%20possible%20paths%20for%20a%20tree%20of%20a%20given%20split%20index%20and%20T%20time-periods%20(the%20set%20denoted%20by%20%24F_T%24).%20%24A(I_T)%24%20and%20%24B(I_T)%24%20denote%20the%20number%20of%20times%20the%20first%20and%20second%20possibilities%20are%20considered%20in%20every%20path%2C%20respectively.%20Following%20the%20equations%20presented%20above%2C%20the%20complete%20optimization%20problem%20can%20be%20written%20as%3A%0A%0A%0A%20%20%20%20%24%24U%5E*(W_0)%20%3D%20%5Ctext%7Bmaximize%7D_%7B(%7B%5Cmathbf%7B%5Calpha%7D_n(I_n)%2C%5Cbeta_n(I_n))%7D_%7BI_n%5Cin%20F_T%2C%7Bn%3D1%2C2%2C..%2CT-1%7D%7D%7D%5C%2C%5C%2C%5C%2CE%5BU(W_T)%5D%24%24%0A%0A%0A%20%20%20%20%24%24%5Ctext%7Bsubject%20to%3A%20%20%7D%20%5Cbeta_0%20%5Cleq%20W_0%20-%20%5Csum_%7Bi%3D1%7D%5E%7Bm%7D%20S_%7Bi%2C0%7D%5B%5Calpha_%7Bi%2C0%7D%20%2B%20%7C%5Calpha_%7Bi%2C0%7D%7C%5D%2C%24%24%0A%0A%20%20%20%20%24%24%5Cbeta_n(I_n)%20%5Cleq%20(1%2Br)%5Cbeta_%7Bn-1%7D(I_n)%20%2B%20%5Csum_%7Bi%3D1%7D%5E%7Bm%7D%20S_%7Bi%2Cn%7D(I_n)%5B%5Calpha_%7Bi%2Cn-1%7D(I_n)%20-%20%5Calpha_%7Bi%2Cn%7D(I_n)%20-%20%5Ctheta_i%20%7C%5Calpha_%7Bi%2Cn-1%7D(I_n)%20-%20%5Calpha_%7Bi%2Cn%7D(I_n)%7C%5D%2C%24%24%0A%0A%20%20%20%20%24%24W_T(I_T)%20%5Cleq%20(1%2Br)%5Cbeta_%7BT-1%7D(I_T)%20%2B%20%5Csum_%7Bi%3D1%7D%5E%7Bm%7D%20S_%7Bi%2CT%7D(I_T)%5B%5Calpha_%7Bi%2CT-1%7D(I_T)%20-%20%5Ctheta_i%20%7C%5Calpha_%7Bi%2CT-1%7D(I_T)%7C%5D%2C%5C%2C%5C%2C%5C%2C%20%5Cforall%20I_T%5Cin%20F_T%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(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%202.)%20Price%20vector%20process%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%20The%20continuous%20price%20process%20that%20we%20intended%20to%20approximate%20is%3A%0A%0A%20%20%20%20%24%24%5Cfrac%7Bd%5Ctilde%7BS_i%7D%7D%7B%5Ctilde%7BS_i%7D%7D%20%3D%20%5Cmu_idt%20%2B%20%5Csum_%7Bj%3D1%7D%5E%7Bm%7D%5Csigma_%7Bij%7D%20dW_j%20%5C%2C%5C%2C%20%2C%20%5C%2C%5C%2C%20%5Cforall%20i%20%3D%201%2C2%2C...%2Cm%24%24%0A%0A%20%20%20%20where%20%24%5Cmu_i%24%20and%20%24%5Csigma_%7Bij%7D%24%20are%20positive%20constants%20and%20the%20%24W_j%24%20denote%20un-correlated%20standard%20Wiener%20processes.%20To%20construct%20a%20discrete%20approximation%2C%20we%20first%20define%20a%20stochastic%20vector%20as%20follows%3A%0A%0A%20%20%20%20%24%24(%5Cepsilon_1%2C%5Cepsilon_2%2C..%2C%5Cepsilon_m)%20%3D%20%5Cbegin%7Bcases%7D%0A%20%20%20%20(%5Cepsilon_1%20(%5Comega_1)%2C%5Cepsilon_2%20(%5Comega_1)%2C..%2C%5Cepsilon_m%20(%5Comega_1))%2C%20%5C%2C%5C%2C%20%5Ctext%7Bwith%20probability%20%7D%20q_1%2C%20%5C%5C%0A%20%20%20%20(%5Cepsilon_1%20(%5Comega_2)%2C%5Cepsilon_2%20(%5Comega_2)%2C..%2C%5Cepsilon_m%20(%5Comega_2))%2C%20%5C%2C%5C%2C%20%5Ctext%7Bwith%20probability%20%7D%20q_2%2C%20%5C%5C%0A%20%20%20%20(%5Cepsilon_1%20(%5Comega_3)%2C%5Cepsilon_2%20(%5Comega_3)%2C..%2C%5Cepsilon_m%20(%5Comega_3))%2C%20%5C%2C%5C%2C%20%5Ctext%7Bwith%20probability%20%7D%20q_3%20%3D%20(1-q_1-q_2)%0A%20%20%20%20%5Cend%7Bcases%7D%0A%20%20%20%20%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(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%20The%20equation%20describing%20the%20event%20tree%20(first%20equation%20of%20the%20notebook)%20becomes%20a%20discrete%20approximation%20of%20the%20above-stated%20stochastic%20process%20if%20we%20set%3A%0A%0A%20%20%20%20%24%24a_i%20%3D%20e%5E%7B%5Cmu_i%20%5CDelta%20t%7D%5Cbigg(%20%5Cfrac%7Be%5E%7B%5Cbig%5B%5Csum_%7Bj%3D1%7D%5E%7Bm%7D%5Csigma_%7Bij%7D%5Cepsilon_j(%5Comega_1)%5Csqrt%7B%5CDelta%20t%7D%5Cbig%5D%7D%7D%7Bz_i%7D%5Cbigg)%24%24%0A%0A%20%20%20%20%24%24b_i%20%3D%20e%5E%7B%5Cmu_i%20%5CDelta%20t%7D%5Cbigg(%20%5Cfrac%7Be%5E%7B%5Cbig%5B%5Csum_%7Bj%3D1%7D%5E%7Bm%7D%5Csigma_%7Bij%7D%5Cepsilon_j(%5Comega_2)%5Csqrt%7B%5CDelta%20t%7D%5Cbig%5D%7D%7D%7Bz_i%7D%5Cbigg)%24%24%0A%0A%20%20%20%20%24%24c_i%20%3D%20e%5E%7B%5Cmu_i%20%5CDelta%20t%7D%5Cbigg(%20%5Cfrac%7Be%5E%7B%5Cbig%5B%5Csum_%7Bj%3D1%7D%5E%7Bm%7D%5Csigma_%7Bij%7D%5Cepsilon_j(%5Comega_3)%5Csqrt%7B%5CDelta%20t%7D%5Cbig%5D%7D%7D%7Bz_i%7D%5Cbigg)%24%24%0A%0A%0A%0A%20%20%20%20In%20the%20limit%20%24T%5Cto%20%5Cinfty%24%20(or%20alternatively%20%24%5CDelta%20t%20%5Cto%200%24)%2C%20the%20approximation%20approaches%20the%20continuous%20process.%0A%20%20%20%20%22%22%22%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%23%23%23%203.)%20Investor's%20reservation%20purchase%20price%20for%20a%20European%20call%20option%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(r%22%22%22Suppose%20that%20an%20investor%20is%20interested%20in%20buying%20a%20European%20call%20option%20on%20the%20security%20%24S_1%24%2C%20with%20time%20to%20maturity%20%24%5Coverline%7BT%7D%24%20and%20a%20strike%20price%20%24K%3E0%24.%20At%20the%20expiration%20time%2C%20the%20investor%20would%20get%20a%20payment%20of%20%24%5Ctext%7Bmax%7D(S_%7B1%2CT%7D%20-%20K%2C%200)%24%20(assuming%20cash%20settlement%20and%20also%20that%20the%20investor%20will%20not%20be%20re-selling%20the%20option%20once%20it%20has%20been%20purchased.)%20Our%20goal%20is%20now%20to%20estimate%20the%20highest%20price%20this%20investor%20is%20willing%20to%20pay%2C%20to%20purchase%20such%20an%20option.%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(r%22%22%22If%20the%20investor%20does%20not%20purchase%20the%20call%20option%20and%20only%20trades%20in%20the%20risky%20securities%20%24S_i%24%20and%20the%20bonds%2C%20then%20the%20portfolio%20is%20given%20by%20the%20optimization%20problem%20stated%20above.%20However%2C%20if%20the%20investor%20buys%20the%20call%20option%20at%20a%20reservation%20purchase%20price%20of%20%24C%24%2C%20then%20their%20portfolio%20becomes%20the%20following%3A%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%24%24P(C%2CW_0)%20%3D%20%5Ctext%7Bmaximize%7D_%7B(%7B%5Cmathbf%7B%5Calpha%7D_n(I_n)%2C%5Cbeta_n(I_n))%7D_%7BI_n%5Cin%20F_T%2C%7Bn%3D1%2C2%2C..%2CT-1%7D%7D%7D%5C%2C%5C%2C%5C%2CE%5BU(W_T)%5D%24%24%0A%0A%0A%20%20%20%20%24%24%5Ctext%7Bsubject%20to%3A%20%20%20%7D%5Cbeta_0%20%5Cleq%20W_0%20-%20C%20-%20%5Csum_%7Bi%3D1%7D%5E%7Bm%7D%20S_%7Bi%2C0%7D%5B%5Calpha_%7Bi%2C0%7D%20%2B%20%7C%5Calpha_%7Bi%2C0%7D%7C%5D%2C%24%24%0A%0A%20%20%20%20%24%24%5Cbeta_n(I_n)%20%5Cleq%20(1%2Br)%5Cbeta_%7Bn-1%7D(I_n)%20%2B%20%5Csum_%7Bi%3D1%7D%5E%7Bm%7D%20S_%7Bi%2Cn%7D(I_n)%5B%5Calpha_%7Bi%2Cn-1%7D(I_n)%20-%20%5Calpha_%7Bi%2Cn%7D(I_n)%20-%20%5Ctheta_i%20%7C%5Calpha_%7Bi%2Cn-1%7D(I_n)%20-%20%5Calpha_%7Bi%2Cn%7D(I_n)%7C%5D%2C%24%24%0A%0A%20%20%20%20%24%24W_T(I_T)%20%5Cleq%20(1%2Br)%5Cbeta_%7BT-1%7D(I_T)%20%2B%20%5Csum_%7Bi%3D1%7D%5E%7Bm%7D%20S_%7Bi%2CT%7D(I_T)%5B%5Calpha_%7Bi%2CT-1%7D(I_T)%20-%20%5Ctheta_i%20%7C%5Calpha_%7Bi%2CT-1%7D(I_T)%7C%5D%20%2B%20%5Ctext%7Bmax%7D(S_%7B1%2CT%7D(I_T)%20-%20K%2C0)%2C%20%5C%2C%5C%2C%5C%2C%20%5Cforall%20I_T%5Cin%20F_T%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(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%20The%20highest%20price%20that%20investor%20is%20willing%20to%20pay%20for%20the%20given%20call%20option%2C%20is%20therefore%20given%20by%20the%20price%20for%20which%20the%20maximum%20expected%20utility%20in%20the%20two%20portfolios%20becomes%20equal%2C%20making%20the%20investor%20indifferent%20to%20the%20choices.%20Thus%2C%20the%20final%20optimization%20problem%20that%20we%20need%20to%20consider%20is%3A%0A%0A%20%20%20%20%24%24C%5E*%20%3D%20%5Ctext%7Bmaximize%7D_%7B(%7B%5Cmathbf%7B%5Calpha%7D_n(I_n)%2C%5Cbeta_n(I_n))%7D_%7BI_n%5Cin%20F_T%2C%7Bn%3D1%2C2%2C..%2CT-1%7D%7D%7D%20%5C%2C%5C%2C%5C%2C%20C%24%24%0A%0A%20%20%20%20%24%24%5Ctext%7Bsubject%20to%3A%20%7D%20E%5BU(W_T)%5D%20%5Cgeq%20U%5E*(W_0)%20%24%24%0A%0A%20%20%20%20along%20with%20the%20other%20constraints%20mentioned%20in%20the%20optimization%20problem%20for%20the%20portfolio%20in%20which%20the%20option%20is%20purchased.%0A%20%20%20%20%22%22%22%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%23%23%23%204.)%20Utility%20function%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%20In%20the%20optimization%20problems%20mentioned%20above%2C%20we%20need%20to%20optimize%20the%20expected%20utility.%20The%20utility%20functions%20that%20we%20consider%20are%20members%20of%20a%20family%20called%20HARA%20utility%20functions%20(Hyperbolic%20Absolute%20Risk%20Aversion).%20The%20general%20expression%20for%20HARA%20utility%20is%3A%0A%0A%20%20%20%20%24%24U(W)%20%3D%20%5Cfrac%7B1-%5Cgamma%7D%7B%5Cgamma%7D%5Cbigg(%5Cfrac%7BaW%7D%7B1-%5Cgamma%7D%20%2B%20b%5Cbigg)%5E%5Cgamma%20%5C%2C%3B%5C%2C%20a%3E0%24%24%0A%0A%20%20%20%20where%20%24W%20%3E%20((%5Cgamma%20-%201)b)%2Fa%24.%20Note%20that%20the%20exponential%20and%20logarithmic%20utility%20functions%20are%20also%20members%20of%20the%20HARA-class.%0A%20%20%20%20%22%22%22%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(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20Another%20thing%20to%20consider%20is%20the%20Arrow-Pratt%20measure%20of%20the%20Absolute%20risk%20aversion.%20For%20the%20HARA-class%2C%20it%20is%3A%0A%0A%20%20%20%20%24%24ARA(W)%20%3D%20%5Cbigg(%5Cfrac%7BW%7D%7B1-%5Cgamma%7D%20%2B%20%5Cfrac%7Bb%7D%7Ba%7D%5Cbigg)%5E%7B-1%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(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%20Fusion%20Implementation%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(r%22%22%22Now%20we%20proceed%20with%20the%20construction%20of%20the%20fusion%20model.%20We%20start%20by%20making%20a%20Tree%20class%20that%20will%20represent%20the%20event%20tree%20discussed%20above.%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%23%23%20Parameters%20for%20Initializing%20the%20Tree%20Class%0A%0A%20%20%20%20When%20creating%20a%20Tree%20object%2C%20the%20following%20parameters%20define%20the%20investment%20environment%20and%20decision-making%20setup%3A%0A%0A%20%20%20%20-%20**M**%20%E2%80%93%20The%20optimization%20model%2C%20typically%20a%20MOSEK%20Fusion%20%60Model%60%2C%20that%20will%20hold%20variables%2C%20constraints%2C%20and%20the%20objective.%20%20%0A%20%20%20%20-%20**T**%20%E2%80%93%20The%20number%20of%20discrete%20time%20steps%20in%20the%20investment%20horizon.%20%20%0A%20%20%20%20-%20**W%E2%82%80**%20%E2%80%93%20The%20investor%E2%80%99s%20initial%20wealth%20at%20time%200.%20%20%0A%20%20%20%20-%20**S**%20%E2%80%93%20The%20price-scaling%20matrix%20that%20adjusts%20asset%20prices%20over%20time.%20%20%0A%20%20%20%20-%20**%CE%B8**%20%E2%80%93%20The%20vector%20of%20transaction%20costs%2C%20representing%20costs%20incurred%20when%20trading%20risky%20assets.%20%20%0A%20%20%20%20-%20**S%E1%B5%A5%E2%82%80**%20%E2%80%93%20The%20initial%20price%20vector%20for%20the%20risky%20securities%20at%20time%200.%20%20%0A%20%20%20%20-%20**r**%20%E2%80%93%20The%20risk-free%20interest%20rate%20applied%20to%20bonds.%20%20%0A%20%20%20%20-%20**U%20%3D%20%5Ba%2C%20b%2C%20%CE%B3%5D**%20%E2%80%93%20The%20set%20of%20parameters%20defining%20the%20investor%E2%80%99s%20HARA%20(Hyperbolic%20Absolute%20Risk%20Aversion)%20utility%20function%2C%20capturing%20risk%20preferences.%0A%20%20%20%20%22%22%22%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%23%23%23%20HARA%20utility%20as%20a%20Power%20cone%3A%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%20The%20objective%20function%20is%3A%0A%0A%20%20%20%20%24%24%5Ctext%7Bmaximize%20%20%20%7DE%5BU(W_T)%5D%20%3D%20%5Csum_%7BI_T%5Cin%20F_T%7DP(I_T)%20%5Cbigg(%5Cfrac%7B1-%5Cgamma%7D%7B%5Cgamma%7D%5Cbigg)%20%20%5Cbigg(%5Cfrac%7BaW(I_T)%7D%7B1-%5Cgamma%7D%20%2B%20b%5Cbigg)%5E%5Cgamma%24%24%0A%0A%20%20%20%20where%20%24P(I_T)%24%20is%20the%20probability%20of%20a%20given%20path.%20We%20can%20re-write%20this%20as%3A%0A%0A%0A%20%20%20%20%24%24%5Ctext%7Bmaximize%20%20%20%7D%20%5Csum_%7BI_T%5Cin%20F_T%7DP(I_T)%20%5Cbigg(%5Cfrac%7B1-%5Cgamma%7D%7B%5Cgamma%7D%5Cbigg)%20h(I_T)%24%24%0A%0A%20%20%20%20%24%24%5Ctext%7Bsubject%20to%20%3A%20%20%20%7D%20h(I_T)%5Cleq%20%5Cbigg(%5Cfrac%7BaW(I_T)%7D%7B1-%5Cgamma%7D%20%2B%20b%5Cbigg)%5E%5Cgamma%24%24%0A%0A%0A%20%20%20%20Now%2C%20the%20constraint%20can%20be%20expressed%20as%20a%20Power%20cone.%20However%2C%20there%20are%20a%20few%20possible%20cases%3A%0A%0A%20%20%20%201.)%20%24%5Cgamma%20%3E%201%24%3A%20In%20this%20case%2C%20the%20conic%20representation%20is%3A%0A%0A%20%20%20%20%24%24%5CBigg(h(I_T)%2C1%2C%5Cbigg(%5Cfrac%7BaW(I_T)%7D%7B1-%5Cgamma%7D%20%2B%20b%5Cbigg)%20%5CBigg)%20%5Cin%20%5Cmathcal%7BP%7D_3%5E%7B1%2F%5Cgamma%7D%24%24%0A%0A%20%20%20%202.)%20%240%20%3C%20%5Cgamma%20%3C%201%24%3A%0A%0A%20%20%20%20%24%24%5CBigg(%5Cbigg(%5Cfrac%7BaW(I_T)%7D%7B1-%5Cgamma%7D%20%2B%20b%5Cbigg)%2C1%2C%20h(I_T)%20%5CBigg)%20%5Cin%20%5Cmathcal%7BP%7D_3%5E%7B%5Cgamma%7D%24%24%0A%0A%20%20%20%203.)%20%24%5Cgamma%20%3C%200%24%3A%0A%0A%20%20%20%20%24%24%5CBigg(h(I_T)%2C%5Cbigg(%5Cfrac%7BaW(I_T)%7D%7B1-%5Cgamma%7D%20%2B%20b%5Cbigg)%2C1%20%20%5CBigg)%20%5Cin%20%5Cmathcal%7BP%7D_3%5E%7B1%2F(1-%5Cgamma)%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(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20Exponential%20utility%20as%20an%20exponential%20cone%3A%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%20The%20objective%20function%20in%20the%20case%20of%20exponential%20utility%20will%20be%20given%20by%3A%0A%0A%20%20%20%20%24%24%5Ctext%7Bmaximize%20%20%20%7DE%5BU(W_T)%5D%20%3D%20%5Csum_%7BI_T%5Cin%20F_T%7DP(I_T)%20%5Cbigg(1%20-%20e%5E%7B-%20%5B%5Ctext%7BARA%7D(W)%5D%20W(I_T)%7D%5Cbigg)%0A%20%20%20%20%24%24%0A%0A%20%20%20%20if%20the%20Absolute%20Risk%20aversion%20is%20nonzero.%20However%2C%20if%20ARA%24(W)%20%3D%200%24%2C%20then%20the%20objective%20function%20is%20simply%3A%0A%0A%20%20%20%20%24%24%5Ctext%7Bmaximize%20%20%20%7DE%5BU(W_T)%5D%20%3D%20%5Csum_%7BI_T%5Cin%20F_T%7DP(I_T)%20W(I_T)%24%24%0A%0A%20%20%20%20For%20the%20non-zero%20ARA%24(W)%24%2C%20we%20express%20the%20objective%20function%20as%20follows%3A%0A%0A%20%20%20%20%24%24%5Ctext%7Bmaximize%20%20%20%7D%20%5Csum_%7BI_T%5Cin%20F_T%7DP(I_T)%20h(I_T)%24%24%0A%0A%20%20%20%20%24%24%5Ctext%7Bsubject%20to%3A%20%20%7D%20(1-h(I_T))%5Cgeq%20e%5E%7B-%5B%5Ctext%7BARA%7D(W)%5DW(I_T)%7D%24%24%0A%0A%20%20%20%20and%20the%20constraint%20is%20readily%20expressed%20as%20an%20exponential%20cone%3A%0A%0A%20%20%20%20%24%24%5Cbig((1-h(I_T))%2C1%2C-%5B%5Ctext%7BARA%7D(W)%5DW(I_T)%5Cbig)%20%5Cin%20K_%7Bexp%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%20import%20numpy%20as%20np%0A%20%20%20%20from%20mosek.fusion%20import%20Model%2C%20Domain%2C%20Expr%2C%20ObjectiveSense%2C%20Matrix%2C%20Var%2C%20SolutionStatus%0A%20%20%20%20import%20sys%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20import%20time%0A%20%20%20%20return%20Domain%2C%20Expr%2C%20Model%2C%20ObjectiveSense%2C%20np%2C%20sys%0A%0A%0A%40app.cell%0Adef%20_(Domain%2C%20Expr%2C%20Level%2C%20np)%3A%0A%20%20%20%20class%20Tree%3A%20%20%20%20%0A%20%20%20%20%20%20%20%20%23%20Instantiate%20the%20Tree%20class.%0A%20%20%20%20%20%20%20%20def%20__init__(self%2C%20M%2C%20T%2C%20W_0%2C%20S%2C%20theta%2C%20S_v_0%2C%20r%2C%20U)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20self.M%20%3D%20M%0A%20%20%20%20%20%20%20%20%20%20%20%20self.W_0%20%3D%20W_0%0A%20%20%20%20%20%20%20%20%20%20%20%20self.T%20%3D%20T%0A%20%20%20%20%20%20%20%20%20%20%20%20self.S_v%20%3D%20S%0A%20%20%20%20%20%20%20%20%20%20%20%20self.r%20%3D%20r%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Shape%20of%20the%20cost%20scaling%20matrix%20will%20give%20us%20the%20split%20index%20and%20the%20number%20of%20risky%20securities.%0A%20%20%20%20%20%20%20%20%20%20%20%20self.s%2C%20self.n%20%3D%20S.shape%0A%20%20%20%20%20%20%20%20%20%20%20%20self.cost%20%3D%20np.asarray(%5Btheta%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20self.S_v_0%20%3D%20S_v_0%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Parameters%20for%20the%20utility%20function.%0A%20%20%20%20%20%20%20%20%20%20%20%20self.U%20%3D%20U%0A%20%20%20%20%20%20%20%20%20%20%20%20self.S_v_t%20%3D%20S_v_0%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20This%20is%20to%20decide%20which%20utility%20will%20be%20used.%0A%20%20%20%20%20%20%20%20%20%20%20%20self.util_dispatch%20%3D%20%7B'HARA'%3A%20self.HARA_util%2C%20'EXP'%3A%20self.exp_util%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20self.levels%20%3D%20%5B%5D%0A%0A%20%20%20%20%20%20%20%20%23%20Method%20to%20make%20all%20the%20levels%2C%20or%20the%20time%20steps%20in%20the%20tree.%0A%20%20%20%20%20%20%20%20def%20level_make(self)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Number%20of%20risky%20securities%2C%20i.e.%20alpha%7Bi%2Ct%3D0%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20self.a0%20%3D%20self.M.variable('a_0'%2C%20%5B1%2C%20self.n%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Bonds%20at%20t%3D0.%0A%20%20%20%20%20%20%20%20%20%20%20%20self.b0%20%3D%20self.M.variable('b_0'%2C%201)%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Making%20the%20first%20budget%20constraint.%0A%20%20%20%20%20%20%20%20%20%20%20%20self.budg_ex%20%3D%20Expr.sub(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Expr.sub(self.W_0%2C%20self.b0)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Expr.dot(self.S_v_0%2C%20Expr.mulElm(1%20%2B%20self.cost%2C%20self.a0))%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20self.root_budget%20%3D%20self.M.constraint('Budget_0'%2C%20self.budg_ex%2C%20Domain.greaterThan(0.0))%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20This%20list%20will%20hold%20the%20level%20objects%20associated%20to%20this%20tree.%0A%20%20%20%20%20%20%20%20%20%20%20%20a%2C%20b%20%3D%20self.a0%2C%20self.b0%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20i%20in%20range(1%2C%20self.T%20%2B%201)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20Appending%20level%20n%2C%20based%20on%20the%20level%20(n-1).%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20self.levels.append(Level(i%2C%20self%2C%20a%2C%20b))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20a%20%3D%20self.levels%5Bi%20-%201%5D.a_new%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20b%20%3D%20self.levels%5Bi%20-%201%5D.b_new%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20a_T%20is%20zero%20().%0A%0A%20%20%20%20%20%20%20%20%23%20Method%20to%20make%20the%20HARA%20utility%20function%20and%20the%20corresponding%20Power-cone%20constraint.%0A%20%20%20%20%20%20%20%20def%20HARA_util(self%2C%20W)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20self.h%20%3D%20self.M.variable('h'%2C%20self.s**self.T%2C%20Domain.greaterThan(0.0))%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20HARA%20utility%20is%20only%20defined%20for%20when%20W%20%3E%20(gamma%20-%201)a%2Fb.%0A%20%20%20%20%20%20%20%20%20%20%20%20self.M.constraint(W%2C%20Domain.greaterThan(self.U%5B1%5D%20*%20(self.U%5B2%5D%20-%201)%20%2F%20self.U%5B0%5D))%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20I%20%3D%20Expr.constTerm(%5Bself.s**self.T%5D%2C%201.0)%0A%20%20%20%20%20%20%20%20%20%20%20%20self.E1%20%3D%20Expr.add(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Expr.mul(self.U%5B0%5D%20%2F%20(1%20-%20self.U%5B2%5D)%2C%20W)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Expr.constTerm(W.getShape()%2C%20self.U%5B1%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Different%20cases%20for%20different%20gamma%20values%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20self.U%5B2%5D%20%3E%201.0%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20self.M.constraint('Obj_terms_HARA'%2C%20Expr.hstack(self.h%2C%20I%2C%20self.E1)%2C%20Domain.inPPowerCone(1%20%2F%20self.U%5B2%5D))%0A%20%20%20%20%20%20%20%20%20%20%20%20elif%20self.U%5B2%5D%20%3C%200.0%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20self.M.constraint('Obj_terms_HARA'%2C%20Expr.hstack(self.h%2C%20self.E1%2C%20I)%2C%20Domain.inPPowerCone(1%20%2F%20(1%20-%20self.U%5B2%5D)))%0A%20%20%20%20%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20self.M.constraint('Obj_terms_HARA'%2C%20Expr.hstack(self.E1%2C%20I%2C%20self.h)%2C%20Domain.inPPowerCone(self.U%5B2%5D))%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20Expr.mul(((1%20-%20self.U%5B2%5D)%20%2F%20self.U%5B2%5D)%2C%20self.h)%0A%0A%20%20%20%20%20%20%20%20%23%20Method%20to%20make%20the%20Exponential%20utility%20constraints.%0A%20%20%20%20%20%20%20%20def%20exp_util(self%2C%20W)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Zero%20ARA(W)%20case%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20self.U%20%3D%3D%200%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20W%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Nonzero%20ARA(W)%20case%0A%20%20%20%20%20%20%20%20%20%20%20%20self.h%20%3D%20self.M.variable('h'%2C%20self.s**self.T)%0A%20%20%20%20%20%20%20%20%20%20%20%20I%20%3D%20Expr.constTerm(%5Bself.s**self.T%5D%2C%201.0)%0A%20%20%20%20%20%20%20%20%20%20%20%20E_exp%20%3D%20Expr.mul(-self.U%2C%20W)%0A%20%20%20%20%20%20%20%20%20%20%20%20self.M.constraint('Obj_terms_exp'%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Expr.hstack(Expr.sub(I%2C%20Expr.mul(self.U%2C%20self.h))%2C%20I%2C%20E_exp)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Domain.inPExpCone())%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20self.h%0A%0A%20%20%20%20return%20(Tree%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%20The%20%3Ci%3ETree%3C%2Fi%3E%20class%20defined%20above%20has%20the%20sub-class%20%3Ci%3ELevel%3C%2Fi%3E.%20The%20budget%20constraints%20involved%20in%20our%20model%20connect%20variables%20that%20lie%20in%20consecutive%20levels.%20Therefore%2C%20we%20can%20visualize%20all%20the%20constraints%20between%20two%20levels%20in%20the%20following%20manner%20(Note%3A%20for%20ease%20of%20visualization%2C%20we%20take%20the%20split%20index%20as%20%24s%20%3D%203%24%2C%20and%20a%20time%20period%20of%20n%20%3D%203)%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Bpmatrix%7D%0A%20%20%20%20a%5Cbegin%7Bbmatrix%7D%0A%20%20%20%20S_%7B(1%2C2)%7D%20%5C%5C%0A%20%20%20%20S_%7B(2%2C2)%7D%20%5C%5C%0A%20%20%20%20S_%7B(3%2C2)%7D%20%5C%5C%0A%20%20%20%20%5Cend%7Bbmatrix%7D%5C%5C%0A%20%20%20%20b%5Cbegin%7Bbmatrix%7D%0A%20%20%20%20S_%7B(1%2C2)%7D%20%5C%5C%0A%20%20%20%20S_%7B(2%2C2)%7D%20%5C%5C%0A%20%20%20%20S_%7B(3%2C2)%7D%20%5C%5C%0A%20%20%20%20%5Cend%7Bbmatrix%7D%5C%5C%0A%20%20%20%20c%5Cbegin%7Bbmatrix%7D%0A%20%20%20%20S_%7B(1%2C2)%7D%20%5C%5C%0A%20%20%20%20S_%7B(2%2C2)%7D%20%5C%5C%0A%20%20%20%20S_%7B(3%2C2)%7D%20%5C%5C%0A%20%20%20%20%5Cend%7Bbmatrix%7D%5C%5C%0A%20%20%20%20%5Cend%7Bpmatrix%7D%0A%20%20%20%20%3A%0A%20%20%20%20%5Cbegin%7Bpmatrix%7D%0A%20%20%20%20%5Cbegin%7Bbmatrix%7D%0A%20%20%20%20%5Cmathbf%7B%5Calpha_%7B(1%2C2)%7D%7D%2C%5Cbeta_%7B(1%2C2)%7D%20%5C%5C%0A%20%20%20%20%5Cmathbf%7B%5Calpha_%7B(2%2C2)%7D%7D%2C%5Cbeta_%7B(2%2C2)%7D%20%5C%5C%0A%20%20%20%20%5Cmathbf%7B%5Calpha_%7B(3%2C2)%7D%7D%2C%5Cbeta_%7B(3%2C2)%7D%20%5C%5C%0A%20%20%20%20%5Cend%7Bbmatrix%7D%20%5C%5C%0A%20%20%20%20%5Cbegin%7Bbmatrix%7D%0A%20%20%20%20%5Cmathbf%7B%5Calpha_%7B(1%2C2)%7D%7D%2C%5Cbeta_%7B(1%2C2)%7D%20%5C%5C%0A%20%20%20%20%5Cmathbf%7B%5Calpha_%7B(2%2C2)%7D%7D%2C%5Cbeta_%7B(2%2C2)%7D%20%5C%5C%0A%20%20%20%20%5Cmathbf%7B%5Calpha_%7B(3%2C2)%7D%7D%2C%5Cbeta_%7B(3%2C2)%7D%20%5C%5C%0A%20%20%20%20%5Cend%7Bbmatrix%7D%20%5C%5C%0A%20%20%20%20%5Cbegin%7Bbmatrix%7D%0A%20%20%20%20%5Cmathbf%7B%5Calpha_%7B(1%2C2)%7D%7D%2C%5Cbeta_%7B(1%2C2)%7D%20%5C%5C%0A%20%20%20%20%5Cmathbf%7B%5Calpha_%7B(2%2C2)%7D%7D%2C%5Cbeta_%7B(2%2C2)%7D%20%5C%5C%0A%20%20%20%20%5Cmathbf%7B%5Calpha_%7B(3%2C2)%7D%7D%2C%5Cbeta_%7B(3%2C2)%7D%20%5C%5C%0A%20%20%20%20%5Cend%7Bbmatrix%7D%20%5C%5C%0A%20%20%20%20%5Cend%7Bpmatrix%7D%20%20%5Clongrightarrow%0A%20%20%20%20%5Cbegin%7Bpmatrix%7D%0A%20%20%20%20%5Cmathbf%7B%5Calpha_%7B(1%2C3)%7D%7D%2C%5Cbeta_%7B(1%2C3)%7D%20%5C%5C%0A%20%20%20%20%5Cmathbf%7B%5Calpha_%7B(2%2C3)%7D%7D%2C%5Cbeta_%7B(2%2C3)%7D%20%5C%5C%0A%20%20%20%20%5Cmathbf%7B%5Calpha_%7B(3%2C3)%7D%7D%2C%5Cbeta_%7B(3%2C3)%7D%20%5C%5C%0A%20%20%20%20%5Cmathbf%7B%5Calpha_%7B(4%2C3)%7D%7D%2C%5Cbeta_%7B(4%2C3)%7D%20%5C%5C%0A%20%20%20%20%5Cmathbf%7B%5Calpha_%7B(5%2C3)%7D%7D%2C%5Cbeta_%7B(5%2C3)%7D%20%5C%5C%0A%20%20%20%20%5Cmathbf%7B%5Calpha_%7B(6%2C3)%7D%7D%2C%5Cbeta_%7B(6%2C3)%7D%20%5C%5C%0A%20%20%20%20%5Cmathbf%7B%5Calpha_%7B(7%2C3)%7D%7D%2C%5Cbeta_%7B(7%2C3)%7D%20%5C%5C%0A%20%20%20%20%5Cmathbf%7B%5Calpha_%7B(8%2C3)%7D%7D%2C%5Cbeta_%7B(8%2C3)%7D%20%5C%5C%0A%20%20%20%20%5Cmathbf%7B%5Calpha_%7B(9%2C3)%7D%7D%2C%5Cbeta_%7B(9%2C3)%7D%20%5C%5C%0A%20%20%20%20%5Cend%7Bpmatrix%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Here%2C%20the%20first%20column%20vector%20is%20a%20%3Ci%3E%22vstack%22%3C%2Fi%3E%20of%20the%20price%20vector%20at%20level%20%24n%3D2%24%2C%20multiplied%20by%20the%20scaling%20factors%20for%20the%20price.%20Therefore%2C%20the%20first%20column%20is%20the%20new%20price%20vector%20(for%20%24n%3D3%24).%20In%20the%20second%20column%2C%20%24%5Calpha%24's%20will%20be%20vectors%20if%20there%20are%20multiple%20risky%20securities.%20Also%2C%20%24%5Calpha_%7B(i%2Cn)%7D%24%20and%20%24%5Cbeta_%7B(i%2Cn)%7D%24%20correspond%20to%20the%20number%20of%20risky%20securities%20and%20the%20bonds%2C%20respectively%2C%20for%20the%20%24i%5E%7B%5Ctext%7Bth%7D%7D%24%20path%20at%20the%20%24n%5E%7B%5Ctext%7Bth%7D%7D%24%20time%20period.%20It%20is%20to%20be%20realized%20that%20for%20a%20given%20time%20period%2C%20%241%5Cleq%20i%20%5Cleq%20s%5En%24.%0A%0A%20%20%20%20The%20above-stated%20representation%20shows%20that%20we%20can%20%3Ci%3E%22repeat%22%3C%2Fi%3E%20the%20variables%20of%20the%20previous%20level%20%24s%24%20number%20of%20times%20and%20then%20it%20becomes%20quite%20easy%20to%20implement%20the%20budget%20constraints%20in%20%3Ci%3EFusion%3C%2Fi%3E.%20One%20can%20also%20extend%20the%20above%20shown%20method%20to%20a%20higher%20split%20index.%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%20np)%3A%0A%20%20%20%20%23%20Each%20level%20corresponds%20to%20a%20time%20step%20in%20the%20event%20tree.%0A%20%20%20%20class%20Level%3A%0A%20%20%20%20%20%20%20%20%23%20l%20corresponds%20to%20the%20time%20step%3B%20a_old%2C%20b_old%20belong%20to%20(l-1)%20in%20the%20tree.%20%0A%20%20%20%20%20%20%20%20def%20__init__(self%2C%20l%2C%20Tree%2C%20a_old%2C%20b_old)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20l%20%3D%3D%20Tree.T%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20If%20the%20current%20level%20is%20the%20final%20time%20period%2C%20then%20all%20risky%20securities%20are%20considered%20sold.%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20self.a_new%20%3D%20Expr.constTerm(%5BTree.s**l%2C%20Tree.n%5D%2C%200.0)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20Final%20step's%20bonds%20are%20the%20wealth%20W(I_T)%3B%20later%20used%20in%20the%20utility%20function.%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20self.b_new%20%3D%20Tree.M.variable('W_T'%2C%20Tree.s**l)%0A%20%20%20%20%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20Risky%20securities%20for%20time%20step%20l.%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20self.a_new%20%3D%20Tree.M.variable(f'a_%7Bl%7D'%2C%20%5BTree.s**l%2C%20Tree.n%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20Bonds%20in%20dollars%20for%20time%20step%20l.%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20self.b_new%20%3D%20Tree.M.variable(f'b_%7Bl%7D'%2C%20Tree.s**l)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Variable%20for%20the%20quadratic%20cone%20to%20implement%20the%20absolute%20value%20constraint.%0A%20%20%20%20%20%20%20%20%20%20%20%20self.t_new%20%3D%20Tree.M.variable(f't_%7Bl%7D'%2C%20%5BTree.s**l%2C%20Tree.n%5D%2C%20Domain.greaterThan(0.0))%0A%20%20%20%20%20%20%20%20%20%20%20%20Tree.cost%20%3D%20np.repeat(Tree.cost%2C%20Tree.s%2C%20axis%3D0)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Repeating%2FStacking%20the%20(l-1)%20level%20variables%20for%20budget%20constraints.%20%0A%20%20%20%20%20%20%20%20%20%20%20%20A%20%3D%20Expr.repeat(a_old%2C%20Tree.s%2C%200)%0A%20%20%20%20%20%20%20%20%20%20%20%20B%20%3D%20Expr.repeat(b_old%2C%20Tree.s%2C%200)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Price%20vector%20of%20previous%20level%2C%20scaled%20and%20stacked%20vertically.%0A%20%20%20%20%20%20%20%20%20%20%20%20Tree.S_v_t%20%3D%20np.vstack(%5Bnp.multiply(j%2C%20Tree.S_v_t)%20for%20j%20in%20Tree.S_v%5D)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Expressions%20for%20budget%20constraints.%0A%20%20%20%20%20%20%20%20%20%20%20%20self.bond_sub%20%3D%20Expr.sub(Expr.mul(B%2C%20(1%20%2B%20Tree.r))%2C%20self.b_new)%0A%20%20%20%20%20%20%20%20%20%20%20%20self.secu_sub%20%3D%20Expr.sub(self.a_new%2C%20A)%0A%20%20%20%20%20%20%20%20%20%20%20%20self.transact%20%3D%20Expr.add(self.secu_sub%2C%20Expr.mulElm(Tree.cost%2C%20self.t_new))%0A%20%20%20%20%20%20%20%20%20%20%20%20self.secu_exp%20%3D%20Expr.mulDiag(self.transact%2C%20Tree.S_v_t.transpose())%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Linear%20budget%20constraint.%0A%20%20%20%20%20%20%20%20%20%20%20%20self.budg_constr%20%3D%20Tree.M.constraint(f'Budget_%7Bl%7D'%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Expr.sub(self.bond_sub%2C%20self.secu_exp)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Domain.greaterThan(0.0))%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Quadratic%20cone%20for%20absolute%20value%20requirement.%0A%20%20%20%20%20%20%20%20%20%20%20%20Tree.M.constraint(f'a%7Bl%7D_abs'%2C%20Expr.stack(2%2C%20self.t_new%2C%20self.secu_sub)%2C%20Domain.inQCone())%0A%20%20%20%20return%20(Level%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20Now%20that%20we%20have%20the%20basic%20structure%20of%20the%20tree%20ready%2C%20we%20can%20easily%20make%20the%20%3Ci%3EFusion%3C%2Fi%3E%20model%20as%20follows...%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(r%22%22%22We%20will%20represent%20the%20paths%20%24I_T%24%20by%20their%20numbers.%20Therefore%2C%20we%20have%20(split_index)%24%5ET%24%20paths.%20Each%20Path%20number%20represented%20in%20the%20base%20of%20the%20split%20index%20will%20give%20us%20a%20unique%20id%20for%20each%20path.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np)%3A%0A%20%20%20%20def%20base_rep(b%2C%20i%2C%20size)%3A%0A%20%20%20%20%20%20%20%20n%20%3D%20np.zeros(size)%0A%20%20%20%20%20%20%20%20for%20j%20in%20range(size)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20n%5Bj%5D%20%3D%20i%20%25%20b%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20i%20%2F%2F%20b%20%3D%3D%200%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20break%0A%20%20%20%20%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20i%20%3D%20i%20%2F%2F%20b%0A%20%20%20%20%20%20%20%20return%20np.flip(n)%0A%0A%20%20%20%20def%20path_id_make(split_index%2C%20T)%3A%0A%20%20%20%20%20%20%20%20path_id%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20for%20i%20in%20range(split_index%20**%20T)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20path_id.append(base_rep(split_index%2C%20i%2C%20T))%0A%20%20%20%20%20%20%20%20return%20np.asarray(path_id).astype(int)%0A%0A%20%20%20%20def%20path_route_calc(path_id%2C%20split_index%2C%20q%2C%20*args)%3A%0A%20%20%20%20%20%20%20%20s%20%3D%20np.zeros(split_index)%0A%20%20%20%20%20%20%20%20for%20_p%20in%20path_id%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20s%5B_p%5D%20%3D%20s%5B_p%5D%20%2B%201%0A%20%20%20%20%20%20%20%20if%20args%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20path_S1%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20j%20in%20range(split_index)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20path_S1.append(args%5B0%5D%5Bj%5D%20**%20s%5Bj%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20path_S1T%20%3D%20np.prod(np.asarray(path_S1))%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20path_S1T%0A%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20path_prob%20%3D%20np.prod(q%20**%20s)%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20path_prob%0A%0A%20%20%20%20def%20price_vector_z(sigma%2C%20eps%2C%20dt%2C%20q)%3A%0A%20%20%20%20%20%20%20%20E%20%3D%20np.exp(np.matmul(eps%2C%20sigma)%20*%20np.sqrt(dt))%0A%20%20%20%20%20%20%20%20return%20np.matmul(q%2C%20E)%0A%0A%20%20%20%20def%20price_vector_abc(sigma%2C%20eps%2C%20dt%2C%20q%2C%20mu%2C%20Z)%3A%0A%20%20%20%20%20%20%20%20E1%20%3D%20np.multiply(np.exp(np.matmul(eps%2C%20sigma)%20*%20np.sqrt(dt))%2C%201%20%2F%20Z)%0A%20%20%20%20%20%20%20%20E2%20%3D%20np.repeat(%5Bnp.exp(mu%20*%20dt)%5D%2C%20eps.shape%5B0%5D%2C%20axis%3D0)%0A%20%20%20%20%20%20%20%20return%20np.multiply(E2%2C%20E1)%0A%20%20%20%20return%20path_id_make%2C%20path_route_calc%2C%20price_vector_abc%2C%20price_vector_z%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20Portfolio%20without%20call%20option%3A%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Expr%2C%20Model%2C%20ObjectiveSense%2C%20Tree%2C%20path_id_make%2C%20path_route_calc%2C%20sys)%3A%0A%20%20%20%20def%20Portfolio(port_params%2C%20util_type%3D'HARA'%2C%20wrtLog%3DTrue)%3A%0A%20%20%20%20%20%20%20%20T%2C%20W_0%2C%20S%2C%20theta%2C%20S_v_0%2C%20r%2C%20U%2C%20q%20%3D%20port_params%0A%20%20%20%20%20%20%20%20M%20%3D%20Model('PORTFOLIO')%0A%20%20%20%20%20%20%20%20if%20wrtLog%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20M.setLogHandler(sys.stdout)%0A%20%20%20%20%20%20%20%20Tree_1%20%3D%20Tree(M%2C%20T%2C%20W_0%2C%20S%2C%20theta%2C%20S_v_0%2C%20r%2C%20U)%0A%20%20%20%20%20%20%20%20Tree_1.level_make()%0A%20%20%20%20%20%20%20%20H%20%3D%20Tree_1.util_dispatch%5Butil_type%5D(Tree_1.levels%5BT%20-%201%5D.b_new)%0A%20%20%20%20%20%20%20%20path_ids%20%3D%20path_id_make(Tree_1.s%2C%20T)%0A%20%20%20%20%20%20%20%20path_probs%20%3D%20%5Bpath_route_calc(_p%2C%20Tree_1.s%2C%20q)%20for%20_p%20in%20path_ids%5D%0A%20%20%20%20%20%20%20%20Obj%20%3D%20Expr.dot(H%2C%20path_probs)%0A%20%20%20%20%20%20%20%20M.objective('PORTFOLIO_OBJ'%2C%20ObjectiveSense.Maximize%2C%20Obj)%0A%20%20%20%20%20%20%20%20M.solve()%0A%20%20%20%20%20%20%20%20utility_W0%20%3D%20M.primalObjValue()%0A%20%20%20%20%20%20%20%20ut_time%20%3D%20M.getSolverDoubleInfo('optimizerTime')%0A%20%20%20%20%20%20%20%20ut_iter%20%3D%20M.getSolverIntInfo('intpntIter')%0A%20%20%20%20%20%20%20%20return%20(M%2C%20Tree_1%2C%20utility_W0%2C%20path_ids%2C%20Obj%2C%20%5But_iter%2C%20ut_time%5D)%0A%20%20%20%20return%20(Portfolio%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20Portfolio%20with%20call%20option%3A%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(r%22%22%22This%20model%20involves%20modifying%20the%20initial%20and%20the%20final%20budget%20constraints%2C%20adding%20a%20constraint%20on%20the%20new%20utility%2C%20creating%20a%20new%20objective%20(the%20option%20price)%20and%20re-optimizing%20the%20previous%20model.%20Fusion%20allows%20re-optimizing%20(this%20saves%20a%20considerable%20amount%20of%20time%2C%20which%20would%20otherwise%20be%20spent%20in%20re-building%20the%20model).%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Domain%2C%20Expr%2C%20ObjectiveSense%2C%20Portfolio%2C%20np%2C%20path_route_calc)%3A%0A%20%20%20%20def%20Option_Portfolio(port_params%2C%20K%2C%20util_type%3D'HARA'%2C%20writeLog%3DTrue%2C%20solver_info%3DFalse)%3A%0A%20%20%20%20%20%20%20%20T%2C%20W_0%2C%20S%2C%20theta%2C%20S_v_0%2C%20r%2C%20U%2C%20q%20%3D%20port_params%0A%20%20%20%20%20%20%20%20M%2C%20Tree_1%2C%20utility_W0%2C%20path_ids%2C%20Obj%2C%20obj_info%20%3D%20Portfolio(port_params%2C%20util_type%3Dutil_type%2C%20wrtLog%3DwriteLog)%0A%20%20%20%20%20%20%20%20path_Svs%20%3D%20np.asarray(%5Bpath_route_calc(_p%2C%20S.shape%5B0%5D%2C%20q%2C%20S%5B%3A%2C%200%5D)%20for%20_p%20in%20path_ids%5D)%0A%20%20%20%20%20%20%20%20call_profit%20%3D%20(path_Svs%20-%20K%20%2B%20abs(path_Svs%20-%20K))%20%2F%202%0A%20%20%20%20%20%20%20%20Call%20%3D%20M.variable('Call_Price'%2C%201%2C%20Domain.inRange(0.0%2C%20S_v_0%5B0%5D))%0A%20%20%20%20%20%20%20%20Tree_1.root_budget.update(Expr.neg(Call)%2C%20Call)%0A%20%20%20%20%20%20%20%20Tree_1.levels%5BT%20-%201%5D.budg_constr.update(call_profit.tolist())%0A%20%20%20%20%20%20%20%20M.constraint('E_geq_U'%2C%20Expr.sub(Obj%2C%20utility_W0)%2C%20Domain.greaterThan(0.0))%0A%20%20%20%20%20%20%20%20M.objective('Call_price_OBJECTIVE'%2C%20ObjectiveSense.Maximize%2C%20Call)%0A%20%20%20%20%20%20%20%20M.solve()%0A%20%20%20%20%20%20%20%20if%20solver_info%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20price_time%20%3D%20M.getSolverDoubleInfo('optimizerTime')%0A%20%20%20%20%20%20%20%20%20%20%20%20price_iter%20%3D%20M.getSolverIntInfo('intpntIter')%0A%20%20%20%20%20%20%20%20%20%20%20%20n_cons%20%3D%20M.getSolverIntInfo('optNumcon')%0A%20%20%20%20%20%20%20%20%20%20%20%20n_vars%20%3D%20M.getSolverIntInfo('optNumvar')%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20(M.primalObjValue()%2C%20n_cons%2C%20n_vars%2C%20obj_info%5B0%5D%2C%20obj_info%5B1%5D%2C%20price_iter%2C%20price_time)%0A%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20M.primalObjValue()%0A%20%20%20%20return%20(Option_Portfolio%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Now%2C%20to%20demonstrate%20the%20model%2C%20we%20solve%20it%20for%20two%20simple%20cases.%20The%20values%20taken%20below%20are%20the%20same%20as%20mentioned%20in%20the%20paper%20(%3Ca%20href%3D%22https%3A%2F%2Fwww.sciencedirect.com%2Fscience%2Farticle%2Fpii%2FS0168927498001044%22%3EAndersen%20et.%20al.%3C%2Fa%3E).%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Option_Portfolio%2C%20np%2C%20price_vector_abc%2C%20price_vector_z)%3A%0A%20%20%20%20T%20%3D%205%0A%20%20%20%20sigma%20%3D%20np.asarray(%5B0.2%5D)%0A%20%20%20%20q%20%3D%20np.ones(3)%20%2F%203%0A%20%20%20%20eps%20%3D%20np.asarray(%5B%5Bnp.sqrt(2)%5D%2C%20%5B-1%20%2F%20np.sqrt(2)%5D%2C%20%5B-1%20%2F%20np.sqrt(2)%5D%5D)%0A%20%20%20%20T_horizon%20%3D%201%20%2F%204%0A%20%20%20%20dT%20%3D%20T_horizon%20%2F%20T%0A%20%20%20%20theta%20%3D%20%5B0.005%5D%0A%20%20%20%20S_v_0%20%3D%20%5B1.0%5D%0A%20%20%20%20r%20%3D%201.06%20**%20dT%20-%201%0A%20%20%20%20W_0%20%3D%201.0%0A%20%20%20%20gamma%20%3D%200.3%0A%20%20%20%20b%20%3D%201%0A%20%20%20%20c%20%3D%200.2%0A%20%20%20%20a%20%3D%20b%20%2F%20(1%20%2F%20c%20%2B%20W_0%20%2F%20(gamma%20-%201))%0A%20%20%20%20K%20%3D%201%0A%20%20%20%20mu%20%3D%200.15%0A%20%20%20%20Z%20%3D%20price_vector_z(sigma%2C%20eps%2C%20dT%2C%20q)%0A%20%20%20%20S_coeffs%20%3D%20np.expand_dims(price_vector_abc(sigma%2C%20eps%2C%20dT%2C%20q%2C%20mu%2C%20Z)%2C%20axis%3D1)%0A%20%20%20%20_util_paras%20%3D%20np.asarray(%5Ba%2C%20b%2C%20gamma%5D)%0A%20%20%20%20_input_pars%20%3D%20%5BT%2C%20W_0%2C%20S_coeffs%2C%20theta%2C%20S_v_0%2C%20r%2C%20_util_paras%2C%20q%5D%0A%20%20%20%20print('%5Cn%5CnCall%20option%20price%20%3D%20%7B%7D'.format(Option_Portfolio(_input_pars%2C%20K)))%0A%20%20%20%20return%20K%2C%20S_coeffs%2C%20S_v_0%2C%20T%2C%20W_0%2C%20b%2C%20c%2C%20eps%2C%20mu%2C%20q%2C%20r%2C%20sigma%2C%20theta%0A%0A%0A%40app.cell%0Adef%20_(K%2C%20Option_Portfolio%2C%20S_coeffs%2C%20S_v_0%2C%20T%2C%20W_0%2C%20c%2C%20q%2C%20r%2C%20theta)%3A%0A%20%20%20%20_input_pars%20%3D%20%5BT%2C%20W_0%2C%20S_coeffs%2C%20theta%2C%20S_v_0%2C%20r%2C%20c%2C%20q%5D%0A%20%20%20%20print('%5Cn%5CnCall%20option%20price%20%3D%20%7B%7D'.format(Option_Portfolio(_input_pars%2C%20K%2C%20util_type%3D'EXP')))%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%23%20Test-cases%3A%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(r%22%22%22%23%23%23%20Reservation%20price%20sensitivity%20for%20the%20choice%20of%20utility%20function%3A%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(r%22%22%22%3Cb%3E(a.)%20Dependency%20of%20the%20reservation%20purchase%20price%20on%20%24%5Cgamma%24%2C%20%24ARA(W_0)%24%20and%20%24%5Coverline%7BT%7D%24.%3C%2Fb%3E%20(Consider%20Table%203%2C%20%3Ca%20href%3D%22https%3A%2F%2Fwww.sciencedirect.com%2Fscience%2Farticle%2Fpii%2FS0168927498001044%22%3EAndersen%20et.%20al.%3C%2Fa%3E)%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(K%2C%20Option_Portfolio%2C%20S_coeffs%2C%20S_v_0%2C%20T%2C%20W_0%2C%20b%2C%20c%2C%20np%2C%20q%2C%20r%2C%20theta)%3A%0A%20%20%20%20gamma_1%20%3D%20%5B-4.0%2C%20-2.0%2C%20-0.9%2C%20-0.3%2C%200.3%2C%200.6%5D%0A%20%20%20%20print('ARA%20%3D%200.2%20%3B%20Time%20Horizon%20%3D%201%2F4%20year')%0A%20%20%20%20print('%7B0%3A%5E6%7D%20%20%7B1%3A%5E9%7D'.format('gamma'%2C%20'C'))%0A%20%20%20%20for%20_g%20in%20gamma_1%3A%0A%20%20%20%20%20%20%20%20a_1%20%3D%20b%20%2F%20(1%20%2F%20c%20%2B%20W_0%20%2F%20(_g%20-%201))%0A%20%20%20%20%20%20%20%20_util_paras%20%3D%20np.asarray(%5Ba_1%2C%20b%2C%20_g%5D)%0A%20%20%20%20%20%20%20%20_input_pars%20%3D%20%5BT%2C%20W_0%2C%20S_coeffs%2C%20theta%2C%20S_v_0%2C%20r%2C%20_util_paras%2C%20q%5D%0A%20%20%20%20%20%20%20%20print('%7B0%3A%5E%205.1f%7D%20%20%7B1%3A%5E9.7f%7D'.format(_g%2C%20Option_Portfolio(_input_pars%2C%20K%2C%20writeLog%3DFalse)))%0A%20%20%20%20_input_pars%20%3D%20%5BT%2C%20W_0%2C%20S_coeffs%2C%20theta%2C%20S_v_0%2C%20r%2C%20c%2C%20q%5D%0A%20%20%20%20print('%7B0%3A%5E5%7D%20%20%7B1%3A%5E9.7f%7D'.format('exp'%2C%20Option_Portfolio(_input_pars%2C%20K%2C%20util_type%3D'EXP'%2C%20writeLog%3DFalse)))%0A%20%20%20%20return%20(gamma_1%2C)%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20K%2C%0A%20%20%20%20Option_Portfolio%2C%0A%20%20%20%20S_coeffs%2C%0A%20%20%20%20S_v_0%2C%0A%20%20%20%20T%2C%0A%20%20%20%20W_0%2C%0A%20%20%20%20b%2C%0A%20%20%20%20gamma_1%2C%0A%20%20%20%20np%2C%0A%20%20%20%20q%2C%0A%20%20%20%20r%2C%0A%20%20%20%20theta%2C%0A)%3A%0A%20%20%20%20c_1%20%3D%201.0%0A%20%20%20%20print('ARA%20%3D%201.0%20%3B%20Time%20Horizon%20%3D%201%2F4%20year')%0A%20%20%20%20print('%7B0%3A%5E6%7D%20%20%7B1%3A%5E9%7D'.format('gamma'%2C%20'C'))%0A%20%20%20%20for%20_g%20in%20gamma_1%5B0%3A4%5D%3A%0A%20%20%20%20%20%20%20%20a_2%20%3D%20b%20%2F%20(1%20%2F%20c_1%20%2B%20W_0%20%2F%20(_g%20-%201))%0A%20%20%20%20%20%20%20%20_util_paras%20%3D%20np.asarray(%5Ba_2%2C%20b%2C%20_g%5D)%0A%20%20%20%20%20%20%20%20_input_pars%20%3D%20%5BT%2C%20W_0%2C%20S_coeffs%2C%20theta%2C%20S_v_0%2C%20r%2C%20_util_paras%2C%20q%5D%0A%20%20%20%20%20%20%20%20print('%7B0%3A%5E%205.1f%7D%20%20%7B1%3A%5E9.7f%7D'.format(_g%2C%20Option_Portfolio(_input_pars%2C%20K%2C%20writeLog%3DFalse)))%0A%20%20%20%20_input_pars%20%3D%20%5BT%2C%20W_0%2C%20S_coeffs%2C%20theta%2C%20S_v_0%2C%20r%2C%20c_1%2C%20q%5D%0A%20%20%20%20print('%7B0%3A%5E5%7D%20%20%7B1%3A%5E9.7f%7D'.format('exp'%2C%20Option_Portfolio(_input_pars%2C%20K%2C%20util_type%3D'EXP'%2C%20writeLog%3DFalse)))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20K%2C%0A%20%20%20%20Option_Portfolio%2C%0A%20%20%20%20S_v_0%2C%0A%20%20%20%20T%2C%0A%20%20%20%20W_0%2C%0A%20%20%20%20b%2C%0A%20%20%20%20eps%2C%0A%20%20%20%20gamma_1%2C%0A%20%20%20%20mu%2C%0A%20%20%20%20np%2C%0A%20%20%20%20price_vector_abc%2C%0A%20%20%20%20price_vector_z%2C%0A%20%20%20%20q%2C%0A%20%20%20%20sigma%2C%0A%20%20%20%20theta%2C%0A)%3A%0A%20%20%20%20T_horizon_1%20%3D%209%0A%20%20%20%20dT_1%20%3D%20T_horizon_1%20%2F%20T%0A%20%20%20%20Z%20%3D%20price_vector_z(sigma%2C%20eps%2C%20dT_1%2C%20q)%0A%20%20%20%20S_coeffs_1%20%3D%20np.expand_dims(price_vector_abc(sigma%2C%20eps%2C%20dT_1%2C%20q%2C%20mu%2C%20Z)%2C%20axis%3D1)%0A%20%20%20%20r_1%20%3D%201.06%20**%20dT_1%20-%201%0A%20%20%20%20c_2%20%3D%200.2%0A%20%20%20%20print('ARA%20%3D%200.2%20%3B%20Time%20Horizon%20%3D%209%20years')%0A%20%20%20%20print('%7B0%3A%5E6%7D%20%20%7B1%3A%5E9%7D'.format('gamma'%2C%20'C'))%0A%20%20%20%20for%20_g%20in%20gamma_1%3A%0A%20%20%20%20%20%20%20%20a_3%20%3D%20b%20%2F%20(1%20%2F%20c_2%20%2B%20W_0%20%2F%20(_g%20-%201))%0A%20%20%20%20%20%20%20%20_util_paras%20%3D%20np.asarray(%5Ba_3%2C%20b%2C%20_g%5D)%0A%20%20%20%20%20%20%20%20_input_pars%20%3D%20%5BT%2C%20W_0%2C%20S_coeffs_1%2C%20theta%2C%20S_v_0%2C%20r_1%2C%20_util_paras%2C%20q%5D%0A%20%20%20%20%20%20%20%20print('%7B0%3A%5E%205.1f%7D%20%20%7B1%3A%5E9.7f%7D'.format(_g%2C%20Option_Portfolio(_input_pars%2C%20K%2C%20writeLog%3DFalse)))%0A%20%20%20%20_input_pars%20%3D%20%5BT%2C%20W_0%2C%20S_coeffs_1%2C%20theta%2C%20S_v_0%2C%20r_1%2C%20c_2%2C%20q%5D%0A%20%20%20%20print('%7B0%3A%5E5%7D%20%20%7B1%3A%5E9.7f%7D'.format('exp'%2C%20Option_Portfolio(_input_pars%2C%20K%2C%20util_type%3D'EXP'%2C%20writeLog%3DFalse)))%0A%20%20%20%20return%20S_coeffs_1%2C%20r_1%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20K%2C%0A%20%20%20%20Option_Portfolio%2C%0A%20%20%20%20S_coeffs_1%2C%0A%20%20%20%20S_v_0%2C%0A%20%20%20%20T%2C%0A%20%20%20%20W_0%2C%0A%20%20%20%20b%2C%0A%20%20%20%20gamma_1%2C%0A%20%20%20%20np%2C%0A%20%20%20%20q%2C%0A%20%20%20%20r_1%2C%0A%20%20%20%20theta%2C%0A)%3A%0A%20%20%20%20c_3%20%3D%201.0%0A%20%20%20%20print('ARA%20%3D%201.0%20%3B%20Time%20Horizon%20%3D%209%20years')%0A%20%20%20%20print('%7B0%3A%5E6%7D%20%20%7B1%3A%5E9%7D'.format('gamma'%2C%20'C'))%0A%20%20%20%20for%20_g%20in%20gamma_1%5B0%3A4%5D%3A%0A%20%20%20%20%20%20%20%20a_4%20%3D%20b%20%2F%20(1%20%2F%20c_3%20%2B%20W_0%20%2F%20(_g%20-%201))%0A%20%20%20%20%20%20%20%20_util_paras%20%3D%20np.asarray(%5Ba_4%2C%20b%2C%20_g%5D)%0A%20%20%20%20%20%20%20%20_input_pars%20%3D%20%5BT%2C%20W_0%2C%20S_coeffs_1%2C%20theta%2C%20S_v_0%2C%20r_1%2C%20_util_paras%2C%20q%5D%0A%20%20%20%20%20%20%20%20print('%7B0%3A%5E%205.1f%7D%20%20%7B1%3A%5E9.7f%7D'.format(_g%2C%20Option_Portfolio(_input_pars%2C%20K%2C%20writeLog%3DFalse)))%0A%20%20%20%20_input_pars%20%3D%20%5BT%2C%20W_0%2C%20S_coeffs_1%2C%20theta%2C%20S_v_0%2C%20r_1%2C%20c_3%2C%20q%5D%0A%20%20%20%20print('%7B0%3A%5E5%7D%20%20%7B1%3A%5E9.7f%7D'.format('exp'%2C%20Option_Portfolio(_input_pars%2C%20K%2C%20util_type%3D'EXP'%2C%20writeLog%3DFalse)))%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%3Cb%3E(b.)%20Dependency%20of%20the%20reservation%20purchase%20price%20on%20the%20initial%20level%20of%20Relative%20Risk%20Aversion%2C%20%24RRA(W_0)%24%3C%2Fb%3E%20(Consider%20Table%204%2C%20%3Ca%20href%3D%22https%3A%2F%2Fwww.sciencedirect.com%2Fscience%2Farticle%2Fpii%2FS0168927498001044%22%3EAndersen%20et.%20al.%3C%2Fa%3E)%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20K%2C%0A%20%20%20%20Option_Portfolio%2C%0A%20%20%20%20S_v_0%2C%0A%20%20%20%20eps%2C%0A%20%20%20%20mu%2C%0A%20%20%20%20np%2C%0A%20%20%20%20price_vector_abc%2C%0A%20%20%20%20price_vector_z%2C%0A%20%20%20%20q%2C%0A%20%20%20%20sigma%2C%0A%20%20%20%20theta%2C%0A)%3A%0A%20%20%20%20T_1%20%3D%205%0A%20%20%20%20T_horizon_2%20%3D%201%20%2F%204%0A%20%20%20%20dT_2%20%3D%20T_horizon_2%20%2F%20T_1%0A%20%20%20%20r_2%20%3D%201.06%20**%20dT_2%20-%201%0A%20%20%20%20W_0_1%20%3D%20%5B1.0%2C%204.0%2C%208.0%5D%0A%20%20%20%20gamma_2%20%3D%20-1.0%0A%20%20%20%20b_1%20%3D%201%0A%20%20%20%20c_4%20%3D%200.2%0A%20%20%20%20Z%20%3D%20price_vector_z(sigma%2C%20eps%2C%20dT_2%2C%20q)%0A%20%20%20%20S_coeffs_2%20%3D%20np.expand_dims(price_vector_abc(sigma%2C%20eps%2C%20dT_2%2C%20q%2C%20mu%2C%20Z)%2C%20axis%3D1)%0A%20%20%20%20print('ARA%20%3D%200.2%20%3B%20Time%20Horizon%20%3D%201%2F4%20year')%0A%20%20%20%20print('%7B0%3A%5E5%7D%20%20%7B1%3A%5E5%7D%20%20%7B2%3A%5E9%7D'.format('W_0'%2C%20'RRA'%2C%20'C'))%0A%20%20%20%20for%20_w0%20in%20W_0_1%3A%0A%20%20%20%20%20%20%20%20a_5%20%3D%20b_1%20%2F%20(1%20%2F%20c_4%20%2B%20_w0%20%2F%20(gamma_2%20-%201))%0A%20%20%20%20%20%20%20%20_util_paras%20%3D%20np.asarray(%5Ba_5%2C%20b_1%2C%20gamma_2%5D)%0A%20%20%20%20%20%20%20%20_input_pars%20%3D%20%5BT_1%2C%20_w0%2C%20S_coeffs_2%2C%20theta%2C%20S_v_0%2C%20r_2%2C%20_util_paras%2C%20q%5D%0A%20%20%20%20%20%20%20%20print('%7B0%3A%5E5.0f%7D%20%20%7B1%3A%5E5.1f%7D%20%20%7B2%3A%5E9.7f%7D'.format(_w0%2C%20c_4%20*%20_w0%2C%20Option_Portfolio(_input_pars%2C%20K%2C%20writeLog%3DFalse)))%0A%20%20%20%20_input_pars%20%3D%20%5BT_1%2C%201.0%2C%20S_coeffs_2%2C%20theta%2C%20S_v_0%2C%20r_2%2C%20c_4%2C%20q%5D%0A%20%20%20%20print('%7B0%3A%5E5%7D%20%20%7B1%3A%5E5%7D%20%20%7B2%3A%5E9.7f%7D'.format('exp'%2C%20''%2C%20Option_Portfolio(_input_pars%2C%20K%2C%20util_type%3D'EXP'%2C%20writeLog%3DFalse)))%0A%20%20%20%20return%20T_1%2C%20W_0_1%2C%20b_1%2C%20c_4%2C%20gamma_2%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20K%2C%0A%20%20%20%20Option_Portfolio%2C%0A%20%20%20%20S_v_0%2C%0A%20%20%20%20T_1%2C%0A%20%20%20%20W_0_1%2C%0A%20%20%20%20b_1%2C%0A%20%20%20%20c_4%2C%0A%20%20%20%20eps%2C%0A%20%20%20%20gamma_2%2C%0A%20%20%20%20mu%2C%0A%20%20%20%20np%2C%0A%20%20%20%20price_vector_abc%2C%0A%20%20%20%20price_vector_z%2C%0A%20%20%20%20q%2C%0A%20%20%20%20sigma%2C%0A%20%20%20%20theta%2C%0A)%3A%0A%20%20%20%20T_horizon_3%20%3D%209%0A%20%20%20%20dT_3%20%3D%20T_horizon_3%20%2F%20T_1%0A%20%20%20%20r_3%20%3D%201.06%20**%20dT_3%20-%201%0A%20%20%20%20Z%20%3D%20price_vector_z(sigma%2C%20eps%2C%20dT_3%2C%20q)%0A%20%20%20%20S_coeffs_3%20%3D%20np.expand_dims(price_vector_abc(sigma%2C%20eps%2C%20dT_3%2C%20q%2C%20mu%2C%20Z)%2C%20axis%3D1)%0A%20%20%20%20print('ARA%20%3D%200.2%20%3B%20Time%20Horizon%20%3D%209%20years')%0A%20%20%20%20print('%7B0%3A%5E5%7D%20%20%7B1%3A%5E5%7D%20%20%7B2%3A%5E9%7D'.format('W_0'%2C%20'RRA'%2C%20'C'))%0A%20%20%20%20for%20_w0%20in%20W_0_1%3A%0A%20%20%20%20%20%20%20%20a_6%20%3D%20b_1%20%2F%20(1%20%2F%20c_4%20%2B%20_w0%20%2F%20(gamma_2%20-%201))%0A%20%20%20%20%20%20%20%20_util_paras%20%3D%20np.asarray(%5Ba_6%2C%20b_1%2C%20gamma_2%5D)%0A%20%20%20%20%20%20%20%20_input_pars%20%3D%20%5BT_1%2C%20_w0%2C%20S_coeffs_3%2C%20theta%2C%20S_v_0%2C%20r_3%2C%20_util_paras%2C%20q%5D%0A%20%20%20%20%20%20%20%20print('%7B0%3A%5E5.0f%7D%20%20%7B1%3A%5E5.1f%7D%20%20%7B2%3A%5E9.7f%7D'.format(_w0%2C%20c_4%20*%20_w0%2C%20Option_Portfolio(_input_pars%2C%20K%2C%20writeLog%3DFalse)))%0A%20%20%20%20_input_pars%20%3D%20%5BT_1%2C%201.0%2C%20S_coeffs_3%2C%20theta%2C%20S_v_0%2C%20r_3%2C%20c_4%2C%20q%5D%0A%20%20%20%20print('%7B0%3A%5E5%7D%20%20%7B1%3A%5E5%7D%20%20%7B2%3A%5E9.7f%7D'.format('exp'%2C%20''%2C%20Option_Portfolio(_input_pars%2C%20K%2C%20util_type%3D'EXP'%2C%20writeLog%3DFalse)))%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%3Cb%3E(c.)%20Convergence%20of%20the%20reservation%20purchase%20price.%3C%2Fb%3E%20(Consider%20Table%205%2C%20%3Ca%20href%3D%22https%3A%2F%2Fwww.sciencedirect.com%2Fscience%2Farticle%2Fpii%2FS0168927498001044%22%3EAndersen%20et.%20al.%3C%2Fa%3E)%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20K%2C%0A%20%20%20%20Option_Portfolio%2C%0A%20%20%20%20S_v_0%2C%0A%20%20%20%20eps%2C%0A%20%20%20%20mu%2C%0A%20%20%20%20np%2C%0A%20%20%20%20price_vector_abc%2C%0A%20%20%20%20price_vector_z%2C%0A%20%20%20%20q%2C%0A%20%20%20%20sigma%2C%0A%20%20%20%20theta%2C%0A)%3A%0A%20%20%20%20T_horizon_4%20%3D%201%20%2F%204%0A%20%20%20%20W_0_2%20%3D%201.0%0A%20%20%20%20gamma_3%20%3D%200.3%0A%20%20%20%20b_2%20%3D%200.0%0A%20%20%20%20c_5%20%3D%200.7%0A%20%20%20%20a_7%20%3D%201%20-%20gamma_3%0A%20%20%20%20_util_paras%20%3D%20np.asarray(%5Ba_7%2C%20b_2%2C%20gamma_3%5D)%0A%20%20%20%20C_trio%20%3D%20%5B%5D%0A%20%20%20%20print('%7B0%3A%5E3%7D%20%20%7B1%3A12%7D%20%20%7B2%3A12%7D%20%20%7B3%3A%5E12%7D'.format('%20'%2C%20'-exp(-0.7W)'%2C%20'(W%5E0.3)%2F0.3'%2C%20'%20'))%0A%20%20%20%20print('%7B0%3A%5E3%7D%20%20%7B1%3A%5E12%7D%20%20%7B2%3A%5E12%7D%20%20%7B3%3A%5E12%7D'.format('T'%2C%20'C_exp'%2C%20'C_pow'%2C%20'CRR'))%0A%20%20%20%20for%20T_2%20in%20np.arange(1%2C%2012)%3A%0A%20%20%20%20%20%20%20%20dT_4%20%3D%20T_horizon_4%20%2F%20T_2%0A%20%20%20%20%20%20%20%20r_4%20%3D%201.06%20**%20dT_4%20-%201%0A%20%20%20%20%20%20%20%20Z%20%3D%20price_vector_z(sigma%2C%20eps%2C%20dT_4%2C%20q)%0A%20%20%20%20%20%20%20%20S_coeffs_4%20%3D%20np.expand_dims(price_vector_abc(sigma%2C%20eps%2C%20dT_4%2C%20q%2C%20mu%2C%20Z)%2C%20axis%3D1)%0A%20%20%20%20%20%20%20%20_input_pars%20%3D%20%5BT_2%2C%20W_0_2%2C%20S_coeffs_4%2C%20theta%2C%20S_v_0%2C%20r_4%2C%20_util_paras%2C%20q%5D%0A%20%20%20%20%20%20%20%20_C_pow%20%3D%20Option_Portfolio(_input_pars%2C%20K%2C%20writeLog%3DFalse)%0A%20%20%20%20%20%20%20%20_input_pars%20%3D%20%5BT_2%2C%20W_0_2%2C%20S_coeffs_4%2C%20%5B0.0%5D%2C%20S_v_0%2C%20r_4%2C%20_util_paras%2C%20q%5D%0A%20%20%20%20%20%20%20%20CRR%20%3D%20Option_Portfolio(_input_pars%2C%20K%2C%20writeLog%3DFalse)%0A%20%20%20%20%20%20%20%20_input_pars%20%3D%20%5BT_2%2C%20W_0_2%2C%20S_coeffs_4%2C%20theta%2C%20S_v_0%2C%20r_4%2C%20c_5%2C%20q%5D%0A%20%20%20%20%20%20%20%20_C_exp%20%3D%20Option_Portfolio(_input_pars%2C%20K%2C%20util_type%3D'EXP'%2C%20writeLog%3DFalse)%0A%20%20%20%20%20%20%20%20print('%7B0%3A%5E3d%7D%20%20%7B1%3A%5E12.10f%7D%20%20%7B2%3A%5E12.10f%7D%20%20%7B3%3A%5E12.10f%7D'.format(T_2%2C%20_C_exp%2C%20_C_pow%2C%20CRR))%0A%20%20%20%20%20%20%20%20C_trio.append(%5B_C_exp%2C%20_C_pow%2C%20CRR%5D)%0A%20%20%20%20return%20T_horizon_4%2C%20W_0_2%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%3Cb%3E(d.)%20Reservation%20purchase%20price%20dependence%20on%20absolute%20risk%20aversion%20(Exponential%20utility).%3C%2Fb%3E%20(Consider%20Table%206%2C%20%3Ca%20href%3D%22https%3A%2F%2Fwww.sciencedirect.com%2Fscience%2Farticle%2Fpii%2FS0168927498001044%22%3EAndersen%20et.%20al.%3C%2Fa%3E)%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20K%2C%0A%20%20%20%20Option_Portfolio%2C%0A%20%20%20%20S_v_0%2C%0A%20%20%20%20T_horizon_4%2C%0A%20%20%20%20W_0_2%2C%0A%20%20%20%20eps%2C%0A%20%20%20%20mu%2C%0A%20%20%20%20np%2C%0A%20%20%20%20price_vector_abc%2C%0A%20%20%20%20price_vector_z%2C%0A%20%20%20%20q%2C%0A%20%20%20%20sigma%2C%0A)%3A%0A%20%20%20%20T_3%20%3D%209%0A%20%20%20%20dT_5%20%3D%20T_horizon_4%20%2F%20T_3%0A%20%20%20%20theta_1%20%3D%20%5B0.005%5D%0A%20%20%20%20r_5%20%3D%201.06%20**%20dT_5%20-%201%0A%20%20%20%20c_6%20%3D%20%5B0.1%2C%200.2%2C%200.4%2C%200.8%2C%201.0%2C%202.0%2C%204.0%5D%0A%20%20%20%20Z%20%3D%20price_vector_z(sigma%2C%20eps%2C%20dT_5%2C%20q)%0A%20%20%20%20S_coeffs_5%20%3D%20np.expand_dims(price_vector_abc(sigma%2C%20eps%2C%20dT_5%2C%20q%2C%20mu%2C%20Z)%2C%20axis%3D1)%0A%20%20%20%20print('%7B0%3A%5E8%7D%20%20%7B1%3A%5E12%7D'.format('ARA(W_0)'%2C%20'C%5BARA(W_0)%5D'))%0A%20%20%20%20C_ara%20%3D%20%5B%5D%0A%20%20%20%20for%20kappa%20in%20c_6%3A%0A%20%20%20%20%20%20%20%20_input_pars%20%3D%20%5BT_3%2C%20W_0_2%2C%20S_coeffs_5%2C%20theta_1%2C%20S_v_0%2C%20r_5%2C%20kappa%2C%20q%5D%0A%20%20%20%20%20%20%20%20_C_exp%20%3D%20Option_Portfolio(_input_pars%2C%20K%2C%20util_type%3D'EXP'%2C%20writeLog%3DFalse)%0A%20%20%20%20%20%20%20%20print('%7B0%3A%5E8.2f%7D%20%20%7B1%3A%5E12.10f%7D'.format(kappa%2C%20_C_exp))%0A%20%20%20%20%20%20%20%20C_ara.append(_C_exp)%0A%20%20%20%20return%20S_coeffs_5%2C%20T_3%2C%20dT_5%2C%20r_5%2C%20theta_1%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%3Cb%3E(e.)%20Reservation%20purchase%20price%20dependence%20on%20absolute%20risk%20aversion%20(Power%20utility).%3C%2Fb%3E%20(Consider%20Table%207%2C%20%3Ca%20href%3D%22https%3A%2F%2Fwww.sciencedirect.com%2Fscience%2Farticle%2Fpii%2FS0168927498001044%22%3EAndersen%20et.%20al.%3C%2Fa%3E)%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(K%2C%20Option_Portfolio%2C%20S_coeffs_5%2C%20S_v_0%2C%20T_3%2C%20W_0_2%2C%20np%2C%20q%2C%20r_5%2C%20theta_1)%3A%0A%20%20%20%20_eta%20%3D%20np.linspace(0.1%2C%200.9%2C%209)%0A%20%20%20%20a_8%20%3D%201%0A%20%20%20%20b_3%20%3D%200.0%0A%20%20%20%20print('%7B0%3A%5E5%7D%20%20%7B1%3A%5E12%7D'.format('eta'%2C%20'C%5BARA(W_0)%5D'))%0A%20%20%20%20C_eta%20%3D%20%5B%5D%0A%20%20%20%20for%20n%20in%20_eta%3A%0A%20%20%20%20%20%20%20%20gamma_4%20%3D%201%20-%20n%0A%20%20%20%20%20%20%20%20_util_paras%20%3D%20np.asarray(%5Ba_8%2C%20b_3%2C%20gamma_4%5D)%0A%20%20%20%20%20%20%20%20_input_pars%20%3D%20%5BT_3%2C%20W_0_2%2C%20S_coeffs_5%2C%20theta_1%2C%20S_v_0%2C%20r_5%2C%20_util_paras%2C%20q%5D%0A%20%20%20%20%20%20%20%20_C_pow%20%3D%20Option_Portfolio(_input_pars%2C%20K%2C%20writeLog%3DFalse)%0A%20%20%20%20%20%20%20%20print('%7B0%3A%5E5.2f%7D%20%20%7B1%3A%5E12.10f%7D'.format(n%2C%20_C_pow))%0A%20%20%20%20%20%20%20%20C_eta.append(_C_pow)%0A%20%20%20%20return%20a_8%2C%20b_3%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%3Cb%3E(f.)%20Reservation%20purchase%20price%20dependence%20on%20initial%20wealth%20(Power%20utility%20with%20%24%5Ceta%20%3D%200.7%24).%3C%2Fb%3E%20(Consider%20Table%208%2C%20%3Ca%20href%3D%22https%3A%2F%2Fwww.sciencedirect.com%2Fscience%2Farticle%2Fpii%2FS0168927498001044%22%3EAndersen%20et.%20al.%3C%2Fa%3E)%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20K%2C%0A%20%20%20%20Option_Portfolio%2C%0A%20%20%20%20S_coeffs_5%2C%0A%20%20%20%20S_v_0%2C%0A%20%20%20%20T_3%2C%0A%20%20%20%20a_8%2C%0A%20%20%20%20b_3%2C%0A%20%20%20%20np%2C%0A%20%20%20%20q%2C%0A%20%20%20%20r_5%2C%0A%20%20%20%20theta_1%2C%0A)%3A%0A%20%20%20%20_eta%20%3D%200.7%0A%20%20%20%20W_0_3%20%3D%20%5B0.25%2C%200.5%2C%201.0%2C%202.0%2C%204.0%2C%208.0%5D%0A%20%20%20%20gamma_5%20%3D%201%20-%20_eta%0A%20%20%20%20_util_paras%20%3D%20np.asarray(%5Ba_8%2C%20b_3%2C%20gamma_5%5D)%0A%20%20%20%20print('%7B0%3A%5E5%7D%20%20%7B1%3A%5E12%7D'.format('W_0'%2C%20'C_pow(W_0)'))%0A%20%20%20%20C_w0%20%3D%20%5B%5D%0A%20%20%20%20for%20_w0%20in%20W_0_3%3A%0A%20%20%20%20%20%20%20%20_input_pars%20%3D%20%5BT_3%2C%20_w0%2C%20S_coeffs_5%2C%20theta_1%2C%20S_v_0%2C%20r_5%2C%20_util_paras%2C%20q%5D%0A%20%20%20%20%20%20%20%20_C_pow%20%3D%20Option_Portfolio(_input_pars%2C%20K%2C%20writeLog%3DFalse)%0A%20%20%20%20%20%20%20%20print('%7B0%3A%5E5.2f%7D%20%20%7B1%3A%5E12.10f%7D'.format(_w0%2C%20_C_pow))%0A%20%20%20%20%20%20%20%20C_w0.append(_C_pow)%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%23%23%23%20The%20effect%20of%20diversification%20opportunities%20on%20the%20reservation%20purchase%20price.%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%20The%20model%20presented%20above%20is%20fairly%20general%2C%20and%20therefore%20we%20can%20easily%20extend%20its%20application%20to%20the%20case%20where%20trade%20takes%20place%20in%20multiple%20securities.%20For%20illustration%2C%20we%20present%20the%20case%20where%20there%20are%20two%20risky%20securities%2C%20following%20%3Ca%20href%3D%22https%3A%2F%2Fwww.sciencedirect.com%2Fscience%2Farticle%2Fpii%2FS0168927498001044%22%3EAndersen%20et.%20al.%3C%2Fa%3E.%20For%20this%20example%2C%20we%20have%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Csigma%5E%7BT%7D%20%3D%20%5Cbegin%7Bpmatrix%7D%0A%20%20%20%20%5Csigma_%7B11%7D%5C%2C%20%2C%5C%2C%5Csigma_%7B21%7D%20%5C%5C%0A%20%20%20%20%5Csigma_%7B12%7D%5C%2C%20%2C%5C%2C%5Csigma_%7B22%7D%20%5C%5C%0A%20%20%20%20%5Cend%7Bpmatrix%7D%20%3D%20%5Cbegin%7Bpmatrix%7D%0A%20%20%20%20%5Csigma_%7B11%7D%5C%2C%20%2C%5C%2C%200.2%5Crho%5C%5C%0A%20%20%20%200.0%5C%2C%20%2C%20%5C%2C%20%5Csqrt%7B(0.2)%5E2%20-%20%5Csigma_%7B21%7D%5E2%7D%20%5C%5C%0A%20%20%20%20%5Cend%7Bpmatrix%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20where%20%24%5Crho%24%20is%20the%20correlation%20between%20logarithms%20of%20the%20two%20securities.%20The%20%24%5Cepsilon%24%20matrix%20is%20given%20by%2C%20%0A%0A%20%20%20%20%24%24%5Cepsilon%20%3D%20%5Cbegin%7Bpmatrix%7D%0A%20%20%20%20%5Cepsilon_1%20(%5Comega_1)%2C%5Cepsilon_2%20(%5Comega_1)%20%5C%5C%0A%20%20%20%20%5Cepsilon_1%20(%5Comega_2)%2C%5Cepsilon_2%20(%5Comega_2)%20%5C%5C%0A%20%20%20%20%5Cepsilon_1%20(%5Comega_3)%2C%5Cepsilon_2%20(%5Comega_3)%0A%20%20%20%20%5Cend%7Bpmatrix%7D%20%3D%20%5Cbegin%7Bpmatrix%7D%0A%20%20%20%20%5Csqrt%7B2%7D%5C%2C%5C%2C%2C%5C%2C%5C%2C0%20%5C%5C%0A%20%20%20%20-1%2F%5Csqrt%7B2%7D%2C%5Csqrt%7B3%2F2%7D%20%5C%5C%0A%20%20%20%20-1%2F%5Csqrt%7B2%7D%2C%5Csqrt%7B3%2F2%7D%0A%20%20%20%20%5Cend%7Bpmatrix%7D%0A%20%20%20%20%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(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%20Moreover%2C%20we%20will%20consider%20different%20values%20for%20the%20transaction%20costs.%20There%20are%20three%20situations%20considered%20below%3A%20completely%20frictionless%20market%2C%20friction%20in%20one%20security%2C%20friction%20in%20both%20securities.%0A%0A%20%20%20%20%3Cb%3ENote%3C%2Fb%3E%3A%20In%20the%20code%2C%20we%20use%20the%20transpose%20of%20the%20sigma%20matrix%2C%20hence%20the%20shapes%20of%20the%20arrays%20that%20represent%20%24%5Csigma%24%20and%20%24%5Cepsilon%24%20must%20be%20maintained%20similar%20to%20what%20is%20shown%20in%20the%20code%20below.%0A%20%20%20%20%22%22%22%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%3Cb%3E(g.)%20Reservation%20purchase%20price%20of%20a%20call%20option%20for%20T%3D9%20as%20a%20function%20of%20%24%5Crho%24%20and%20%24%5Ctheta_i%24%20in%20the%20presence%20of%20two%20risky%20securities.%3C%2Fb%3E%20(Consider%20Table%2010%2C%20%3Ca%20href%3D%22https%3A%2F%2Fwww.sciencedirect.com%2Fscience%2Farticle%2Fpii%2FS0168927498001044%22%3EAndersen%20et.%20al.%3C%2Fa%3E)%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20Option_Portfolio%2C%0A%20%20%20%20T_3%2C%0A%20%20%20%20dT_5%2C%0A%20%20%20%20np%2C%0A%20%20%20%20price_vector_abc%2C%0A%20%20%20%20price_vector_z%2C%0A%20%20%20%20q%2C%0A%20%20%20%20r_5%2C%0A)%3A%0A%20%20%20%20W_0_4%20%3D%201.0%0A%20%20%20%20gamma_6%20%3D%200.3%0A%20%20%20%20b_4%20%3D%201%0A%20%20%20%20c_7%20%3D%200.2%0A%20%20%20%20a_9%20%3D%20b_4%20%2F%20(1%20%2F%20c_7%20%2B%20W_0_4%20%2F%20(gamma_6%20-%201))%0A%20%20%20%20_util_paras%20%3D%20np.asarray(%5Ba_9%2C%20b_4%2C%20gamma_6%5D)%0A%20%20%20%20K_1%20%3D%201%0A%20%20%20%20sig11%20%3D%200.2%0A%20%20%20%20sig12%20%3D%200.0%0A%20%20%20%20eps_1%20%3D%20np.asarray(%5B%5Bnp.sqrt(2)%2C%200%5D%2C%20%5B-1%20%2F%20np.sqrt(2)%2C%20np.sqrt(3%20%2F%202)%5D%2C%20%5B-1%20%2F%20np.sqrt(2)%2C%20-np.sqrt(3%20%2F%202)%5D%5D)%0A%20%20%20%20S_v_0_1%20%3D%20%5B1.0%2C%201.0%5D%0A%20%20%20%20mu_1%20%3D%20np.asarray(%5B0.15%2C%200.15%5D)%0A%20%20%20%20rho%20%3D%20%5B1%2C%200.5%2C%200.0%2C%20-0.5%2C%20-0.9%5D%0A%20%20%20%20theta_2%20%3D%20%5B0.0%2C%200.0%5D%0A%20%20%20%20print('theta_1%20%3D%20%7B0%3A5.3f%7D%20%3B%20theta_2%20%3D%20%7B1%3A5.3f%7D'.format(theta_2%5B0%5D%2C%20theta_2%5B1%5D))%0A%20%20%20%20print('%7B0%3A%5E5%7D%20%20%7B1%3A%5E12%7D'.format('rho'%2C%20'C(S1%2CS2)'))%0A%20%20%20%20for%20_p%20in%20rho%3A%0A%20%20%20%20%20%20%20%20_sig21%20%3D%20_p%20*%200.2%0A%20%20%20%20%20%20%20%20sigma_1%20%3D%20np.asarray(%5B%5Bsig11%2C%20_sig21%5D%2C%20%5Bsig12%2C%20np.sqrt(0.2%20**%202%20-%20_sig21%20**%202)%5D%5D)%0A%20%20%20%20%20%20%20%20Z%20%3D%20price_vector_z(sigma_1%2C%20eps_1%2C%20dT_5%2C%20q)%0A%20%20%20%20%20%20%20%20S_coeffs_6%20%3D%20price_vector_abc(sigma_1%2C%20eps_1%2C%20dT_5%2C%20q%2C%20mu_1%2C%20Z)%0A%20%20%20%20%20%20%20%20_input_pars%20%3D%20%5BT_3%2C%20W_0_4%2C%20S_coeffs_6%2C%20theta_2%2C%20S_v_0_1%2C%20r_5%2C%20c_7%2C%20q%5D%0A%20%20%20%20%20%20%20%20print('%7B0%3A%5E%204.1f%7D%20%20%7B1%3A%5E12.10f%7D'.format(_p%2C%20Option_Portfolio(_input_pars%2C%20K_1%2C%20util_type%3D'EXP'%2C%20writeLog%3DFalse)))%0A%20%20%20%20return%20K_1%2C%20S_v_0_1%2C%20W_0_4%2C%20c_7%2C%20eps_1%2C%20mu_1%2C%20rho%2C%20sig11%2C%20sig12%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20K_1%2C%0A%20%20%20%20Option_Portfolio%2C%0A%20%20%20%20S_v_0_1%2C%0A%20%20%20%20T_3%2C%0A%20%20%20%20W_0_4%2C%0A%20%20%20%20c_7%2C%0A%20%20%20%20dT_5%2C%0A%20%20%20%20eps_1%2C%0A%20%20%20%20mu_1%2C%0A%20%20%20%20np%2C%0A%20%20%20%20price_vector_abc%2C%0A%20%20%20%20price_vector_z%2C%0A%20%20%20%20q%2C%0A%20%20%20%20r_5%2C%0A%20%20%20%20rho%2C%0A%20%20%20%20sig11%2C%0A%20%20%20%20sig12%2C%0A)%3A%0A%20%20%20%20theta_3%20%3D%20%5B0.005%2C%200.0%5D%0A%20%20%20%20print('theta_1%20%3D%20%7B0%3A5.3f%7D%20%3B%20theta_2%20%3D%20%7B1%3A5.3f%7D'.format(theta_3%5B0%5D%2C%20theta_3%5B1%5D))%0A%20%20%20%20print('%7B0%3A%5E5%7D%20%20%7B1%3A%5E12%7D'.format('rho'%2C%20'C(S1%2CS2)'))%0A%20%20%20%20for%20_p%20in%20rho%3A%0A%20%20%20%20%20%20%20%20_sig21%20%3D%20_p%20*%200.2%0A%20%20%20%20%20%20%20%20sigma_2%20%3D%20np.asarray(%5B%5Bsig11%2C%20_sig21%5D%2C%20%5Bsig12%2C%20np.sqrt(0.2%20**%202%20-%20_sig21%20**%202)%5D%5D)%0A%20%20%20%20%20%20%20%20Z%20%3D%20price_vector_z(sigma_2%2C%20eps_1%2C%20dT_5%2C%20q)%0A%20%20%20%20%20%20%20%20S_coeffs_7%20%3D%20price_vector_abc(sigma_2%2C%20eps_1%2C%20dT_5%2C%20q%2C%20mu_1%2C%20Z)%0A%20%20%20%20%20%20%20%20_input_pars%20%3D%20%5BT_3%2C%20W_0_4%2C%20S_coeffs_7%2C%20theta_3%2C%20S_v_0_1%2C%20r_5%2C%20c_7%2C%20q%5D%0A%20%20%20%20%20%20%20%20print('%7B0%3A%5E%204.2f%7D%20%20%7B1%3A%5E12.10f%7D'.format(_p%2C%20Option_Portfolio(_input_pars%2C%20K_1%2C%20util_type%3D'EXP'%2C%20writeLog%3DFalse)))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20K_1%2C%0A%20%20%20%20Option_Portfolio%2C%0A%20%20%20%20S_v_0_1%2C%0A%20%20%20%20T_3%2C%0A%20%20%20%20W_0_4%2C%0A%20%20%20%20c_7%2C%0A%20%20%20%20dT_5%2C%0A%20%20%20%20eps_1%2C%0A%20%20%20%20mu_1%2C%0A%20%20%20%20np%2C%0A%20%20%20%20price_vector_abc%2C%0A%20%20%20%20price_vector_z%2C%0A%20%20%20%20q%2C%0A%20%20%20%20r_5%2C%0A%20%20%20%20rho%2C%0A%20%20%20%20sig11%2C%0A%20%20%20%20sig12%2C%0A)%3A%0A%20%20%20%20theta_4%20%3D%20%5B0.005%2C%200.005%5D%0A%20%20%20%20print('theta_1%20%3D%20%7B0%3A5.3f%7D%20%3B%20theta_2%20%3D%20%7B1%3A5.3f%7D'.format(theta_4%5B0%5D%2C%20theta_4%5B1%5D))%0A%20%20%20%20print('%7B0%3A%5E5%7D%20%20%7B1%3A%5E12%7D'.format('rho'%2C%20'C(S1%2CS2)'))%0A%20%20%20%20for%20_p%20in%20rho%3A%0A%20%20%20%20%20%20%20%20_sig21%20%3D%20_p%20*%200.2%0A%20%20%20%20%20%20%20%20sigma_3%20%3D%20np.asarray(%5B%5Bsig11%2C%20_sig21%5D%2C%20%5Bsig12%2C%20np.sqrt(0.2%20**%202%20-%20_sig21%20**%202)%5D%5D)%0A%20%20%20%20%20%20%20%20Z%20%3D%20price_vector_z(sigma_3%2C%20eps_1%2C%20dT_5%2C%20q)%0A%20%20%20%20%20%20%20%20S_coeffs_8%20%3D%20price_vector_abc(sigma_3%2C%20eps_1%2C%20dT_5%2C%20q%2C%20mu_1%2C%20Z)%0A%20%20%20%20%20%20%20%20_input_pars%20%3D%20%5BT_3%2C%20W_0_4%2C%20S_coeffs_8%2C%20theta_4%2C%20S_v_0_1%2C%20r_5%2C%20c_7%2C%20q%5D%0A%20%20%20%20%20%20%20%20print('%7B0%3A%5E%204.2f%7D%20%20%7B1%3A%5E12.10f%7D'.format(_p%2C%20Option_Portfolio(_input_pars%2C%20K_1%2C%20util_type%3D'EXP'%2C%20writeLog%3DFalse)))%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%3Cb%3E(h.)%20Reservation%20purchase%20price%20of%20a%20call%20option%20for%20T%3D9%2C%20as%20a%20function%20of%20%24%5Ctheta_i%24%2C%20in%20the%20case%20of%20two%20risky%20securities%3B%20%24%5Crho%20%3D%20-0.9%24.%3C%2Fb%3E%20(Consider%20Table%2011%2C%20%3Ca%20href%3D%22https%3A%2F%2Fwww.sciencedirect.com%2Fscience%2Farticle%2Fpii%2FS0168927498001044%22%3EAndersen%20et.%20al.%3C%2Fa%3E)%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20K_1%2C%0A%20%20%20%20Option_Portfolio%2C%0A%20%20%20%20S_v_0_1%2C%0A%20%20%20%20T_3%2C%0A%20%20%20%20W_0_4%2C%0A%20%20%20%20c_7%2C%0A%20%20%20%20dT_5%2C%0A%20%20%20%20eps_1%2C%0A%20%20%20%20mu_1%2C%0A%20%20%20%20np%2C%0A%20%20%20%20price_vector_abc%2C%0A%20%20%20%20price_vector_z%2C%0A%20%20%20%20q%2C%0A%20%20%20%20r_5%2C%0A%20%20%20%20sig11%2C%0A%20%20%20%20sig12%2C%0A)%3A%0A%20%20%20%20rho_1%20%3D%20-0.9%0A%20%20%20%20_sig21%20%3D%20rho_1%20*%200.2%0A%20%20%20%20sigma_4%20%3D%20np.asarray(%5B%5Bsig11%2C%20_sig21%5D%2C%20%5Bsig12%2C%20np.sqrt(0.2%20**%202%20-%20_sig21%20**%202)%5D%5D)%0A%20%20%20%20Z%20%3D%20price_vector_z(sigma_4%2C%20eps_1%2C%20dT_5%2C%20q)%0A%20%20%20%20S_coeffs_9%20%3D%20price_vector_abc(sigma_4%2C%20eps_1%2C%20dT_5%2C%20q%2C%20mu_1%2C%20Z)%0A%20%20%20%20theta_list%20%3D%20%5B0.0008%2C%200.0016%2C%200.003%2C%200.006%2C%200.01%2C%200.02%2C%200.05%2C%200.1%5D%0A%20%20%20%20print('%7B0%3A%5E5%7D%20%20%7B1%3A%5E12%7D'.format('theta'%2C%20'C(S1%2CS2)'))%0A%20%20%20%20for%20theta_i%20in%20theta_list%3A%0A%20%20%20%20%20%20%20%20theta_5%20%3D%20%5Btheta_i%2C%20theta_i%5D%0A%20%20%20%20%20%20%20%20_input_pars%20%3D%20%5BT_3%2C%20W_0_4%2C%20S_coeffs_9%2C%20theta_5%2C%20S_v_0_1%2C%20r_5%2C%20c_7%2C%20q%5D%0A%20%20%20%20%20%20%20%20print('%7B0%3A%5E5.4f%7D%20%20%7B1%3A%5E12.10f%7D'.format(theta_i%2C%20Option_Portfolio(_input_pars%2C%20K_1%2C%20util_type%3D'EXP'%2C%20writeLog%3DFalse)))%0A%20%20%20%20return%20(sigma_4%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%3Cb%3E(i.)%20Computational%20efficiency%20for%20different%20values%20of%20T%20(time%20periods).%3C%2Fb%3E%20(Consider%20Table%2012%2C%20%3Ca%20href%3D%22https%3A%2F%2Fwww.sciencedirect.com%2Fscience%2Farticle%2Fpii%2FS0168927498001044%22%3EAndersen%20et.%20al.%3C%2Fa%3E)%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(r%22%22%22The%20columns%20of%20the%20output%20table%20in%20the%20following%20cell%20denote%3A%20T%20(time%20periods)%2C%20cons.%20(number%20of%20constraints)%2C%20vars.%20(number%20of%20variables)%2C%20it.%20(number%20of%20iterations%20for%20the%20%3Ci%3Eno-option%3C%2Fi%3E%20model%20as%20well%20as%20the%20%3Ci%3Eoption-price%3C%2Fi%3E%20model)%2C%20time.%20(time%20taken%2C%20in%20seconds%20for%20both%20models).%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20K_1%2C%0A%20%20%20%20OptimizerError%2C%0A%20%20%20%20Option_Portfolio%2C%0A%20%20%20%20S_v_0_1%2C%0A%20%20%20%20SolutionError%2C%0A%20%20%20%20W_0_4%2C%0A%20%20%20%20c_7%2C%0A%20%20%20%20dT_5%2C%0A%20%20%20%20eps_1%2C%0A%20%20%20%20mu_1%2C%0A%20%20%20%20price_vector_abc%2C%0A%20%20%20%20price_vector_z%2C%0A%20%20%20%20q%2C%0A%20%20%20%20sigma_4%2C%0A)%3A%0A%20%20%20%20theta_6%20%3D%20%5B0.005%2C%200.005%5D%0A%20%20%20%20print('%7B0%3A%5E2%7D%20%20%7B1%3A%5E8%7D%20%20%7B2%3A%5E10%7D%20%20%7B3%3A%5E11%7D%20%20%7B4%3A%5E11%7D'.format(''%2C%20''%2C%20''%2C%20'No-option'%2C%20'Option-price'))%0A%20%20%20%20print('%7B0%3A%3E2%7D%20%20%7B1%3A%3E8%7D%20%20%7B2%3A%3E10%7D%20%20%7B3%3A%5E3%7D%20%20%7B4%3A%5E6%7D%20%20%7B5%3A%5E3%7D%20%20%7B6%3A%5E6%7D'.format('T'%2C%20'cons.'%2C%20'vars.'%2C%20'it.'%2C%20'time'%2C%20'it.'%2C%20'time'))%0A%20%20%20%20total_info_arr%20%3D%20%5B%5D%0A%20%20%20%20for%20T_4%20in%20range(1%2C%2010)%3A%0A%20%20%20%20%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20T_horizon_5%20%3D%201%20%2F%204%0A%20%20%20%20%20%20%20%20%20%20%20%20dt%20%3D%20T_horizon_5%20%2F%20T_4%0A%20%20%20%20%20%20%20%20%20%20%20%20r_6%20%3D%201.06%20**%20dT_5%20-%201%0A%20%20%20%20%20%20%20%20%20%20%20%20Z%20%3D%20price_vector_z(sigma_4%2C%20eps_1%2C%20dT_5%2C%20q)%0A%20%20%20%20%20%20%20%20%20%20%20%20S_coeffs_10%20%3D%20price_vector_abc(sigma_4%2C%20eps_1%2C%20dT_5%2C%20q%2C%20mu_1%2C%20Z)%0A%20%20%20%20%20%20%20%20%20%20%20%20_input_pars%20%3D%20%5BT_4%2C%20W_0_4%2C%20S_coeffs_10%2C%20theta_6%2C%20S_v_0_1%2C%20r_6%2C%20c_7%2C%20q%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20call%2C%20n_cons%2C%20n_var%2C%20ut_it%2C%20ut_time%2C%20price_it%2C%20price_time%20%3D%20Option_Portfolio(_input_pars%2C%20K_1%2C%20util_type%3D'EXP'%2C%20writeLog%3DFalse%2C%20solver_info%3DTrue)%0A%20%20%20%20%20%20%20%20%20%20%20%20print('%7B0%3A%3E2d%7D%20%20%7B1%3A%3E8d%7D%20%20%7B2%3A%3E10d%7D%20%20%7B3%3A%3E3d%7D%20%20%7B4%3A%3E6.3f%7D%20%20%7B5%3A%3E3d%7D%20%20%7B6%3A%3E6.3f%7D'.format(T_4%2C%20n_cons%2C%20n_var%2C%20ut_it%2C%20ut_time%2C%20price_it%2C%20price_time))%0A%20%20%20%20%20%20%20%20%20%20%20%20total_info_arr.append(%5Bcall%2C%20n_cons%2C%20n_var%2C%20ut_it%2C%20ut_time%2C%20price_it%2C%20price_time%5D)%0A%20%20%20%20%20%20%20%20except%20MemoryError%20as%20e%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(e)%0A%20%20%20%20%20%20%20%20%20%20%20%20break%0A%20%20%20%20%20%20%20%20except%20SolutionError%20as%20s%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(s)%0A%20%20%20%20%20%20%20%20except%20OptimizerError%20as%20e%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(e)%0A%20%20%20%20%20%20%20%20%20%20%20%20break%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%22The%20calculations%20shown%20above%20were%20performed%20on%20a%20desktop%20with%2015.6%20GB%20of%20RAM%20and%20an%20Intel%24%5E%5CcircledR%24%20Core%24%5E%7B%5Ctext%7BTM%7D%7D%24%20i7-6770HQ%20CPU%20%40%202.6%20GHz%20%24%5Ctimes%24%208.%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(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
6b0a19e7fa86b6ff939333ccc91a73ed12c49edeb83b44c62708bea162a4baa8