public void ModifyLattice(double U) { // Forward induction; building the tree var down = _strategy.DownValue; var up = _strategy.UpValue; var si = GetOptionLattice.MinIndex; GetOptionLattice[si, si] = U; GetAssetLattice[si, si] = U; // Loop from the min index to the end index for (var n = GetOptionLattice.MinIndex + 1; n <= GetOptionLattice.MaxIndex; n++) { for (var i = 0; i < GetOptionLattice.NumberColumns(n) - 1; i++) { GetOptionLattice[n, i] = down * GetOptionLattice[n - 1, i]; GetOptionLattice[n, i + 1] = up * GetOptionLattice[n - 1, i]; GetAssetLattice[n, i] = down * GetAssetLattice[n - 1, i]; GetAssetLattice[n, i + 1] = up * GetAssetLattice[n - 1, i]; } } // Postcondition: we now have the complete lattice for the underlying asset }
public double GetPrice(Vector <double> RHS) { // Backward induction; calculate the price based on discete payoff function at t = T var pr = _strategy.ProbValue; // Initialise the vector at the expiry date/MaxIndex var ei = GetOptionLattice.MaxIndex; // Exception handling: sizes of RHS and base vector must be the same for (var i = 0; i < GetOptionLattice.NumberColumns(ei); i++) { GetOptionLattice[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 (var n = GetOptionLattice.MaxIndex - 1; n >= GetOptionLattice.MinIndex; n--) { for (var i = 0; i < GetOptionLattice.NumberColumns(n); i++) { S = GetOptionLattice[n, i]; GetOptionLattice[n, i] = _disc * (pr * GetOptionLattice[n + 1, i + 1] + (1.0 - pr) * GetOptionLattice[n + 1, i]); // Now take early exercise into account if (_constraintExists) { GetOptionLattice[n, i] = _con(GetOptionLattice[n, i], S); } } } var si = GetOptionLattice.MinIndex; return(GetOptionLattice[si, si]); }
public Vector <double> BasePyramidVector() { return(GetOptionLattice.BasePyramidVector()); }