コード例 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            CorpListManager.CalcVoratility();
            String[] delclms = new String[] { "33gyousyuCode",
                                              "17gyousyuCode",
                                              "17gyousyuClass",
                                              "kiboCode",
                                              "kiboClass" };
            foreach (var clm in delclms)
            {
                if (CorpListManager.dtCache.Columns.Contains(clm))
                {
                    CorpListManager.dtCache.Columns.Remove(clm);
                }
            }

            if (!(CorpListManager.dtCache.Columns.Contains("ボラティリティ")))
            {
                CorpListManager.dtCache.Columns.Add("ボラティリティ", typeof(double));
            }

            foreach (DataRow dr in CorpListManager.dtCache.Rows)
            {
                dr["ボラティリティ"] = CorpListManager.CorpCache.Get(dr.Field <int>("corpCode")).volatility;
            }

            dataGridView1.DataSource = CorpListManager.dtCache;
        }
コード例 #2
0
        public static void RefreshCache2(System.DateTime Bgn)
        {
            /////////////////////////////////
            Stopwatch sw_dic = new Stopwatch();

            ///////////////////////
            sw_dic.Start();

            //各種オブジェクトの作成
            DataTable dt_list   = new DataTable();
            DataTable dt_counts = new DataTable();

            if (CorpListManager.CorpCache.KeyLength() == 0)
            {
                CorpListManager.RefreshCache();                                             //CorpListへ企業情報を格納する。
            }
            //dt_listに全株価情報を取得
            String fltr = "where (date > '" + Bgn.ToString("yyyy-mm-dd") + "') AND (corpCode <10000) ";

            dt_list = SQLManager.SendSQL("select * from t_yahoofdata " + fltr + "GROUP BY corpCode ASC, date ASC;");

            dt_counts = SQLManager.SendSQL(
                "SELECT corpCode, COUNT(date) FROM t_yahoofdata " + fltr + " GROUP BY corpCode;");

            ////////////////////////////////
            sw_dic.Stop();

            //////////////////////
            Stopwatch sw_linq = new Stopwatch();
            Stopwatch sw_copy = new Stopwatch();

            //CorpListから
            int startpoint = 0;
            int count      = 0;

            foreach (var code in CorpListManager.CorpCache.Keys())
            {
                object[] obj_count = (from row in dt_counts.AsEnumerable()
                                      where (int)row[0] == code
                                      select row[1]).ToArray(); //切り取り終了行数を設定
                count = Convert.ToInt32(obj_count[0]);

                ////////////////////////
                sw_linq.Start();

                //startpointからcountだけデータを切り取る
                DataRow[] dr_rows = dt_list.AsEnumerable().Skip(startpoint).Take(count).ToArray();
                startpoint += count;

                ///////////////////////
                sw_linq.Stop();

                OHLCSeries sd_temp = new OHLCSeries(dr_rows.Length);//一時変数は銘柄ごとに作り直し

                ///////////////////////
                sw_copy.Start();

                //SQLManager.DataTableDump(ref dt_list, "List.txt");//dumpテスト

                for (int i = 0; i < dr_rows.Length; i++)
                {
                    if ((int)dr_rows[i]["corpCode"] != code)
                    {
                        sw_copy.Stop();
                        MessageBox.Show("Refresh()で切り取り行数が一致しませんでした。\n corpcode: " + code.ToString());
                        SQLManager.DataTableDump(ref dt_list, "List.txt");
                        SQLManager.DataTableDump(ref dt_counts, "Counts.txt");
                        return;
                    }
                    sd_temp.data[i].date      = (DateTime)dr_rows[i]["Date"];
                    sd_temp.data[i].open      = Convert.ToDouble(dr_rows[i]["open"]);
                    sd_temp.data[i].close     = Convert.ToDouble(dr_rows[i]["adj_close"]); //終値は修正後終値を使用
                    sd_temp.data[i].high      = Convert.ToDouble(dr_rows[i]["high"]);
                    sd_temp.data[i].low       = Convert.ToDouble(dr_rows[i]["low"]);
                    sd_temp.data[i].adj_close = Convert.ToDouble(dr_rows[i]["adj_close"]);
                    sd_temp.data[i].volume    = Convert.ToInt32(dr_rows[i]["volume"]);
                }
                ////////////////////////////////
                sw_copy.Stop();

                sd_temp.corpCode = code;
                StockCache.SetData(sd_temp);
            }
            MessageBox.Show("LINQ : " + sw_linq.ElapsedMilliseconds
                            + "ms\nCOPY : " + sw_copy.ElapsedMilliseconds
                            + "ms\nDIC : " + sw_dic.ElapsedMilliseconds + "ms");
        }
コード例 #3
0
        public static StockDataCache StockCache = new StockDataCache(); //全銘柄の株価データ

        /// <summary>
        /// RefreshCache:全銘柄の株価データをStockCacheへ取得
        /// </summary>
        public static void RefreshCache()
        {
            /////////////////////////////////
            Stopwatch sw_dic = new Stopwatch();

            ///////////////////////
            sw_dic.Start();

            //各種オブジェクトの作成
            DataTable dt_list = new DataTable();
            String    sql     = "select * from t_yahoofdata where (date > '2014-01-01') AND (corpCode <10000) ;";



            if (CorpListManager.CorpCache.KeyLength() == 0)
            {
                CorpListManager.RefreshCache();                                             //CorpListへ企業情報を格納する。
            }
            //dt_listに全株価情報を取得
            dt_list = SQLManager.SendSQL(sql);
            ////////////////////////////////
            sw_dic.Stop();

            //////////////////////
            Stopwatch sw_linq = new Stopwatch();
            Stopwatch sw_copy = new Stopwatch();

            //////////////////////

            //CorpListから
            foreach (var code in CorpListManager.CorpCache.Keys())
            {
                ////////////////////////
                sw_linq.Start();

                DataRow[] dr_rows = (
                    from row in dt_list.AsEnumerable()
                    where row.Field <int>("corpCode") == code
                    orderby row.Field <DateTime>("date")
                    select row).ToArray();

                ///////////////////////
                sw_linq.Stop();



                OHLCSeries sd_temp = new OHLCSeries(dr_rows.Length);//一時変数は銘柄ごとに作り直し



                ///////////////////////
                sw_copy.Start();

                for (int i = 0; i < dr_rows.Length; i++)
                {
                    sd_temp.data[i].date      = (DateTime)dr_rows[i]["Date"];
                    sd_temp.data[i].open      = Convert.ToInt32(dr_rows[i]["open"]);
                    sd_temp.data[i].close     = Convert.ToInt32(dr_rows[i]["adj_close"]);
                    sd_temp.data[i].high      = Convert.ToInt32(dr_rows[i]["high"]);
                    sd_temp.data[i].low       = Convert.ToInt32(dr_rows[i]["low"]);
                    sd_temp.data[i].adj_close = Convert.ToInt32(dr_rows[i]["adj_close"]);
                    sd_temp.data[i].volume    = Convert.ToInt32(dr_rows[i]["volume"]);
                }
                ////////////////////////////////
                sw_copy.Stop();

                sd_temp.corpCode = code;
                StockCache.SetData(sd_temp);
            }
            MessageBox.Show("LINQ : " + sw_linq.ElapsedMilliseconds
                            + "ms\nCOPY : " + sw_copy.ElapsedMilliseconds
                            + "ms\nDIC : " + sw_dic.ElapsedMilliseconds + "ms");
        }