Beispiel #1
0
        private void sim_item_grid_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try {
                int rowIndex = sim_item_grid.CurrentRow.Index;
                if (Run_sim_Flag == false)
                {
                    default_code = sim_item_grid.Rows[rowIndex].Cells[0].Value.ToString();
                    LogTextset("유사도", "종목 선택 완료");
                    if (EndDayFlag && StartDayFlag)
                    {
                        Stock_var stock = new Stock_var();
                        marketdb  DB    = new marketdb();

                        stock.daily_data = DB.get_daily_price(default_code, StartDay, EndDay);

                        double min = Convert.ToDouble(stock.daily_data.AsEnumerable().Min(row => row["close"]));
                        double max = Convert.ToDouble(stock.daily_data.AsEnumerable().Max(row => row["close"]));
                        min = min * 0.95;
                        max = max * 1.05;
                        default_graph.Series[0].Name = sim_item_grid.Rows[rowIndex].Cells[1].Value.ToString();
                        default_graph.DataSource     = stock.daily_data;
                        default_graph.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineWidth = 1;
                        default_graph.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineWidth = 1;
                        if (max != min)
                        {
                            default_graph.ChartAreas["ChartArea1"].AxisY.Maximum = max;
                            default_graph.ChartAreas["ChartArea1"].AxisY.Minimum = min;
                        }
                        default_graph.Series[0].XValueType        = ChartValueType.Date;
                        default_graph.Series[0].XValueMember      = "date";
                        default_graph.Series[0].IsXValueIndexed   = true;
                        default_graph.Series[0].YValueMembers     = "high,low,open,close";
                        default_graph.Series[0].CustomProperties  = "PriceDownColor=Blue,PriceUpColor=Red";
                        default_graph.Series[0]["OpenCloseStyle"] = "Triangle";
                        default_graph.Series[0]["ShowOpenClose"]  = "Both";
                        default_graph.DataBind();
                    }
                    defaultcodeFlag = true;
                }
            }
            catch (Exception ex) {
                Console.WriteLine("Item_grid_CellClick error");
                Console.WriteLine(ex);
            }
        }
Beispiel #2
0
        public void item_grid_fill()
        {
            try {
                Stock_var stock           = new Stock_var();
                marketdb  DB              = new marketdb();
                string    item_search_str = sim_search_text.Text;

                stock.company_info = DB.get_company_info_search(item_search_str); // 검색 버튼을 눌렀을 경우 item_search_str을 정해줌

                foreach (KeyValuePair <string, string> pair in stock.company_info)
                {
                    sim_item_grid.Rows.Add(pair.Key, pair.Value);   //  ui를 건드리므로, invoke씀
                }
            }
            catch {
                return;
            }
        }
Beispiel #3
0
        private void sim_result_grid_key(object sender, KeyEventArgs e)
        {
            try {
                if (e.KeyCode.Equals(Keys.Up) || e.KeyCode.Equals(Keys.Down))
                {
                    Stock_var stock = new Stock_var();
                    marketdb  DB    = new marketdb();
                    stock.company_info = DB.get_company_info();

                    int    rowIndex    = sim_result_grid.CurrentRow.Index;
                    string target_code = sim_result_grid.Rows[rowIndex].Cells[0].Value.ToString();


                    if (EndDayFlag && StartDayFlag)
                    {
                        stock.daily_data                     = DB.get_daily_price(stock.company_info.FirstOrDefault(x => x.Value == target_code).Key, StartDay, EndDay);
                        target_graph.Series[0].Name          = sim_result_grid.Rows[rowIndex].Cells[0].Value.ToString();
                        target_graph.DataSource              = stock.daily_data;
                        target_graph.Series[0].XValueType    = ChartValueType.DateTime;
                        target_graph.Series[0].XValueMember  = "date";
                        target_graph.Series[0].YValueMembers = "close";

                        target_graph.DataBind();

                        double min = Convert.ToDouble(stock.daily_data.AsEnumerable().Min(row => row["close"]));
                        double max = Convert.ToDouble(stock.daily_data.AsEnumerable().Max(row => row["close"]));

                        min = min * 0.8;
                        max = max * 1.2;

                        if (max != min)
                        {
                            target_graph.ChartAreas[0].AxisY.Minimum = min;
                            target_graph.ChartAreas[0].AxisY.Maximum = max;
                        }
                    }
                }
            }
            catch (Exception ex) {
                Console.WriteLine("Item_grid_CellClick error");
                Console.WriteLine(ex);
            }
        }
