Example #1
0
        private bool BuildPopulationMatrix()
        {
            bool              success = true;
            int               i, nSize;
            List <Double>     eqMemberX, eqMemberY;
            ClassificationKey keyX = (cbProtoAttributeX.SelectedIndex < 0) ? ClassificationKey.NULL : ClassKeyList[cbProtoAttributeX.SelectedIndex];
            ClassificationKey keyY = (cbProtoAttributeY.SelectedIndex < 0) ? ClassificationKey.NULL : ClassKeyList[cbProtoAttributeY.SelectedIndex];

            nSize = DataSrc.HistoricalData.Constituents.Count;
            PopulationToClassify = new double[nSize, 2];

            eqMemberX = null;
            eqMemberY = null;

            if (keyX == keyY || keyX == ClassificationKey.NULL || keyY == ClassificationKey.NULL)
            {
                success = false;
            }
            else
            {
                for (i = 0; i < nSize; i++)
                {
                    eqMemberX = SelectDataComponent(keyX, DataSrc.HistoricalData.Constituents[i]);
                    eqMemberY = SelectDataComponent(keyY, DataSrc.HistoricalData.Constituents[i]);

                    if (eqMemberX != null && eqMemberY != null)
                    {
                        switch (ClassFnList[cbProtoFunction.SelectedIndex])
                        {
                        case PrototypeFunction.AVERAGE:
                            PopulationToClassify[i, 0] = eqMemberX.Average();
                            PopulationToClassify[i, 1] = eqMemberY.Average();
                            break;

                        case PrototypeFunction.STD_DEV:
                            PopulationToClassify[i, 0] = Helpers.StdDev(eqMemberX);
                            PopulationToClassify[i, 1] = Helpers.StdDev(eqMemberY);
                            break;

                        case PrototypeFunction.VARIANCE:
                        default:
                            break;
                        }
                    }
                    else
                    {
                        success = false;
                        break;
                    }
                }
            }

            return(success);
        }
Example #2
0
        private List <double> SelectDataComponent(ClassificationKey pKey, Equity pSrc)
        {
            List <double> return_list;

            switch (pKey)
            {
            case ClassificationKey.CLOSE:
                return_list = pSrc.HistoricalPrice;
                break;

            case ClassificationKey.HIGH:
                return_list = pSrc.HistoricalHighs;
                break;

            case ClassificationKey.LOW:
                return_list = pSrc.HistoricalLows;
                break;

            case ClassificationKey.OPEN:
                return_list = pSrc.HistoricalOpens;
                break;

            case ClassificationKey.PCT_CHANGE:
                return_list = pSrc.HistoricalPctChange;
                break;

            case ClassificationKey.VOLUME:
                return_list = Algorithms.IncrementalPercentChange(pSrc.HistoricalVolumes, 0);
                break;

            default:
                return_list = new List <double>();
                break;
            }

            return(return_list);
        }
Example #3
0
        private void BuildMovingChart()
        {
            int           i, n;
            List <double> x_seed;
            List <double> y_seed;

            ClassificationKey keyX = (cbProtoAttributeX.SelectedIndex < 0) ? ClassificationKey.NULL : ClassKeyList[cbProtoAttributeX.SelectedIndex];
            ClassificationKey keyY = (cbProtoAttributeY.SelectedIndex < 0) ? ClassificationKey.NULL : ClassKeyList[cbProtoAttributeY.SelectedIndex];

            this.daily_chart_x_values = new List <List <double> >();
            this.daily_chart_y_values = new List <List <double> >();

            n      = this.DataSrc.HistoricalData.Constituents.Count;
            x_seed = new List <double>(new double[n]);
            this.daily_chart_x_values.Add(x_seed);

            //If no feature is selected for the y-axis, treat the data as 1 dimensional
            // To do this, each X-point for a particular equity will be placed at a unique but constant y-value
            if (this.cbProtoAttributeY.SelectedIndex < 0)
            {
                y_seed = Enumerable.Range(1, n).Select(x => (double)x).ToList();
            }
            else
            {
                //Otherwise, start all data points at (0, 0)
                y_seed = new List <double>(new double[n]);
            }
            this.daily_chart_y_values.Add(y_seed);

            //Problem: not guaranteed that the date associated with a data-point-index is the same accross the entire array of Constituents. Need to align first.

            //Create each subsequent series by adding the selected x attribute at the given index to it's previous value for each equity in the list
            for (i = 0; i < this.DataSrc.HistoricalData.Constituents[0].HistoricalPriceDate.Count; i++)
            {
                switch (keyX)
                {
                case ClassificationKey.PCT_CHANGE:
                    x_seed = this.DataSrc.HistoricalData.Constituents.Select(x => x.HistoricalPctChange[i]).ToList();
                    break;

                case ClassificationKey.VOLUME:
                    x_seed = this.DataSrc.HistoricalData.Constituents.Select(x => x.HistoricalVolumes[i]).ToList();
                    break;

                default:
                    x_seed = this.DataSrc.HistoricalData.Constituents.Select(x => x.HistoricalPctChange[i]).ToList();
                    break;
                }

                //If no feature is selected for the y-axis, treat the data as 1 dimensional
                // To do this, each X-point for a particular equity will be placed at a unique but constant y-value
                if (this.cbProtoAttributeY.SelectedIndex < 0)
                {
                    y_seed = Enumerable.Range(1, n).Select(x => (double)x).ToList();
                    this.daily_chart_y_values.Add(y_seed);
                }
                else
                {
                    //Otherwise increment the data from the center point
                    switch (keyY)
                    {
                    case ClassificationKey.PCT_CHANGE:
                        y_seed = this.DataSrc.HistoricalData.Constituents.Select(x => x.HistoricalPctChange[i]).ToList();
                        break;

                    case ClassificationKey.VOLUME:
                        y_seed = this.DataSrc.HistoricalData.Constituents.Select(x => x.HistoricalVolumes[i]).ToList();
                        break;

                    default:
                        y_seed = this.DataSrc.HistoricalData.Constituents.Select(x => x.HistoricalPctChange[i]).ToList();
                        break;
                    }
                    this.daily_chart_y_values.Add(this.daily_chart_y_values[i].Zip(y_seed, (x, y) => x + y).ToList());
                }

                this.daily_chart_x_values.Add(this.daily_chart_x_values[i].Zip(x_seed, (x, y) => x + y).ToList());
            }

            this.chartSlider.Maximum = this.DataSrc.HistoricalData.Constituents.Select(x => x.HistoricalPriceDate.Count).Max();
            BindChartData(this.daily_chart_x_values[0], this.daily_chart_y_values[0], new List <int>(new int[n]));
        }