示例#1
0
        public static Correlation Series(DataSeries x, DataSeries y, int period)
        {
            string description = string.Concat(new object[] { "Correlation(", x.Description, ",", y.Description, ",", period.ToString(), ")" });

            if (x.Cache.ContainsKey(description))
            {
                return((Correlation)x.Cache[description]);
            }

            Correlation _Correlation = new Correlation(x, y, period, description);

            x.Cache[description] = _Correlation;
            return(_Correlation);
        }
示例#2
0
        //private double AVERAGE(int start, DataSeries d, int period)
        //{
        //    return SMA.Series(d, period)[start];
        //}

        //private double CORREL(int start, DataSeries x, DataSeries y, int period)
        //{
        //    double pearson = 0;
        //    double covXY = 0;
        //    if (x.Count < period || y.Count < period)
        //    {
        //        // Too little data.
        //    }
        //    else
        //    {
        //        covXY = WealthLab.Indicators.Sum.Series((x - AVERAGE(start, x, period)) * (y - AVERAGE(start, y, period)), period)[start];
        //        covXY /= period;
        //        double stdx = StdDev.Series(x, period, StdDevCalculation.Population)[start];
        //        double stdy = StdDev.Series(y, period, StdDevCalculation.Population)[start];
        //        if (stdx * stdy != 0)
        //        {
        //            pearson = covXY / (stdx * stdy);
        //        }
        //    }
        //    return pearson;
        //}

        public CorrelationXL(DataSeries x, DataSeries y, int period, string description)
            : base(x, description)
        {
            //for (int i = period; i < x.Count; i++)
            //{
            //    base[i] = CORREL(i, x, y, period);
            //}

            Correlation c = Correlation.Series(x, y, period);

            for (int bar = period; bar < x.Count; bar++)
            {
                base[bar] = c[bar];
            }
        }