// ICloneable interface public object Clone() { MultiPath temp = (MultiPath)this.MemberwiseClone(); temp.multiPath_ = new List <Path>(this.multiPath_); return(temp); }
override public double value(MultiPath path) { double val = 0.0; //int assetNum = path.assetNumber(); //for (int i = 0; i < payoffNum_; i++) //{ // int position = cashFlowPosition_[i]; // for (int j = 0; i < assetNum; j++) // { // pathValue_[j] = path[j][i]; // } // if( domains_[i].eventOcc(pathValue_) ) // { // val = val + payoffs_[i].value(path) * discountFactor_[i]; // } //} return val; }
///Script /// public override double ScriptDico(Dictionary <string, List <double> > timeDico, Dictionary <string, List <double> > indexDico, Handle <YieldTermStructure> discountTS, MultiPath path) { double fixingValue = 0.0; double payoff = 0.0; double yield = 0.0; bool iscalled = false; double discount = 1.0; int i = 0; MultiPath _path = (MultiPath)path; double strike = indexDico["strike"][0]; // Go through all dates // for (int t = 0; t < path.length(); t++) { double k = _path[0].time(t); if (_path[0].time(t) == timeDico["fixing"][i] && (iscalled == false)) { fixingValue = _path[0].value(t); yield = fixingValue / strike; if (yield > 1.0) { iscalled = true; discount = discountTS.link.discount(_path[0].time(i), true); payoff = (1 + indexDico["coupons"][i]) * 100 * discount; INSPOUT("ProbaCall " + i, 1.0); return(payoff); } i++; } } // if no previous payoff compute last redemption // fixingValue = _path[0].value(path.length() - 1); yield = fixingValue / strike; discount = discountTS.link.discount(_path[0].time(path.length() - 1), true); if ((iscalled == false) && (yield < indexDico["barrier"][0])) { payoff = yield * 100 * discount; INSPOUT("ProbaDown", 1.0); INSPOUT("AvgDown", yield); } else { payoff = 100.0 * discount; INSPOUT("ProbaMid", 1.0); } // return payoff // return(payoff); }
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); }
public abstract double value(MultiPath path);