예제 #1
0
    public void modifyLattice(double U)
    {     // Forward induction; building the tree
        double down = str.downValue();
        double up   = str.upValue();

        int si = lattice.MinIndex;

        lattice[si, si] = U;

        // Loop from the min index to the end index
        for (int n = lattice.MinIndex + 1; n <= lattice.MaxIndex; n++)
        {
            for (int i = 0; i < lattice.NumberColumns(n) - 1; i++)
            {
                lattice[n, i]     = down * lattice[n - 1, i];
                lattice[n, i + 1] = up * lattice[n - 1, i];
            }
        }

        // Postcondition: we now have the complete lattice for the underlying asset
    }
    // Useful function
    public void UpdateLattice(Lattice <double> source, double rootValue)
    {           // Find the depth of the lattice; this a Template Method Pattern
        int si = source.MinIndex;

        source[si, si] = rootValue;

        // Loop from the min index to the end index
        for (int n = source.MinIndex + 1; n <= source.MaxIndex; n++)
        {
            for (int i = 0; i < source.NumberColumns(n); i++)
            {
                source[n, i]     = d * source[n - 1, i];
                source[n, i + 1] = u * source[n - 1, i];
            }
        }
    }