public double value(Path path) { int n = path.length(); if (!(n > 1)) { throw new Exception("the path cannot be empty"); } double sum = runningSum_; int fixings; if (path.timeGrid().mandatoryTimes()[0] == 0.0) { // include initial fixing //sum = std::accumulate(path.begin(),path.end(),runningSum_); for (int i = 0; i < path.length(); i++) { sum += path[i]; } fixings = pastFixings_ + n; } else { //sum = std::accumulate(path.begin()+1,path.end(),runningSum_); for (int i = 1; i < path.length(); i++) { sum += path[i]; } fixings = pastFixings_ + n - 1; } double averagePrice = sum / fixings; return(discount_ * payoff_.value(averagePrice)); }
public double value(Path path) { int n = path.length() - 1; Utils.QL_REQUIRE(n > 0, () => "the path cannot be empty"); double averagePrice; double product = runningProduct_; int fixings = n + pastFixings_; if (path.timeGrid().mandatoryTimes()[0].IsEqual(0.0)) { fixings += 1; product *= path.front(); } // care must be taken not to overflow product double maxValue = double.MaxValue; averagePrice = 1.0; for (int i = 1; i < n + 1; i++) { double price = path[i]; if (product < maxValue / price) { product *= price; } else { averagePrice *= Math.Pow(product, 1.0 / (double)fixings); product = price; } } averagePrice *= Math.Pow(product, 1.0 / fixings); return(discount_ * payoff_.value(averagePrice)); }
public double value(IPath path) { if (!(path.length() > 0)) { throw new ApplicationException("the path cannot be empty"); } return(payoff_.value((path as Path).back()) * discount_); }
public double value(Path path) { int n = path.length() - 1; if (!(n > 0)) { throw new ApplicationException("the path cannot be empty"); } double averagePrice; double product = runningProduct_; int fixings = n + pastFixings_; if (path.timeGrid().mandatoryTimes()[0] == 0.0) { fixings += 1; product *= path.front(); } // care must be taken not to overflow product double maxValue = double.MaxValue; //QL_MAX_REAL; averagePrice = 1.0; for (int i = 1; i < n + 1; i++) { double price = path[i]; if (product < maxValue / price) { product *= price; } else { averagePrice *= Math.Pow(product, 1.0 / (double)fixings); product = price; } } averagePrice *= Math.Pow(product, 1.0 / fixings); return(discount_ * payoff_.value(averagePrice)); }