Welcome to THETAWIKI. If you like to create or edit a page please make sure to login or register an account. All registered users please make sure to provide a valid email address.

Dynamic Utility Optimization

From ThetaWiki
Jump to: navigation, search


In a dynamic trading situation, portfolio weights are obtained via optimizing investors' utility function. The utility function can be arbitrary and in this example it is

function util = utility(p)
  util = log(p)

A dynamic trading strategy based on discrete portfolio weights is very easy to implement in ThetaML, as what shows below.

ThetaML Implementation

The underlying stock 'S' and the discount numeraire 'EUR' are processes simulated externally. For example, the process 'S' can be a stock price process that follows a Geometric Brownian Motion or a Heston Volatility process. The discount numeraire 'EUR' can be a constant discount curve as implemented in Discounting, or a stochastic process that has a dynamics as defined in the CIR model.

model Portfolio
  import S         "Stock prices"
  import EUR       "Discount 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
  Port = Port_0
  Port_obs = Port
  % loop 'n_dt' times
  loop n_dt
    % optimization by brute force,
    % implements d = argmax_{d}(E(utility(Port!)))
    util = -1E10
    % array looping; the variables 'c', 'pi' and 'cur_uitl' serve both as array iterators and
    % array elements; the arrays 'Pi' and 'Util' are built here with this array loop
    loop c, pii, cur_util : C, Pii, Util
      % compute utility calling a user defined Matlab function
      % the 'return!' accesses the 'return' in the next line
      cur_util = E(utility(returns!))
      % 'pii!' accesses the 'pii' defined in the next array loop
      returns = pii!/Port_0
      % remember portfolio weight d with largst utility
      if cur_util > util
        d = c
        util = cur_util
    u = Util
    % Array loop; compute all possible outcomes of the portfolio
    % for optimization
    loop pii, c : Pii, C
      pii = Port + c*(S! - S) + (1 - c)*(100/EUR! - 100/EUR)
    % Investment in S or Zero Bond (with value 1/EUR)
    Port = Port + d*(S! - S) + (1 - d)*(100/EUR! - 100/EUR)
    d_obs = d
    % the ThetaML command 'Theta' passes time by 'T/n_dt' years
    Theta T/n_dt
    Port_obs = Port

Note that the number of Monte Carlo paths has to be much larger than that used in simulating option prices. 300000 paths were used in this example.