Hello all,

I am trying to write a method that builds a binomial tree for option 
pricing.  I am trying to set up my tree like this:

function build_tree(s_opt::StockOption)
  u = 1 + s_opt.pu
  d = 1 - s_opt.pd
  # qu = (exp((s_opt.r - s_opt.div) * s_opt.dt) - d) / (u - d)
  # qd = 1 - qu

  # init array
   stockTree = Vector{Float64}[ zeros(m) for m = 1:s_opt.N + 1]

  for i = 1:s_opt.N + 1
    for j = 1:i
      stockTree[i][j] = s_opt.S0 * u ^ (j-1) * d ^ (i - j)
    end
  end

  return stockTree
end

Is this the most "Julian" way to do this (I didn't find really any modules 
that would suit this purpose)?

Here is what prints out:

*3-element Array{Array{Float64,1},1}:*

* [50.0]                       *

* [40.0,60.0]                  *

* [32.00000000000001,48.0,72.0]*

I suppose also I could default the [1][1] state to the spot price (S0), so 
then I don't need to alter the looping range and instead start the range at 
2.

Thanks!

Chris

Reply via email to