Hi Tim,
thank you. This works quite well.
## creating a shifted range for addressing the Array in the usual i,j
notation, the use of N here adjusts this for the size of any tree/ array
J = sub(1:(2N+1), (1+(N+1):((2N+1)+(N+1))))
## Asset price at node N,-N, now using negative node locations in the grid,
but using J[ ] shifts to the correct location in the array
St[J[-Nj]] = 'do some calc'
## Asset prices from bottom -N, to N, at time step N, same here. Iterating
as well.
for j = (-Nj+1):Nj
St[J[j]] = St[J[j]-1] * edx
end
thanks
Sven
Am Mittwoch, 26. August 2015 04:51:15 UTC+2 schrieb Tim Holy:
>
> SubArrays should let you do this.
>
> julia> x = 1:5
> 1:5
>
> julia> y = sub(x, 4:8)
> 5-element SubArray{Int64,1,UnitRange{Int64},(UnitRange{Int64},)}:
> 4
> 5
> #undef
> #undef
> #undef
>
> julia> y[0]
> 3
>
> julia> y[-2]
> 1
>
> julia> y[2]
> 5
>
> --Tim
>
> On Tuesday, August 25, 2015 10:57:50 AM Sven Duve wrote:
> > Hello,
> >
> > I am on Julia 0.3.9, I am trying to implement an American Binomial
> Spread
> > Options model. I got it working, but am wondering if there is a
> different
> > solution, perhaps cleaner one.
> >
> > I am doing the following to populate the options value's array, and then
> > loop over the array to simulate the exercise conditions in the tree:
> >
> >
> > for i in range(N-1, -1, N) ## the outer loop is counting down
> walking
> > back in the tree
> > for j in range(-i, 2, i+1)
> > for k in range(-i, 2, i+1)
> >
> > C[k+(N+1), j+(N+1)] = "some value" ## so in order to
> position
> > the value to the right location in the Array, I need to adjust the index
> > with (N+1)
> >
> > end
> > end
> > end
> >
> >
> > The question really is, can I create a matrix and change the indexing
> like
> > A = eye(), so that when A[0, 0] would be the center of the matrix?
> >
> >
> > Thanks
> >
> >
> > Sven
>
>