Esempio n. 1
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);
            }
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
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);
            //}
        }