public static RrFunction ZcRateCoeffFunction(double maturity, double meanReversion) { var expMat = Math.Exp(-meanReversion * maturity); if (DoubleUtils.MachineEquality(1.0, expMat)) { return(RrFunctions.Affine(1.0, -maturity)); } return((expMat / meanReversion) * RrFunctions.Exp(meanReversion) - (1.0 / meanReversion)); }
public void TestIntegralExp() { var exp = RrFunctions.Exp(0.1); var step = new StepFunction(new[] { 0.0, 5.0 }, new[] { 0.015, 0.010 }, 0.0); var f = exp * step; var integral = f.Integral(0.0); var testVal = integral.Eval(10.0); var expintegral = exp.Integral(0.0); var refVal = 0.015 * (expintegral.Eval(5.0) - expintegral.Eval(0.0)) + 0.01 * (expintegral.Eval(10.0) - expintegral.Eval(5.0)); Assert.IsTrue(DoubleUtils.Equality(testVal, refVal, 1.5 * DoubleUtils.MachineEpsilon)); }
private static double[][] VarSwapDeformation(Bergomi2FModel b2F, double[] fwdVolStart, double[] fwdVolEnd) { Debug.Assert(fwdVolStart.Length == fwdVolEnd.Length); var initCurve = b2F.Xi.Integral(0.0); var factor1 = (b2F.Xi * RrFunctions.Exp(-b2F.K1)).Integral(0.0); var factor2 = (b2F.Xi * RrFunctions.Exp(-b2F.K2)).Integral(0.0); var alpha = Alpha(b2F); return(EnumerableUtils.For(0, fwdVolStart.Length, i => { double volMatStart = fwdVolStart[i]; double volMatEnd = fwdVolEnd[i]; double initFwdVariance = initCurve.Eval(volMatEnd) - initCurve.Eval(volMatStart); double def1 = factor1.Eval(volMatEnd) - factor1.Eval(volMatStart); double def2 = factor2.Eval(volMatEnd) - factor2.Eval(volMatStart); return new[] { (1.0 - b2F.Theta) * def1, b2F.Theta * def2 }.Mult(b2F.Nu * alpha / initFwdVariance); })); }
public static RrFunction IntegratedCovariance(RrFunction instantCovariance, double meanReversion1, double meanReversion2, double startDate = 0.0) { var integratedExpCov = (instantCovariance * RrFunctions.Exp(meanReversion1 + meanReversion2)).Integral(startDate); return(integratedExpCov * RrFunctions.Exp(-(meanReversion1 + meanReversion2))); }
public static RrFunction IntegratedDrift(RrFunction instantDrift, double meanReversion, double startDate = 0.0) { var integratedExpDrift = (instantDrift * RrFunctions.Exp(meanReversion)).Integral(startDate); return(integratedExpDrift * RrFunctions.Exp(-meanReversion)); }