// ICloneable interface public object Clone() { MultiPath temp = (MultiPath)this.MemberwiseClone(); temp.multiPath_ = new List <Path>(this.multiPath_); return(temp); }
private Sample <IPath> next(bool antithetic) { if (brownianBridge_) { Utils.QL_FAIL("Brownian bridge not supported"); return(null); } Sample <List <double> > sequence_ = antithetic ? generator_.lastSequence() : generator_.nextSequence(); int m = process_.size(); int n = process_.factors(); MultiPath path = (MultiPath)next_.value; Vector asset = process_.initialValues(); for (int j = 0; j < m; j++) { path[j].setFront(asset[j]); } Vector temp; next_.weight = sequence_.weight; TimeGrid timeGrid = path[0].timeGrid(); double t, dt; for (int i = 1; i < path.pathSize(); i++) { int offset = (i - 1) * n; t = timeGrid[i - 1]; dt = timeGrid.dt(i - 1); if (antithetic) { temp = -1 * new Vector(sequence_.value.GetRange(offset, n)); } else { temp = new Vector(sequence_.value.GetRange(offset, n)); } asset = process_.evolve(t, asset, dt, temp); for (int j = 0; j < m; j++) { path[j][i] = asset[j]; } } return(next_); }
public double value(IPath path) { MultiPath p = path as MultiPath; Utils.QL_REQUIRE(p != null, () => "invalid path"); Utils.QL_REQUIRE(p.pathSize() > 0, () => "the path cannot be empty"); Vector states = new Vector(p.assetNumber()); for (int j = 0; j < states.size(); ++j) { states[j] = p[j][p.pathSize() - 1]; } double df = 1.0 / process_.numeraire(exerciseTime_, states); return(payoff_.value(states[0]) * df); }