예제 #1
0
        public static double AverageRawReturn(this DenseVector d)
        {
            double[] result = RawRateOfReturn(d.ToArray());
            var      e      = new DenseVector(result);

            return(e.Mean());
        }
예제 #2
0
        public static double Kurtosis(this double[] data)
        {
            var d     = new DenseVector(data);
            var num   = new DenseVector(d.Count);
            var denom = new DenseVector(d.Count);

            d.CopyTo(num);
            d.CopyTo(denom);

            for (int i = 0; i < num.Count; i++)
            {
                num[i]   = Math.Pow(d[i] - d.Mean(), 4);
                denom[i] = Math.Pow(d[i] - d.Mean(), 2);
            }

            return((num.Sum() * num.Count) / (Math.Pow(denom.Sum(), 2)));
        }
예제 #3
0
        public static double[] NormalizeZScore(this double[] data)
        {
            var d      = new DenseVector(data);
            var result = new DenseVector(d.Count);

            d.CopyTo(result);
            result = (DenseVector)((result - d.Mean()) / (d.StandardDeviation()));
            return(result.ToArray());
        }
예제 #4
0
        public static double Covariance(DenseVector x, DenseVector y)
        {
            var    cov   = new DenseVector(x.Count);
            double xMean = x.Mean();
            double yMean = y.Mean();

            if (xMean.Equals(double.NaN) || yMean.Equals(double.NaN))
            {
                return(double.NaN);
            }

            for (int i = 0; i < x.Count; i++)
            {
                cov[i] = (x[i] - xMean) * (y[i] - yMean);
            }

            return(((double)1 / (x.Count - 1)) * cov.Sum());
        }
예제 #5
0
        public void VarianceRatioTest(double[] data, int lag = 1, TimeSeriesType cor = TimeSeriesType.HOM)
        {
            DenseVector x = new DenseVector(data);

            //Mean
            double mu = x.Mean();

            //Variance for 1st Order Difference
            double s1 = (x.SubVector(lag, x.Count - lag) - x.SubVector(0, x.Count - 2)).Variance();


            double dLag   = lag;
            double varvrt = double.NaN;

            switch (cor)
            {
            case TimeSeriesType.HOM:
            {
                varvrt = 2 * (2 * dLag - 1) * (dLag - 1) / (3 * dLag * x.Count);
                break;
            }

            case TimeSeriesType.HET:
            {
                varvrt = 0;
                double sum2 = 0;
                for (int j = 0; j < lag; j++)
                {
                    double sum1a = 0;     //(x(j+2:n)-x(j+1:n-1)-mu).^2
                    double sum1b = 0;     //(x(2:n-j)-x(1:n-j-1)-mu).^2;
                    double sum1  = sum1a * sum1b;
                    double delta = sum1 / (Math.Pow(sum2, 2));
                    varvrt += 0;      //(2*(q(i)-j)/q(i))^2)*delta;
                }
                break;
            }
            }

            ZScore = (VRatio - 1) / Math.Sqrt(varvrt);
            PValue = NormCDF(ZScore);
        }
예제 #6
0
        /// <summary>
        /// 计算ROTI
        /// </summary>
        /// <param name="arc"></param>
        /// <remarks>
        /// 2019.研究台风引起电离层扰动的形态特征.许九靖. 安徽理工大学.
        /// </remarks>
        public static void CalROTI(ref OArc arc)
        {
            if (arc is null)
            {
                return;
            }

            // 利用相位观测值计算相对STEC信号
            for (int i = 1; i < arc.Length; i++)
            {
                if (Math.Abs(arc[i]["L4"]) < 1e-13 ||
                    Math.Abs(arc[i + 1]["L4"]) < 1e-13)
                {
                    continue;
                }

                arc[i]["ltec"] = 9.52437 * (arc[i]["L4"] - arc[i - 1]["L4"]);
            }

            int order = 9;
            int left, right;

            left = right = (order - 1) / 2;
            Vector <double> seg = new DenseVector(order);

            for (int i = left; i < arc.Length - right; i++)
            {
                for (int j = 0; j < order; j++)
                {
                    seg[j] = arc[i - left + j]["ltec"];
                }

                arc[i]["roti"] = Math.Sqrt(seg.DotProduct(seg) / order - Math.Pow(seg.Mean(), 2));
            }

            arc.StartIndex += left + 1;
            arc.EndIndex   -= right + 1;
        }