/// <summary> /// Calculates the PV using Gauss Hermite quadrature if at least one scenario needs it. /// </summary> private void CalculateNumericalPV(Vector numericalPv, Vector isUnique, Vector[] stdDev, Vector[] coefficient, Vector[] coupon) { if (isUnique.MinElement() == 0.0) { double delta = fSwaptionDeal.Payer_Receiver == PayerReceiver.Payer ? 1.0 : -1.0; // At least one scenario needs numerical integration CalcUtils.GaussianQuadratureIntegral(numericalPv, (vout, y) => { vout.Clear(); VectorEngine.For(0, coupon.Length, i => { vout.Subtract(CalcUtils.SafeExpMultiply(stdDev[i] * y, delta * coupon[i] * coefficient[i])); return(LoopAction.Continue); }); vout.Assign(VectorMath.Max(vout, 0.0)); }, fQuadrature.Value); } }