Ejemplo n.º 1
0
 public AppGUI()
 {
     _stockRecordBUS = new StockRecordBUS();
     _stockRecordDTO = null;
     strPath = "";
     InitializeComponent();
 }
Ejemplo n.º 2
0
 public AppGUI()
 {
     _stockRecordBUS = new StockRecordBUS();
     _stockRecordDTO = null;
     strPath         = "";
     InitializeComponent();
 }
Ejemplo n.º 3
0
 public void LoadWholdeData(string fileName)
 {
     StockRecordBUS stockRecordBUS = new StockRecordBUS();
     WholeData = stockRecordBUS.LoadData(fileName);
 }
Ejemplo n.º 4
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (tbxCsvFilePath.Text == "" || cmbPreprocess.SelectedIndex < 0 || tbxNumInputNode.Text == "" || tbxTrainingRatio.Text == "")
            {
                MessageBox.Show("Error: You must fill all required inputs!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //1. Đọc dữ liệu từ file .csv vào mảng và tiền xử lý
            StockRecordBUS stockRecordBUS = new StockRecordBUS();
            StockRecordDTO stockRecordDTO = stockRecordBUS.LoadData(tbxCsvFilePath.Text);
            double[] dblSource = new double[stockRecordDTO.Entries.Count];
            int i = 0;
            foreach (EntryDTO entryDTO in stockRecordDTO.Entries)
            {
                dblSource[i] = entryDTO.ClosePrice;
                i++;
            }
            PreprocessBUS preprocessBUS = new PreprocessBUS();
            #region Phần riêng
            if (rdPricePrediction.Checked)//Dự đoán giá
            {
                if (rdSVR.Checked)//Mô hình SVR
                {
                    if (cmbPreprocess.SelectedItem.ToString() == "ScaleByMinMax")
                    {
                        preprocessBUS.FindMinMax(dblSource);
                        dblSource = preprocessBUS.PreprocessByMinMax(dblSource);
                    }
                }
                else//Mô hình ANN
                {
                    if (cmbPreprocess.SelectedItem.ToString() == "ScaleByMinMax")
                    {
                        preprocessBUS.FindMinMax(dblSource);
                        dblSource = preprocessBUS.PreprocessByMinMax(dblSource);
                    }
                }
            }
            else//Dự đoán xu hướng
            {
                if (rdSVR.Checked)//Mô hình SVR
                {
                    if (cmbPreprocess.SelectedItem.ToString() == "Return[-1,1]")
                    {
                        dblSource = preprocessBUS.Scale_SVR_Return(stockRecordDTO.Entries.Count, dblSource, 1, 1);
                    }
                }
                else//Mô hình ANN
                {
                    if (cmbPreprocess.SelectedItem.ToString() == "Return[-1,1]")
                    {
                        dblSource = preprocessBUS.Scale_SVR_Return(stockRecordDTO.Entries.Count, dblSource, 1, 1);
                    }
                }
            }
            #endregion

            //2. Chuyển sang định dạng của LibSVM (dựa vào số node đầu vào)
            ConverterBUS converter = new ConverterBUS();
            int iPos = tbxCsvFilePath.Text.LastIndexOf('\\');
            string strFolderPath = tbxCsvFilePath.Text.Remove(iPos+1);
            string strTotalFile = strFolderPath + stockRecordDTO.ID + ".txt";
            int iNumInputNode = Convert.ToInt32(tbxNumInputNode.Text);
            int numDaysPredicted = 1;
            int iNumLine = 0;

            if (cmbPreprocess.SelectedItem.ToString() == "Return[-1,1]")
            {
                if (int.TryParse(tbxNumDaysPredicted.Text,out numDaysPredicted))
                {
                    converter.ConvertForTrend(int.Parse(tbxNumDaysPredicted.Text), iNumInputNode, dblSource, strTotalFile, out iNumLine, 2, false);
                }
                else
                {
                    MessageBox.Show("Please enter a number");
                    return;
                }
            }
            else
            {
                if(ckbImproveDirection.Checked)
                {
                    double dblTrainPercent = Convert.ToDouble(tbxTrainingRatio.Text);
                    converter.ConvertWImprovedDirection(iNumInputNode, dblSource, strTotalFile, dblTrainPercent, out iNumLine);
                }
                else
                {
                    converter.Convert(iNumInputNode, dblSource, strTotalFile, out iNumLine);
                }
            }
            //3. Từ file chứa toàn bộ dữ liệu ta phân phối vào 2 file train và test (dựa vào tỉ lệ bộ train)
            string strTrainFile = strFolderPath + stockRecordDTO.ID + "_" + numDaysPredicted + "_train.txt";
            string strTestFile = strFolderPath + stockRecordDTO.ID + "_" + numDaysPredicted + "_test.txt";
            StreamReader reader = new StreamReader(strTotalFile);
            StreamWriter trainWriter = new StreamWriter(strTrainFile);
            StreamWriter testWriter = new StreamWriter(strTestFile);

            //Ghi phương thức xử lý vào dòng đầu tiên của file test
            //Mục đích là để ta có thể chuyển về dữ liệu nguyên thủy
            testWriter.WriteLine(cmbPreprocess.SelectedItem.ToString() + " " + preprocessBUS.Min.ToString() + " " + preprocessBUS.Max.ToString());

            double dblTrainingSetRatio = Convert.ToDouble(tbxTrainingRatio.Text);
            //int iBound = numDaysPredicted > iNumInputNode ? 2 * numDaysPredicted : numDaysPredicted + iNumInputNode;
            //int iNumLine = dblSource.Length - iBound + 1;
            int iDivideLine = (int)(dblTrainingSetRatio * iNumLine/100);
            for (i = 0; i < iDivideLine; i++)
            {
                string strLine = reader.ReadLine();
                trainWriter.WriteLine(strLine);
            }
            for (; i < iNumLine; i++)
            {
                string strLine = reader.ReadLine();
                testWriter.WriteLine(strLine);
            }

            testWriter.Close();
            trainWriter.Close();
            reader.Close();

            MessageBox.Show("Finish!");
        }
Ejemplo n.º 5
0
        private void MainGUI_Load(object sender, EventArgs e)
        {
            //Khởi gán
            cmbPreprocess.SelectedIndex = 0;
            tbxNumInputNode.Text = "5";
            tbxTrainingRatio.Text = "80";
            cmbModelSelection.SelectedIndex = 0;
            cmbTrainingMeasure.SelectedIndex = 0;

            //Khởi gán tham số ANN
            tbxNumInputNode.Text = 5.ToString();
            tbxANNHiddenNode.Text = 4.ToString();
            tbxLearningRate.Text = 0.3.ToString();
            tbxMaxLoops.Text = 2000.ToString();
            tbxBias.Text = 0.ToString();
            tbxMomentum.Text = 0.01.ToString();

            if (rdANN.Checked == true)
            {
                gbAnnSetting.Enabled = true;
            }
            else
            {
                gbAnnSetting.Enabled = false;
            }

            _stockRecordBUS = new StockRecordBUS();
            _stockRecordDTO = null;
            strStockPath = "";
        }
Ejemplo n.º 6
0
        private void SaveLastUpdateDate(List<string> listStockIdUpdate)
        {
            StockRecordBUS srbuss = new StockRecordBUS();

            for (int i = 0; i < listStockIdUpdate.Count; i++)
            {
                StockRecordDTO srdto = srbuss.LoadData(_updateFolder + listStockIdUpdate[i].ToLower() + ".csv");
                //listStockIdUpdate[i] = _updateFolder + listStockIdUpdate[i].ToLower() + ".csv";
                EntryDTO entry = (EntryDTO)srdto.Entries[srdto.Entries.Count - 1];
                StreamWriter rw = new StreamWriter(_updateFolder + listStockIdUpdate[i].ToLower() + "_lastupdate.txt");
                rw.WriteLine(entry.Date.ToString());
                rw.Close();
            }
        }
Ejemplo n.º 7
0
        private void Preprocess(bool isBatchMode)
        {
            string strInputFile = null;
            double dblTrainingSetRatio = 0;

            if (isBatchMode)
            {
                strInputFile = tbxBatchInputFile.Text;
                dblTrainingSetRatio = Convert.ToDouble(tbxTrainingRatio.Text);
            }
            else
            {
                strInputFile = tbxCsvFilePath.Text;
                dblTrainingSetRatio = Convert.ToDouble(tbxTrainingRatio.Text);
            }
            //1. Đọc dữ liệu từ file .csv vào mảng và tiền xử lý
            StockRecordBUS stockRecordBUS = new StockRecordBUS();
            StockRecordDTO stockRecordDTO = stockRecordBUS.LoadData(strInputFile);

            _stockRecordDTO = stockRecordDTO;

            double[] dblClosePrices = new double[stockRecordDTO.Entries.Count];
            double[] dblVolumes = new double[stockRecordDTO.Entries.Count];
            int i = 0;
            foreach (EntryDTO entryDTO in stockRecordDTO.Entries)
            {
                dblClosePrices[i] = entryDTO.ClosePrice;
                dblVolumes[i] = entryDTO.Volume;
                i++;
            }

            //2. Chuyển sang định dạng của LibSVM (dựa vào số node đầu vào)
            ConverterBUS converter = new ConverterBUS();
            int iPos = strInputFile.LastIndexOf('\\');
            string strFolderPath = strInputFile.Remove(iPos + 1);
            string strTotalFile = strFolderPath + stockRecordDTO.ID;
            int numDaysPredicted = Int32.Parse(cmbNumDaysPredicted.Text);
            int iNumLine = 0;

            ConverterBUS.Convert(dblClosePrices, dblVolumes, numDaysPredicted, strTotalFile, out iNumLine);

            //3. Từ file chứa toàn bộ dữ liệu ta phân phối vào 2 file train và test (dựa vào tỉ lệ bộ train)
            string strTrainFile = strFolderPath + stockRecordDTO.ID + "_" + numDaysPredicted + "_train.txt";
            string strTestFile = strFolderPath + stockRecordDTO.ID + "_" + numDaysPredicted + "_test.txt";
            string strDTTrainFile = strFolderPath + stockRecordDTO.ID + "_" + numDaysPredicted + "_train.data.txt";
            string strDTTestFile = strFolderPath + stockRecordDTO.ID + "_" + numDaysPredicted + "_test.data.txt";

            StreamReader reader = new StreamReader(strTotalFile + ".txt");
            StreamReader dtReader = new StreamReader(strTotalFile + ".data");
            StreamWriter trainWriter = new StreamWriter(strTrainFile);
            StreamWriter testWriter = new StreamWriter(strTestFile);
            StreamWriter dtTrainWriter = new StreamWriter(strDTTrainFile);
            StreamWriter dtTestWriter = new StreamWriter(strDTTestFile);

            string SubTrainFile = null;
            string SubTestFile = null;
            string dtannSubTrainFile = null;
            string dtannSubTestFile = null;

            StreamWriter SubTrainWriter = null;
            StreamWriter SubTestWriter = null;
            StreamWriter dtannSubTrainWriter = null;
            StreamWriter dtannSubTestWriter = null;
            if (rdDTANN.Checked == true)
            {
                SubTrainFile = strFolderPath + stockRecordDTO.ID + "_" + numDaysPredicted + "_train_subtrain.txt";
                SubTestFile = strFolderPath + stockRecordDTO.ID + "_" + numDaysPredicted + "_train_subtest.txt";

                dtannSubTrainFile = strFolderPath + stockRecordDTO.ID + "_" + numDaysPredicted + "_train_subtrain.data.txt";
                dtannSubTestFile = strFolderPath + stockRecordDTO.ID + "_" + numDaysPredicted + "_train_subtest.data.txt";

                SubTrainWriter = new StreamWriter(SubTrainFile);
                SubTestWriter = new StreamWriter(SubTestFile);
                dtannSubTrainWriter = new StreamWriter(dtannSubTrainFile);
                dtannSubTestWriter = new StreamWriter(dtannSubTestFile);
            }

            //int iBound = numDaysPredicted > iNumInputNode ? 2 * numDaysPredicted : numDaysPredicted + iNumInputNode;
            //int iNumLine = dblSource.Length - iBound + 1;
            int iDivideLine = (int)(dblTrainingSetRatio * iNumLine / 100);
            int iSudDevideLine = (int)(90 * iDivideLine / 100);
            for (i = 0; i < iDivideLine; i++)
            {
                string strLine = reader.ReadLine();
                trainWriter.WriteLine(strLine);
                if (rdDTANN.Checked == true)
                {
                    if (i < iSudDevideLine)// Phân bổ cho tập train con
                    {
                        SubTrainWriter.WriteLine(strLine);
                    }
                    else// Phân bổ cho tập test con
                    {
                        SubTestWriter.WriteLine(strLine);
                    }
                }

                strLine = dtReader.ReadLine();
                dtTrainWriter.WriteLine(strLine);
                if (rdDTANN.Checked == true)
                {
                    if (i < iSudDevideLine)// Phân bổ cho tập train con
                    {
                        dtannSubTrainWriter.WriteLine(strLine);
                    }
                    else// Phân bổ cho tập test con
                    {
                        dtannSubTestWriter.WriteLine(strLine);
                    }
                }
            }
            for (; i < iNumLine; i++)
            {
                string strLine = reader.ReadLine();
                testWriter.WriteLine(strLine);
                strLine = dtReader.ReadLine();
                dtTestWriter.WriteLine(strLine);
            }

            testWriter.Close();
            trainWriter.Close();
            dtTestWriter.Close();
            dtTrainWriter.Close();
            reader.Close();
            dtReader.Close();

            if (rdDTANN.Checked == true)
            {
                SubTrainWriter.Close();
                SubTestWriter.Close();
                dtannSubTrainWriter.Close();
                dtannSubTestWriter.Close();
            }
        }
Ejemplo n.º 8
0
        private void MainGUI_Load(object sender, EventArgs e)
        {
            //Khởi gán
            cmbNumDaysPredicted.SelectedIndex = 0;
            tbxTrainingRatio.Text = "80";
            cmbModelSelection.SelectedIndex = 0;
            cmbActivationFunc.SelectedIndex = 0;
            cmbExperimentMode.SelectedIndex = 0;
            cmbPruneFunc.SelectedIndex = 0;
            cmbSplitFunc.SelectedIndex = 0;
            cmbChoseMethods.SelectedIndex = 0;
            //cmbSAStockID.SelectedIndex = 0;

            _trainFilePath = "";
            _testFilePath = "";
            _modelFilePath = "";

            //Khởi gán tham số ANN
            tbxANNHiddenNode.Text = 4.ToString();
            tbxLearningRate.Text = 0.3.ToString();
            tbxMaxLoops.Text = 2000.ToString();
            tbxBias.Text = 0.ToString();
            tbxMomentum.Text = 0.01.ToString();

            if (rdANN.Checked == true)
            {
                gbAnnSetting.Enabled = true;
                gbSVRSetting.Enabled = false;
                gbDTSetting.Enabled = false;
                gbKmeansSetting.Enabled = false;
            }

            _stockRecordBUS = new StockRecordBUS();
            _stockRecordDTO = null;

            _stockSARecordBUS = new StockRecordBUS();
            _stockSARecordDTO = null;

            _stockAppPath = "";

            tbxChoseFolder.Visible = false;
            btnChoseFolder.Visible = false;

             _defautFolder = (System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName).Replace(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].Name, "");
             _updateFolder = _defautFolder + "DataUpdate\\";
             _trainModel = _defautFolder + "AppModel\\";
             _suggestionFolder = _defautFolder + "Suggestion\\";
             _defautFolder = _defautFolder + "Data\\";

            LoadStockIdFromFolder(_defautFolder);
        }
Ejemplo n.º 9
0
 public Form1()
 {
     _stockRecordBUS = new StockRecordBUS();
     _stockRecordDTO = null;
     InitializeComponent();
 }