Beispiel #4
0
        private void sim_result_grid_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try {
                Stock_var stock = new Stock_var();
                marketdb  DB    = new marketdb();
                stock.company_info = DB.get_company_info();

                int    rowIndex    = sim_result_grid.CurrentRow.Index;
                string target_code = sim_result_grid.Rows[rowIndex].Cells[0].Value.ToString();


                if (EndDayFlag && StartDayFlag)
                {
                    stock.daily_data = DB.get_daily_price(stock.company_info.FirstOrDefault(x => x.Value == target_code).Key, StartDay, EndDay);

                    double min = Convert.ToDouble(stock.daily_data.AsEnumerable().Min(row => row["close"]));
                    double max = Convert.ToDouble(stock.daily_data.AsEnumerable().Max(row => row["close"]));
                    min = min * 0.8;
                    max = max * 1.2;
                    target_graph.Series[0].Name = sim_result_grid.Rows[rowIndex].Cells[0].Value.ToString();
                    target_graph.DataSource     = stock.daily_data;
                    target_graph.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineWidth = 1;
                    target_graph.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineWidth = 1;
                    if (max != min)
                    {
                        target_graph.ChartAreas["ChartArea1"].AxisY.Maximum = max;
                        target_graph.ChartAreas["ChartArea1"].AxisY.Minimum = min;
                    }
                    target_graph.Series[0].XValueType        = ChartValueType.Date;
                    target_graph.Series[0].XValueMember      = "date";
                    target_graph.Series[0].IsXValueIndexed   = true;
                    target_graph.Series[0].YValueMembers     = "high,low,open,close";
                    target_graph.Series[0].CustomProperties  = "PriceDownColor=Blue,PriceUpColor=Red";
                    target_graph.Series[0]["OpenCloseStyle"] = "Triangle";
                    target_graph.Series[0]["ShowOpenClose"]  = "Both";
                    target_graph.DataBind();
                }
            }
            catch (Exception ex) {
                Console.WriteLine("Item_grid_CellClick error");
                Console.WriteLine(ex);
            }
        }
Beispiel #5
0
        public void corr_calc()
        {
            Run_sim_Flag = true;

            Stock_var d_stk   = new Stock_var();
            marketdb  dtw_db  = new marketdb();
            Stock_var tar_stk = new Stock_var();
            //double[] d_pip = null;
            //double[] t_pip = null;

            //int pip_len;
            int    pct     = 0;
            int    bar_cnt = 0;
            double result  = 0;

            d_stk.company_info = dtw_db.get_company_info();
            d_stk.daily_data   = dtw_db.get_daily_price(default_code, StartDay, EndDay);

            object[] d_stk_arr         = d_stk.daily_data.Select().Select(x => x["close"]).ToArray();
            int[]    d_stk_arr_int     = d_stk_arr.Cast <int>().ToArray();
            double[] d_stk_arr_Scaling = Normalization.FeatureScaling(d_stk_arr_int);


            //pip_len = d_stk_arr_Scaling.Length < 700 ? 100 :
            //   d_stk_arr_Scaling.Length < 250 ? 75 :
            //   d_stk_arr_Scaling.Length < 120 ? 60 :
            //   d_stk_arr_Scaling.Length < 100 ? 50 :
            //   d_stk_arr_Scaling.Length < 60 ? 30 : 30;
            //Console.WriteLine(pip_len);



            //d_pip = Representation.PIP_VD(d_stk_arr_Scaling, pip_len);

            Parallel.ForEach(d_stk.company_info, cur_info => {
                try {
                    tar_stk.daily_data = dtw_db.get_daily_price(cur_info.Key, StartDay, EndDay);
                    object[] t_stk_arr = tar_stk.daily_data.Select().Select(x => x["close"]).ToArray();

                    int[] t_stk_arr_Int        = t_stk_arr.Cast <int>().ToArray();
                    double[] t_stk_arr_Scaling = Normalization.FeatureScaling(t_stk_arr_Int);
                    //t_pip = Representation.PIP_VD(t_stk_arr_Scaling, pip_len);

                    result = SimilarityMeasure.corr(d_stk_arr_Scaling, t_stk_arr_Scaling);
                    //result = SimilarityMeasure.corr(d_pip, t_pip);
                    //result = SimilarityMeasure.GetDynamicTimeWarpDistance(d_pip, t_pip);
                    if (result > 0.89)
                    {
                        sim_result_dict.Add(cur_info.Value, result);

                        if (InvokeRequired)
                        {
                            Invoke(new Action(delegate() {
                                sim_result_grid.Rows.Add(cur_info.Value, sim_result_dict[cur_info.Value]);
                            }));
                        }
                    }


                    pct = ((++bar_cnt * 100) / d_stk.company_info.Count);
                    if (pct >= 100)
                    {
                        pct = 100;
                    }
                    if (InvokeRequired)
                    {
                        Invoke(new Action(delegate() {
                            sim_bar.Value = pct;
                        }));
                    }
                }
                catch {
                    ++bar_cnt;
                }
            });

            //foreach (KeyValuePair<string, double> pair in sim_result_dict ) {
            //    sim_result_grid.Rows.Add(pair.Key, pair.Value);
            //}
        }