Example #1
0
        // Async run helper function
        public bool GeneratePrediction(PredictionGenerator predictor, BackgroundWorker worker)
        {
            predictor.RecursiveGetPredictions(Int32.Parse(predictIntervalsBox.Text));
            string predictionDataPrintoutFile = DEFAULTDIRECTORY + "\\PredictionData_" + DateTime.Now.Month.ToString() + "-" +
                                                DateTime.Now.Day.ToString() + "-" + DateTime.Now.Year.ToString() + "_" + DateTime.Now.Hour.ToString() +
                                                DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + ".csv";

            predictor.WriteDataToCSV(predictionDataPrintoutFile);
            return(true);
        }
        // Public objects
        //reserved

        // Default Class Constructor
        public StockTraderEvolutionChamber(string futureMarketDataFilePath, string trainingDataFilePath, float tradeCost)
        {
            perTradeFee = tradeCost;
            try
            {
                using (FileStream stream = new FileStream(futureMarketDataFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        // Initialize the full market
                        string   line   = reader.ReadLine();
                        string[] values = line.Split(',');
                        // Populate the history of market values that will be used
                        while (!reader.EndOfStream)
                        {
                            line   = reader.ReadLine();
                            values = line.Split(',');
                            float[] prices = new float[values.Length - 1];
                            for (int i = 1; i < values.Length; i++)
                            {
                                prices[i - 1] = Single.Parse(values[i]);
                                if ((prices[i - 1] != 0.0f) && (!order.Contains(i - 1)))
                                {
                                    order.Add(i - 1);
                                }
                            }
                            stockPrices.Add(prices);
                        }
                    }
                }
            }
            catch (Exception)
            {
                System.Windows.Forms.MessageBox.Show("Stock Data History file format incorrect.");
            }

            predictor = new PredictionGenerator(trainingDataFilePath);
        }
Example #3
0
        // Method to handle clicking the Prediction button
        private void predictionButton_Click(object sender, EventArgs e)
        {
            if (trainingDataPrintoutFile == null)
            {
                System.Windows.Forms.MessageBox.Show("Invalid training data file path. Please select a formatted " +
                                                     "stock data file or run the downloader to generate one.");
                OpenFileDialog selectFileDialog = new OpenFileDialog();
                if (DEFAULTDIRECTORY == String.Empty)
                {
                    selectFileDialog.InitialDirectory = "C:\\";
                }
                else
                {
                    selectFileDialog.InitialDirectory = DEFAULTDIRECTORY;
                }
                selectFileDialog.Filter      = "sdp files (*.sdp)|*.sdp";
                selectFileDialog.FilterIndex = 1;

                if (selectFileDialog.ShowDialog() == DialogResult.OK)
                {
                    trainingDataPrintoutFile = selectFileDialog.FileName;
                    DEFAULTDIRECTORY         = trainingDataPrintoutFile.Trim().Remove(trainingDataPrintoutFile.LastIndexOf(@"\"));
                    outputFilePath           = DEFAULTDIRECTORY;
                }
                else
                {
                    return;
                }
            }

            PredictionGenerator predictor = new PredictionGenerator(trainingDataPrintoutFile);

            predictionButton.Enabled = false;

            predictionBackgroundWorker.RunWorkerAsync(predictor);
        }