private static void ExportFeaturesAndLabel(string code)
        {
            string filePath = (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX) ? Environment.GetEnvironmentVariable("HOME") : Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");

            filePath += "\\indicatorOutput.txt";

            DateTime targetDate = IndicatorService.LastDate(code);

            int numberOfData = 4000;

            var data = IndicatorService.GetData(code, targetDate, new string[] { "Tarih", "Kapanis" }, numberOfData + 1);

            double[] sma = MovingAverage.Simple(code, targetDate, 14, numberOfData);
            double[] wma = MovingAverage.Weighted(code, targetDate, 14, numberOfData);
            double[] ema = MovingAverage.Exponential(code, targetDate, 14, numberOfData);
            MovingAverageConvergenceDivergence macd = new MovingAverageConvergenceDivergence(code, targetDate, 12, 26, 9, numberOfData);

            double[]    rsi         = RelativeStrengthIndex.Rsi(code, targetDate, 14, numberOfData);
            double[]    williams    = WilliamsR.Wsr(code, targetDate, 14, numberOfData);
            Stochastics stochastics = new Stochastics(code, targetDate, 14, 3, 3, numberOfData);

            double[] closesOut      = IndicatorDataPreprocessor.GetClosesOut(numberOfData, data);
            double[] smaOut         = IndicatorDataPreprocessor.GetSMAOut(sma);
            double[] wmaOut         = IndicatorDataPreprocessor.GetWMAOut(wma);
            double[] emaOut         = IndicatorDataPreprocessor.GetEMAOut(ema);
            double[] macdOut        = IndicatorDataPreprocessor.GetMACDOut(macd);
            double[] rsiOut         = IndicatorDataPreprocessor.GetRSIOut(rsi);
            double[] williamsROut   = IndicatorDataPreprocessor.GetWilliamsROut(williams);
            double[] stochasticsOut = IndicatorDataPreprocessor.GetStochasticsOut(stochastics);

            int minRowCount;

            minRowCount = smaOut.Length;
            minRowCount = minRowCount < wmaOut.Length ? minRowCount : wmaOut.Length;
            minRowCount = minRowCount < emaOut.Length ? minRowCount : emaOut.Length;
            minRowCount = minRowCount < macdOut.Length ? minRowCount : macdOut.Length;
            minRowCount = minRowCount < rsiOut.Length ? minRowCount : rsiOut.Length;
            minRowCount = minRowCount < williamsROut.Length ? minRowCount : williamsROut.Length;
            minRowCount = minRowCount < stochasticsOut.Length ? minRowCount : stochasticsOut.Length;
            minRowCount = minRowCount < closesOut.Length ? minRowCount : closesOut.Length;

            FeatureVector vector = new FeatureVector();

            vector.AddColumn("SMA", smaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            vector.AddColumn("WMA", wmaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            vector.AddColumn("EMA", emaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            vector.AddColumn("MACD", macdOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            vector.AddColumn("RSI", rsiOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            vector.AddColumn("WilliamsR", williamsROut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            vector.AddColumn("Stochastics", stochasticsOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            vector.AddColumn("label", closesOut.Select(p => (object)string.Format("{0:0.0}", p).ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());

            new CSVExporter(vector).Export(filePath);
            Console.WriteLine("Operations completed.");
        }
        private void PreprocessIndicators()
        {
            var data = IndicatorService.GetData(code, targetDate, new string[] { "Tarih", "Kapanis" }, numberOfData + 1);

            double[] sma = null;
            double[] wma = null;
            double[] ema = null;
            MovingAverageConvergenceDivergence macd = null;

            double[]    rsi         = null;
            double[]    williamsR   = null;
            Stochastics stochastics = null;

            if (isSMA)
            {
                sma = MovingAverage.Simple(code, targetDate, 14, numberOfData);
            }
            if (isWMA)
            {
                wma = MovingAverage.Weighted(code, targetDate, 14, numberOfData);
            }
            if (isEMA)
            {
                ema = MovingAverage.Exponential(code, targetDate, 14, numberOfData);
            }
            if (isMACD)
            {
                macd = new MovingAverageConvergenceDivergence(code, targetDate, 12, 26, 9, numberOfData);
            }
            if (isRSI)
            {
                rsi = RelativeStrengthIndex.Rsi(code, targetDate, 14, numberOfData);
            }
            if (isWilliamsR)
            {
                williamsR = WilliamsR.Wsr(code, targetDate, 14, numberOfData);
            }
            if (isStochastics)
            {
                stochastics = new Stochastics(code, targetDate, 14, 3, 3, numberOfData);
            }

            double[] closesOut      = IndicatorDataPreprocessor.GetClosesOut(numberOfData, data);
            double[] smaOut         = null;
            double[] wmaOut         = null;
            double[] emaOut         = null;
            double[] macdOut        = null;
            double[] rsiOut         = null;
            double[] williamsROut   = null;
            double[] stochasticsOut = null;

            if (isSMA)
            {
                smaOut = IndicatorDataPreprocessor.GetSMAOut(sma);
            }
            if (isWMA)
            {
                wmaOut = IndicatorDataPreprocessor.GetWMAOut(wma);
            }
            if (isEMA)
            {
                emaOut = IndicatorDataPreprocessor.GetEMAOut(ema);
            }
            if (isMACD)
            {
                macdOut = IndicatorDataPreprocessor.GetMACDOut(macd);
            }
            if (isRSI)
            {
                rsiOut = IndicatorDataPreprocessor.GetRSIOut(rsi, false);
            }
            if (isWilliamsR)
            {
                williamsROut = IndicatorDataPreprocessor.GetWilliamsROut(williamsR, false);
            }
            if (isStochastics)
            {
                stochasticsOut = IndicatorDataPreprocessor.GetStochasticsOut(stochastics, false);
            }

            minRowCount = closesOut.Length;
            if (isSMA)
            {
                minRowCount = minRowCount < smaOut.Length ? minRowCount : smaOut.Length;
            }
            if (isWMA)
            {
                minRowCount = minRowCount < wmaOut.Length ? minRowCount : wmaOut.Length;
            }
            if (isEMA)
            {
                minRowCount = minRowCount < emaOut.Length ? minRowCount : emaOut.Length;
            }
            if (isMACD)
            {
                minRowCount = minRowCount < macdOut.Length ? minRowCount : macdOut.Length;
            }
            if (isRSI)
            {
                minRowCount = minRowCount < rsiOut.Length ? minRowCount : rsiOut.Length;
            }
            if (isWilliamsR)
            {
                minRowCount = minRowCount < williamsROut.Length ? minRowCount : williamsROut.Length;
            }
            if (isStochastics)
            {
                minRowCount = minRowCount < stochasticsOut.Length ? minRowCount : stochasticsOut.Length;
            }

            FeatureVector featureVector = new FeatureVector();

            if (isSMA)
            {
                featureVector.AddColumn("SMA", smaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            }
            if (isWMA)
            {
                featureVector.AddColumn("WMA", wmaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            }
            if (isEMA)
            {
                featureVector.AddColumn("EMA", emaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            }
            if (isMACD)
            {
                featureVector.AddColumn("MACD", macdOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            }
            if (isRSI)
            {
                featureVector.AddColumn("RSI", rsiOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            }
            if (isWilliamsR)
            {
                featureVector.AddColumn("WilliamsR", williamsROut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            }
            if (isStochastics)
            {
                featureVector.AddColumn("Stochastics", stochasticsOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            }
            featureVector.AddColumn("label", closesOut.Select(p => (object)string.Format("{0:0.0}", p).ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());

            int count = featureVector.Values[0].Length;

            training = new FeatureVector();
            test     = new FeatureVector();

            for (int i = 0; i < featureVector.ColumnName.Count; i++)
            {
                training.AddColumn(featureVector.ColumnName[i], featureVector.Values[i].Take((int)(count * trainingPercentage / 100.0)).ToArray());
                test.AddColumn(featureVector.ColumnName[i], featureVector.Values[i].Skip((int)(count * trainingPercentage / 100.0)).Take(count).ToArray()); // Take(count) means take the rest of all elements, number of the rest of the elements is smaller than count.
            }
        }
Ejemplo n.º 3
0
        private void mavParameterNext_Click(object sender, EventArgs e)
        {
            mavResultTitle.Text = Code + " için Moving Average sonucu";
            MAVPeriod           = (int)mavPeriod.Value;

            mavResultChart.Series.Clear();

            var closeSeries = new Series
            {
                Name      = "Kapanış",
                Color     = System.Drawing.Color.Black,
                ChartType = SeriesChartType.Line
            };
            var smaSeries = new Series
            {
                Name      = "Simple Moving Average",
                Color     = System.Drawing.Color.Red,
                ChartType = SeriesChartType.Line
            };
            var wmaSeries = new Series
            {
                Name      = "Weighted Moving Average",
                Color     = System.Drawing.Color.Green,
                ChartType = SeriesChartType.Line
            };
            var emaSeries = new Series
            {
                Name      = "Exponential Moving Average",
                Color     = System.Drawing.Color.Blue,
                ChartType = SeriesChartType.Line
            };

            var closeData = IndicatorService.GetData(Code, TargetDate, new string[] { "Tarih", "Kapanis" }, NumberOfData);

            double[] smaData, wmaData, emaData;
            if (MapReduceAllowed)
            {
                smaData = MovingAverage.SimpleMR(Code, TargetDate, MAVPeriod, NumberOfData);
                wmaData = MovingAverage.WeightedMR(Code, TargetDate, MAVPeriod, NumberOfData);
                emaData = MovingAverage.ExponentialMR(Code, TargetDate, MAVPeriod, NumberOfData);
            }
            else
            {
                smaData = MovingAverage.Simple(Code, TargetDate, MAVPeriod, NumberOfData);
                wmaData = MovingAverage.Weighted(Code, TargetDate, MAVPeriod, NumberOfData);
                emaData = MovingAverage.Exponential(Code, TargetDate, MAVPeriod, NumberOfData);
            }

            DateTime date;

            for (int i = 0; i < smaData.Length; i++)
            {
                var close = closeData.ElementAt(i);
                date = close.GetElement("Tarih").Value.AsBsonDateTime.ToLocalTime();

                closeSeries.Points.AddXY(date, close.GetElement("Kapanis").Value.ToDouble());
                smaSeries.Points.AddXY(date, smaData[i]);
                wmaSeries.Points.AddXY(date, wmaData[i]);
                emaSeries.Points.AddXY(date, emaData[i]);
            }

            mavResultChart.ChartAreas[0].AxisY.Minimum = Math.Floor(new double[] { closeData.Select(p => p.GetElement("Kapanis").Value.ToDouble()).Min(), smaData.Min(), wmaData.Min(), emaData.Min() }.Min());
            mavResultChart.ChartAreas[0].AxisY.Maximum = Math.Ceiling(new double[] { closeData.Select(p => p.GetElement("Kapanis").Value.ToDouble()).Max(), smaData.Max(), wmaData.Max(), emaData.Max() }.Max());

            mavResultChart.Series.Add(closeSeries);
            mavResultChart.Series.Add(smaSeries);
            mavResultChart.Series.Add(wmaSeries);
            mavResultChart.Series.Add(emaSeries);

            mavResultChart.Invalidate();

            mavResultPanel.BringToFront();
        }
Ejemplo n.º 4
0
        private void buttonForDataSplitNext_Click(object sender, EventArgs e)
        {
            trainingSetPercentage = (double)numericUpDownForTrainingSetPercent.Value / 100.0;
            numFolds = (int)numericUpDownForNumFolds.Value;

            double[] smaOut         = null;
            double[] wmaOut         = null;
            double[] emaOut         = null;
            double[] macdOut        = null;
            double[] stochasticsOut = null;
            double[] williamsROut   = null;
            double[] rsiOut         = null;
            double[] closesOut      = null;

            var data = IndicatorService.GetData(code, targetDate, new string[] { "Tarih", "Kapanis" }, numberOfData + 1);

            if (isSMAChecked)
            {
                smaOut = IndicatorDataPreprocessor.GetSMAOut(MovingAverage.Simple(code, targetDate, smaPeriod, numberOfData));
            }
            if (isWMAChecked)
            {
                wmaOut = IndicatorDataPreprocessor.GetWMAOut(MovingAverage.Weighted(code, targetDate, wmaPeriod, numberOfData));
            }
            if (isEMAChecked)
            {
                emaOut = IndicatorDataPreprocessor.GetEMAOut(MovingAverage.Exponential(code, targetDate, emaPeriod, numberOfData));
            }
            if (isMACDChecked)
            {
                macdOut = IndicatorDataPreprocessor.GetMACDOut(new MovingAverageConvergenceDivergence(code, targetDate, firstPeriod, secondPeriod, triggerPeriod, numberOfData));
            }
            if (isStochasticsChecked)
            {
                stochasticsOut = IndicatorDataPreprocessor.GetStochasticsOut(new Stochastics(code, targetDate, fastKPeriod, fastDPeriod, slowDPeriod, numberOfData));
            }
            if (isWilliamsRChecked)
            {
                williamsROut = IndicatorDataPreprocessor.GetWilliamsROut(WilliamsR.Wsr(code, targetDate, williamsRPeriod, numberOfData));
            }
            if (isRSIChecked)
            {
                rsiOut = IndicatorDataPreprocessor.GetRSIOut(RelativeStrengthIndex.Rsi(code, targetDate, rsiPeriod, numberOfData));
            }
            closesOut = IndicatorDataPreprocessor.GetClosesOut(numberOfData, data);

            int minRowCount = 1000000;

            if (smaOut != null)
            {
                minRowCount = smaOut.Length;
            }
            if (wmaOut != null)
            {
                minRowCount = minRowCount < wmaOut.Length ? minRowCount : wmaOut.Length;
            }
            if (emaOut != null)
            {
                minRowCount = minRowCount < emaOut.Length ? minRowCount : emaOut.Length;
            }
            if (macdOut != null)
            {
                minRowCount = minRowCount < macdOut.Length ? minRowCount : macdOut.Length;
            }
            if (rsiOut != null)
            {
                minRowCount = minRowCount < rsiOut.Length ? minRowCount : rsiOut.Length;
            }
            if (williamsROut != null)
            {
                minRowCount = minRowCount < williamsROut.Length ? minRowCount : williamsROut.Length;
            }
            if (stochasticsOut != null)
            {
                minRowCount = minRowCount < stochasticsOut.Length ? minRowCount : stochasticsOut.Length;
            }
            if (closesOut != null)
            {
                minRowCount = minRowCount < closesOut.Length ? minRowCount : closesOut.Length;
            }

            var fv = new FeatureVector();

            if (isSMAChecked)
            {
                fv.AddColumn("SMA", smaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            }
            if (isWMAChecked)
            {
                fv.AddColumn("WMA", wmaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            }
            if (isEMAChecked)
            {
                fv.AddColumn("EMA", emaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            }
            if (isMACDChecked)
            {
                fv.AddColumn("MACD", macdOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            }
            if (isRSIChecked)
            {
                fv.AddColumn("RSI", rsiOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            }
            if (isWilliamsRChecked)
            {
                fv.AddColumn("WilliamsR", williamsROut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            }
            if (isStochasticsChecked)
            {
                fv.AddColumn("Stochastics", stochasticsOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            }
            fv.AddColumn("label", closesOut.Select(p => (object)string.Format("{0:0.0}", p).ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());

            var training = new FeatureVector();
            var test     = new FeatureVector();
            int count    = fv.Values[0].Length;

            for (int i = 0; i < fv.ColumnName.Count; i++)
            {
                training.AddColumn(fv.ColumnName[i], fv.Values[i].Take((int)(count * trainingSetPercentage)).ToArray());
            }

            for (int i = 0; i < fv.ColumnName.Count; i++)
            {
                test.AddColumn(fv.ColumnName[i], fv.Values[i].Skip((int)(count * trainingSetPercentage)).Take(count).ToArray()); // Take(count) means take the rest of all elements, number of the rest of the elements is smaller than count.
            }

            if (numFolds > 0)
            {
                BinaryClassificationEvaluator bce1    = new BinaryClassificationEvaluator();
                LinearRegression    linearRegression  = new LinearRegression();
                CrossValidator      cvLinReg          = new CrossValidator(linearRegression, bce1, numFolds);
                CrossValidatorModel cvLinRegModel     = (CrossValidatorModel)cvLinReg.Fit(training);
                FeatureVector       linRegPredictions = cvLinRegModel.transform(test);
                bce1.evaluate(linRegPredictions);
                linRegAcc = bce1.Accuracy;

                BinaryClassificationEvaluator bce2 = new BinaryClassificationEvaluator();
                LogisticRegression            logisticRegression = new LogisticRegression();
                CrossValidator      cvLogReg          = new CrossValidator(logisticRegression, bce2, numFolds);
                CrossValidatorModel cvLogRegModel     = (CrossValidatorModel)cvLogReg.Fit(training);
                FeatureVector       logRegPredictions = cvLogRegModel.transform(test);
                bce2.evaluate(logRegPredictions);
                logRegAcc = bce2.Accuracy;

                BinaryClassificationEvaluator bce3    = new BinaryClassificationEvaluator();
                NaiveBayes          naiveBayes        = new NaiveBayes();
                CrossValidator      cvNaiBay          = new CrossValidator(naiveBayes, bce3, numFolds);
                CrossValidatorModel cvNaiBayModel     = (CrossValidatorModel)cvNaiBay.Fit(training);
                FeatureVector       naiBayPredictions = cvNaiBayModel.transform(test);
                bce3.evaluate(naiBayPredictions);
                naiBayAcc = bce3.Accuracy;
            }
            else
            {
                BinaryClassificationEvaluator bce1          = new BinaryClassificationEvaluator();
                LinearRegression      linearRegression      = new LinearRegression();
                LinearRegressionModel linearRegressionModel = (LinearRegressionModel)linearRegression.Fit(training);
                FeatureVector         linRegPredictions     = linearRegressionModel.transform(test);
                bce1.evaluate(linRegPredictions);
                linRegAcc = bce1.Accuracy;

                BinaryClassificationEvaluator bce2 = new BinaryClassificationEvaluator();
                LogisticRegression            logicticRegression      = new LogisticRegression();
                LogisticRegressionModel       logisticRegressionModel = (LogisticRegressionModel)logicticRegression.Fit(training);
                FeatureVector logRegPredictions = logisticRegressionModel.transform(test);
                bce2.evaluate(logRegPredictions);
                logRegAcc = bce2.Accuracy;

                BinaryClassificationEvaluator bce3 = new BinaryClassificationEvaluator();
                NaiveBayes      naiveBayes         = new NaiveBayes();
                NaiveBayesModel naiveBayesModel    = (NaiveBayesModel)naiveBayes.Fit(training);
                FeatureVector   naiBayPredictions  = naiveBayesModel.transform(test);
                bce3.evaluate(naiBayPredictions);
                naiBayAcc = bce3.Accuracy;
            }

            labelForLinRegAcc.Text = linRegAcc.ToString();
            labelForLogRegAcc.Text = logRegAcc.ToString();
            labelForNaiBayAcc.Text = naiBayAcc.ToString();

            panelForResults.BringToFront();
        }
        private static void RunConsoleApplication()
        {
            string filePath = (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX) ? Environment.GetEnvironmentVariable("HOME") : Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");

            filePath += "\\indicatorOutput.txt";

            string   code       = "AKBNK";
            DateTime targetDate = new DateTime(2018, 11, 1).ToLocalTime();

            int numberOfData = 1000;

            var data = IndicatorService.GetData(code, targetDate, new string[] { "Tarih", "Kapanis" }, numberOfData + 1);

            double[] sma = MovingAverage.Simple(code, targetDate, 14, numberOfData);
            double[] wma = MovingAverage.Weighted(code, targetDate, 14, numberOfData);
            double[] ema = MovingAverage.Exponential(code, targetDate, 14, numberOfData);
            MovingAverageConvergenceDivergence macd = new MovingAverageConvergenceDivergence(code, targetDate, 12, 26, 9, numberOfData);

            double[]    rsi         = RelativeStrengthIndex.Rsi(code, targetDate, 14, numberOfData);
            double[]    williams    = WilliamsR.Wsr(code, targetDate, 14, numberOfData);
            Stochastics stochastics = new Stochastics(code, targetDate, 14, 3, 3, numberOfData);

            double[] closesOut      = IndicatorDataPreprocessor.GetClosesOut(numberOfData, data);
            double[] smaOut         = IndicatorDataPreprocessor.GetSMAOut(sma);
            double[] wmaOut         = IndicatorDataPreprocessor.GetWMAOut(wma);
            double[] emaOut         = IndicatorDataPreprocessor.GetEMAOut(ema);
            double[] macdOut        = IndicatorDataPreprocessor.GetMACDOut(macd);
            double[] rsiOut         = IndicatorDataPreprocessor.GetRSIOut(rsi);
            double[] williamsROut   = IndicatorDataPreprocessor.GetWilliamsROut(williams);
            double[] stochasticsOut = IndicatorDataPreprocessor.GetStochasticsOut(stochastics);

            int minRowCount;

            minRowCount = smaOut.Length;
            minRowCount = minRowCount < wmaOut.Length ? minRowCount : wmaOut.Length;
            minRowCount = minRowCount < emaOut.Length ? minRowCount : emaOut.Length;
            minRowCount = minRowCount < macdOut.Length ? minRowCount : macdOut.Length;
            minRowCount = minRowCount < rsiOut.Length ? minRowCount : rsiOut.Length;
            minRowCount = minRowCount < williamsROut.Length ? minRowCount : williamsROut.Length;
            minRowCount = minRowCount < stochasticsOut.Length ? minRowCount : stochasticsOut.Length;
            minRowCount = minRowCount < closesOut.Length ? minRowCount : closesOut.Length;
            FeatureVector vector = new FeatureVector();

            vector.AddColumn("SMA", smaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            vector.AddColumn("WMA", wmaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            vector.AddColumn("EMA", emaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            vector.AddColumn("MACD", macdOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            vector.AddColumn("RSI", rsiOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            vector.AddColumn("WilliamsR", williamsROut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            vector.AddColumn("Stochastics", stochasticsOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());
            vector.AddColumn("label", closesOut.Select(p => (object)string.Format("{0:0.0}", p).ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray());

            new LabeledPointExporter(vector).Export(filePath);

            int           count    = vector.Values[0].Length;
            FeatureVector training = new FeatureVector();

            for (int i = 0; i < vector.ColumnName.Count; i++)
            {
                training.AddColumn(vector.ColumnName[i], vector.Values[i].Take(count / 2).ToArray());
            }

            FeatureVector test = new FeatureVector();

            for (int i = 0; i < vector.ColumnName.Count; i++)
            {
                test.AddColumn(vector.ColumnName[i], vector.Values[i].Skip(count / 2).Take(count / 2).ToArray());
            }

            //TestNaiveBayes(training, test);
            //TestNaiveBayesUsingCrossValidation(training, test);
            //TestLinearRegression(training, test);
            //TestLinearRegressionUsingCrossValidation(training, test);
            //TestLogisticRegression(training, test);
            //TestLogisticRegressionUsingCrossValidation(training, test);
        }
        private static void RunFeatureSelector(int mlAlgorithm, bool isCrossValidationEnabled, double trainingSetPercentage)
        {
            string   code       = "AKBNK";
            DateTime targetDate = new DateTime(2018, 11, 1).ToLocalTime();

            int numberOfData = 4000;

            var data = IndicatorService.GetData(code, targetDate, new string[] { "Tarih", "Kapanis" }, numberOfData + 1);

            double[] sma = MovingAverage.Simple(code, targetDate, 14, numberOfData);
            double[] wma = MovingAverage.Weighted(code, targetDate, 14, numberOfData);
            double[] ema = MovingAverage.Exponential(code, targetDate, 14, numberOfData);
            MovingAverageConvergenceDivergence macd = new MovingAverageConvergenceDivergence(code, targetDate, 12, 26, 9, numberOfData);

            double[]    rsi         = RelativeStrengthIndex.Rsi(code, targetDate, 14, numberOfData);
            double[]    williams    = WilliamsR.Wsr(code, targetDate, 14, numberOfData);
            Stochastics stochastics = new Stochastics(code, targetDate, 14, 3, 3, numberOfData);

            double[] closesOut      = IndicatorDataPreprocessor.GetClosesOut(numberOfData, data);
            double[] smaOut         = IndicatorDataPreprocessor.GetSMAOut(sma);
            double[] wmaOut         = IndicatorDataPreprocessor.GetWMAOut(wma);
            double[] emaOut         = IndicatorDataPreprocessor.GetEMAOut(ema);
            double[] macdOut        = IndicatorDataPreprocessor.GetMACDOut(macd);
            double[] rsiOut         = IndicatorDataPreprocessor.GetRSIOut(rsi, false);
            double[] williamsROut   = IndicatorDataPreprocessor.GetWilliamsROut(williams, false);
            double[] stochasticsOut = IndicatorDataPreprocessor.GetStochasticsOut(stochastics, false);

            int minRowCount;

            minRowCount = smaOut.Length;
            minRowCount = minRowCount < wmaOut.Length ? minRowCount : wmaOut.Length;
            minRowCount = minRowCount < emaOut.Length ? minRowCount : emaOut.Length;
            minRowCount = minRowCount < macdOut.Length ? minRowCount : macdOut.Length;
            minRowCount = minRowCount < rsiOut.Length ? minRowCount : rsiOut.Length;
            minRowCount = minRowCount < williamsROut.Length ? minRowCount : williamsROut.Length;
            minRowCount = minRowCount < stochasticsOut.Length ? minRowCount : stochasticsOut.Length;
            minRowCount = minRowCount < closesOut.Length ? minRowCount : closesOut.Length;

            int numberOfIndicators   = IndicatorService.indicators.Length;
            int numberOfCombinations = (int)Math.Pow(2, numberOfIndicators) - 1;

            for (int i = 1; i <= numberOfCombinations; i++)
            {
                int        tmp        = i;
                List <int> indicators = new List <int>();
                for (int j = 0; j < numberOfIndicators; j++)
                {
                    if ((tmp & 1) == 1)
                    {
                        indicators.Add(IndicatorService.indicators[j]);
                    }
                    tmp >>= 1;
                }

                double accuracy = CalculateAccuracy(indicators, mlAlgorithm, isCrossValidationEnabled, minRowCount, trainingSetPercentage, smaOut, wmaOut, emaOut, macdOut, rsiOut, williamsROut, stochasticsOut, closesOut);
                if (indicators.Contains(IndicatorService.SMA))
                {
                    Console.Write("SMA ");
                }
                if (indicators.Contains(IndicatorService.WMA))
                {
                    Console.Write("WMA ");
                }
                if (indicators.Contains(IndicatorService.EMA))
                {
                    Console.Write("EMA ");
                }
                if (indicators.Contains(IndicatorService.MACD))
                {
                    Console.Write("MACD ");
                }
                if (indicators.Contains(IndicatorService.RSI))
                {
                    Console.Write("RSI ");
                }
                if (indicators.Contains(IndicatorService.WilliamsR))
                {
                    Console.Write("WilliamsR ");
                }
                if (indicators.Contains(IndicatorService.Stochastics))
                {
                    Console.Write("Stochastics ");
                }
                Console.WriteLine("=>\t" + accuracy);
            }
        }