示例#1
0
        /*public void Download_PerDay(DateTime date)
         * {
         *  dynamic[] equility_pages = new dynamic[] { new PageStock(), new PageForeign() };//, new PageJuristic("selfoper_"), new PageJuristic("investtrust_"), };
         *
         *  foreach (dynamic page in equility_pages)
         *  {
         *      current_download_status = "Downloading " + page.getFilePrefix() + date.ToShortDateString();
         *      Logger.Log(current_download_status);
         *      page.download_page(page.getPageUrl(date),   date);
         *      Thread.Sleep(5000);
         *  }
         * }*/

        public void BatchDownloadStockTrading()
        {
            dynamic[] equility_pages = new dynamic[] { new PageStock(), new PageForeign() };

            //DateTime date = checkDownload ? StartDate : equility_pages[0].getLastDBDate(sql_db, "2379");
            DateTime date = DbSql.getLastDBDate("2379");

            date = date.CompareTo(StartDate) > 0 ? date : StartDate;

            while (!date.Equals(DateTime.Today))
            {
                date = date.AddDays(1);
                //Logger.v("Downloading data starting from " + String.Format("{0}", date));
                if (!TradingDays.IsTradingDay(date))
                {
                    continue;
                }
                //Download_PerDay(date);
                foreach (dynamic page in equility_pages)
                {
                    String content = String.Empty;
                    if (!File.Exists(TargetDirectory + page.getFileName(date)))
                    {
                        current_download_status = "Downloading " + page.getFilePrefix() + date.ToShortDateString();
                        Logger.Log(current_download_status);
                        content = page.download_page(page.getPageUrl(date), Encoding.GetEncoding("utf-8"));
                        Thread.Sleep(5000);
                        using (StreamWriter sw = new StreamWriter(TargetDirectory + page.getFileName(date), false, Encoding.GetEncoding("utf-8")))
                        {
                            sw.Write(content);
                            sw.Close();
                        }
                    }
                    else
                    {
                        using (StreamReader sr = new StreamReader(TargetDirectory + page.getFileName(date), Encoding.GetEncoding("utf-8")))
                        {
                            content = sr.ReadToEnd();
                        }
                    }
                    ArrayList stock_data = page.ParseHtml(content, date);
                    if (stock_data.Count > 0)
                    {
                        page.DBSave(stock_data);
                    }
                }
                //Thread.Sleep(5000);
            }
        }
示例#2
0
        public float simulate_transation(String stock_index, ArrayList trade_history)
        {
            StockData stock_data = new StockData(stock_index);

            stock_data.LoadAll();

            //ArrayList trade_history = new ArrayList();
            Boolean  hold = false;
            DateTime date = START_DATE;

            while (!date.Equals(DateTime.Today))
            {
                if (TradingDays.IsTradingDay(date))
                {
                    if (hold)
                    {
                        if (eval_func.sell(stock_data, date))
                        {
                            trade_history.Add(new Trade_Cmd {
                                is_buy = false, date = date
                            });
                            hold = false;
                        }
                    }
                    else
                    {
                        if (eval_func.buy(stock_data, date))
                        {
                            trade_history.Add(new Trade_Cmd {
                                is_buy = true, date = date
                            });
                            hold = true;
                        }
                    }
                }
                date = date.AddDays(1);
            }

            return(evaluate_transation(stock_data, trade_history));
        }