Ejemplo n.º 1
0
        public static void ProcessUpdateMMTest(Server svr, string strStockCode, bool bCon)
        {
            Database db = svr.Databases.GetByName("StockPredict");

            Microsoft.AnalysisServices.MiningStructure ms = db.MiningStructures.FindByName(strStockCode);

            string            strMsg, strCap;
            MessageBoxButtons buttons = MessageBoxButtons.OK;

            if (ms == null)
            {
                strMsg = "Cấu trúc dự báo cho cổ phiếu này không tồn tại!";
                strCap = "Mining Structure";
                // Displays the MessageBox.
                MessageBox.Show(strMsg, strCap, buttons, MessageBoxIcon.Error);
                return;
            }

            Microsoft.AnalysisServices.MiningModel mm = ms.MiningModels.FindByName(strStockCode);
            if (mm == null)
            {
                strMsg = "Mô hình dự báo cho cổ phiếu này không tồn tại!";
                strCap = "Mining Model";
                // Displays the MessageBox.
                MessageBox.Show(strMsg, strCap, buttons, MessageBoxIcon.Error);
                return;
            }


            // Check exist table: CR
            ADOMDLib.ExistExpandTable(strStockCode, "_CRT", bCon);

            // Initial parameters
            DefaultParam(strStockCode);

            // Get ToDate from StockForecastModel
            SqlConnection cn = new SqlConnection(str_Con_SQL);

            cn.Open();
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = cn;
            cmd.CommandText = "SELECT ToDate FROM StockForecastModel WHERE StockCode='" + strStockCode + "'";
            SqlDataReader rdr = cmd.ExecuteReader();

            rdr.Read();
            DateTime dtTo = rdr.GetDateTime(0);

            rdr.Close();
            cn.Close();

            // Loop mining
            while (AUTO_DETECT_PERIODICITY < 0.95)
            {
                while (COMPLEXITY_PENALTY < 0.95)
                {
                    while (HISTORIC_MODEL_COUNT < 3)
                    {
                        while (HISTORIC_MODEL_GAP < 15)
                        {
                            if (!UpdateMMTest(mm, strStockCode, dtTo))
                            {
                                // Update parameters into StockForecastModel
                                UpdateForecastModel(strStockCode);
                                return;
                            }
                            HISTORIC_MODEL_GAP++;
                        }
                        HISTORIC_MODEL_GAP = i_Save_HMG;
                        HISTORIC_MODEL_COUNT++;
                    }
                    HISTORIC_MODEL_COUNT = 1;
                    COMPLEXITY_PENALTY  += 0.05;
                }
                COMPLEXITY_PENALTY       = 0.05;
                AUTO_DETECT_PERIODICITY += 0.05;
            }

            // Get the best parameters
            UpdateMMTest(mm, strStockCode, dtTo);
            GetBestParamTest(strStockCode);
            UpdateForecastModel(strStockCode);
        }
Ejemplo n.º 2
0
        public static void ProcessUpdateMM(Server svr, string strStockCode, bool bCon)
        {
            Database db = svr.Databases.GetByName("StockPredict");

            Microsoft.AnalysisServices.MiningStructure ms = db.MiningStructures.FindByName(strStockCode);

            string            strMsg, strCap;
            MessageBoxButtons buttons = MessageBoxButtons.OK;

            if (ms == null)
            {
                strMsg = "Cấu trúc dự báo cho cổ phiếu này không tồn tại!";
                strCap = "Mining Structure";
                // Displays the MessageBox.
                MessageBox.Show(strMsg, strCap, buttons, MessageBoxIcon.Error);
                return;
            }

            Microsoft.AnalysisServices.MiningModel mm = ms.MiningModels.FindByName(strStockCode);
            if (mm == null)
            {
                strMsg = "Mô hình dự báo cho cổ phiếu này không tồn tại!";
                strCap = "Mining Model";
                // Displays the MessageBox.
                MessageBox.Show(strMsg, strCap, buttons, MessageBoxIcon.Error);
                return;
            }


            // Check exist table: CR
            ADOMDLib.ExistExpandTable(strStockCode, "_CR", bCon);

            // Initial parameters and get count of IDs
            int iCount_ID = InitialParameters(strStockCode);

            // Loop mining
            while (AUTO_DETECT_PERIODICITY < 0.95)
            {
                while (COMPLEXITY_PENALTY < 0.95)
                {
                    while (HISTORIC_MODEL_COUNT < 3)
                    {
                        while (HISTORIC_MODEL_GAP < 15)
                        {
                            HISTORIC_MODEL_GAP++;
                            if (!UpdateMM(mm, strStockCode, false))
                            {
                                // back to previous
                                //HISTORIC_MODEL_GAP--;
                                //UpdateMM(mm, strStockCode, true);
                                // Update parameters into StockForecastModel
                                UpdateForecastModel(strStockCode);
                                return;
                            }
                        }
                        HISTORIC_MODEL_GAP = i_Save_HMG;
                        HISTORIC_MODEL_COUNT++;
                    }
                    HISTORIC_MODEL_COUNT = 1;
                    COMPLEXITY_PENALTY  += 0.05;
                }
                COMPLEXITY_PENALTY       = 0.05;
                AUTO_DETECT_PERIODICITY += 0.05;
            }
            // Get the best parameters
            // Get the best parameters
            UpdateMM(mm, strStockCode, false);
            GetBestParam(strStockCode);
            UpdateForecastModel(strStockCode);
        }