public double swaption(Swaption.Arguments arguments, double fixedRate, double range, int intervals) { Date settlement = termStructure().link.referenceDate(); DayCounter dayCounter = termStructure().link.dayCounter(); double start = dayCounter.yearFraction(settlement, arguments.floatingResetDates[0]); double w = (arguments.type == VanillaSwap.Type.Payer ? 1 : -1); List <double> fixedPayTimes = new InitializedList <double>(arguments.fixedPayDates.Count); for (int i = 0; i < fixedPayTimes.Count; ++i) { fixedPayTimes[i] = dayCounter.yearFraction(settlement, arguments.fixedPayDates[i]); } SwaptionPricingFunction function = new SwaptionPricingFunction(a(), sigma(), b(), eta(), rho(), w, start, fixedPayTimes, fixedRate, this); double upper = function.mux() + range * function.sigmax(); double lower = function.mux() - range * function.sigmax(); SegmentIntegral integrator = new SegmentIntegral(intervals); return(arguments.nominal * w * termStructure().link.discount(start) * integrator.value(function.value, lower, upper)); }
public override void calculate() { Utils.QL_REQUIRE(arguments_.exercise.type() == Exercise.Type.European, () => "not an European Option"); StrikedTypePayoff payoff = arguments_.payoff as StrikedTypePayoff; Utils.QL_REQUIRE(payoff != null, () => "not an European Option"); double variance = process_.blackVolatility().link.blackVariance(arguments_.exercise.lastDate(), payoff.strike()); double dividendDiscount = process_.dividendYield().link.discount(arguments_.exercise.lastDate()); double riskFreeDiscount = process_.riskFreeRate().link.discount(arguments_.exercise.lastDate()); double drift = Math.Log(dividendDiscount / riskFreeDiscount) - 0.5 * variance; Integrand f = new Integrand(arguments_.payoff, process_.stateVariable().link.value(), drift, variance); SegmentIntegral integrator = new SegmentIntegral(5000); double infinity = 10.0 * Math.Sqrt(variance); results_.value = process_.riskFreeRate().link.discount(arguments_.exercise.lastDate()) / Math.Sqrt(2.0 * Math.PI * variance) * integrator.value(f.value, drift - infinity, drift + infinity); }