示例#1
0
    public double getPrice(Vector <double> RHS)
    {     // Backward induction; calculate the price based on discete payoff function at t = T
        double pr = str.probValue();

        // Initialise the vector at the expiry date/MaxIndex
        int ei = lattice.MaxIndex;


        // Exception handling: sizes of RHS and base vector must be the same
        for (int i = 0; i < lattice.NumberColumns(ei); i++)
        {
            lattice[ei, i] = RHS[i];
        }

        double S;           // Value at node [n,i] before it gets overwritten

        // Loop from the max index to the start (min) index
        for (int n = lattice.MaxIndex - 1; n >= lattice.MinIndex; n--)
        {
            for (int i = 0; i < lattice.NumberColumns(n); i++)
            {
                S             = lattice[n, i];
                lattice[n, i] = disc * (pr * lattice[n + 1, i + 1] + (1.0 - pr) * lattice[n + 1, i]);

                // Now take early exercise into account
                if (constraintExists)
                {
                    lattice[n, i] = con(lattice[n, i], S);
                }
            }
        }

        int si = lattice.MinIndex;

        return(lattice[si, si]);
    }