Ejemplo n.º 1
0
        public void SinglePathCovariance(double[] dates, double epsilon, double precision)
        {
            var brownian   = BrownianBridge.Create(dates);
            var dim        = brownian.GaussianSize(1);
            var jacobian   = FiniteDifferenceUtils.CenteredJacobian(x => BrownianPath1d(brownian, x), dim, new double[dim], epsilon);
            var covariance = jacobian.Prod(jacobian.Tranpose());

            for (int i = 0; i < dates.Length; i++)
            {
                for (int j = 0; j < dates.Length; j++)
                {
                    var cov_ij = Math.Min(dates[i], dates[j]);
                    var error  = Math.Abs(cov_ij - covariance[i, j]);
                    Assert.LessOrEqual(error, precision);
                }
            }
        }
Ejemplo n.º 2
0
        public void SinglePathIncrementCovariance(double[] dates, double epsilon, double precision)
        {
            var brownian   = BrownianBridge.Create(dates);
            var dim        = brownian.GaussianSize(1);
            var jacobian   = FiniteDifferenceUtils.CenteredJacobian(x => PathInc1D(brownian, x), dim, new double[dim], epsilon);
            var covariance = jacobian.Prod(jacobian.Tranpose());

            for (int i = 0; i < dates.Length; i++)
            {
                var error = Math.Abs(covariance[i, i] - (i == 0 ? dates[0] : dates[i] - dates[i - 1]));
                Assert.LessOrEqual(error, precision);

                for (int j = 0; j < i; j++)
                {
                    var errorij = Math.Abs(covariance[i, j]);
                    Assert.LessOrEqual(errorij, precision);
                    Assert.IsTrue(DoubleUtils.MachineEquality(covariance[i, j], covariance[j, i]));
                }
            }
        }