Dynamic Utility Optimization
From ThetaWiki
[edit] Overview
In a dynamic trading situation, one might want to optimize the investor's actions over the portfolio weights. A simple ThetaScript is sufficient to optimize a dynamic trading strategy based on discretizing the possible portfolio weights.
[edit] ThetaScript
Model Portfolio import S "Stock price" import EUR "Numeraire" import Port_0 "Initial portfolio value" import T "Investment horizon" import n_dt "Number of rebalances" export Port_obs "Portfolio" export d_obs "Optimal ratio" % initialize C with values from [0...1] index = 0 n = 10 loop n+1 C[index+1] = index/n index = index + 1 end Port = Port_0 Port_obs = Port loop n_dt % optimization by brute force, % implements d = argmax_{d}(E(utility(Port!))) util = -1E10 loop c, pi, cur_util:C, Pi, Util % compute utility calling a userdefined Matlab function cur_util = E(utility(return!)) return = pi!/Port_0 % remember portfolio weight d with largst utility if cur_util> util d = c util = cur_util end end u = Util % Compute all possible outcomes of the portfolio % for optimization loop pi, c : Pi, C pi = Port + c*(S!-S) + (1-c)*(100/EUR!-100/EUR) end % Investment in S or Zero Bond (with value 1/EUR) Port = Port + d*(S!-S) + (1-d)*(100/EUR!-100/EUR) d_obs = d Theta T/n_dt Port_obs = Port end end
The utility function can be arbitrary and in this example it is
function util = utility(p) util = log(p)
Note that the number of Monte Carlo paths has to be larger than in evaluating options. 300000 paths were used in this example.
