Пример #1
0
        // Async run helper function
        public bool EvolveTrader(StockTraderEvolutionChamber chamber, BackgroundWorker worker)
        {
            List <float> bestTraderData = new List <float>(chamber.RunEvolution(Int32.Parse(genCountBox.Text), Int32.Parse(genSizeBox.Text), Single.Parse(mutationRateBox.Text)));

            // Write bestTrader history results to file
            using (StreamWriter writer = new StreamWriter(DEFAULTDIRECTORY + "\\BestTraderPerformance_" + 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"))
            {
                writer.Write("PortfolioValue\r\n");
                foreach (float d in bestTraderData)
                {
                    writer.Write(d.ToString() + "\r\n");
                }
            }
            return(true);
        }
Пример #2
0
        // Method to handle clicking the Evolve button
        private void evolveButton_Click(object sender, EventArgs e)
        {
            if (stockDataPrintoutFile == null)
            {
                System.Windows.Forms.MessageBox.Show("Invalid stock 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)
                {
                    stockDataPrintoutFile = selectFileDialog.FileName;
                    DEFAULTDIRECTORY      = stockDataPrintoutFile.Trim().Remove(stockDataPrintoutFile.LastIndexOf(@"\"));
                    outputFilePath        = DEFAULTDIRECTORY;
                }
                else
                {
                    return;
                }
            }
            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;
                }
            }

            StockTraderEvolutionChamber chamber = new StockTraderEvolutionChamber(stockDataPrintoutFile, trainingDataPrintoutFile, Single.Parse(tradeFeeBox.Text));

            evolveButton.Enabled = false;

            evolveBackgroundWorker.RunWorkerAsync(chamber);
        }