Exemple #1
0
        //从本地数据库获取股票上市退市信息
        public List <StockIPOInfo> GetStockListInfoFromSql()
        {
            List <StockIPOInfo> stockInfos = new List <StockIPOInfo>();
            var       sqlStr = "select [Code],[SecName],[IPODate],[DelistDate],[UpdateDateTime] from [Common].[dbo].[StockInfo]";
            DataTable dt     = new DataTable();

            try
            {
                dt = sqlReader.GetDataTable(sqlStr);
            }
            catch
            {
                logger.Warn(string.Format("There is no IPO information from specialized sqlserver!!!"));
            }
            foreach (DataRow dr in dt.Rows)
            {
                StockIPOInfo info = new StockIPOInfo();
                info.code    = Convert.ToString(dr[0]);
                info.name    = Convert.ToString(dr[1]);
                info.IPODate = Convert.ToDateTime(dr[2]);
                if (dr[3] != DBNull.Value)
                {
                    info.DelistDate = Convert.ToDateTime(dr[3]);
                }
                else
                {
                    info.DelistDate = new DateTime(2099, 12, 31);
                }
                info.updateTime = Convert.ToDateTime(dr[4]);
                stockInfos.Add(info);
            }
            return(stockInfos);
        }
 public void stockBackTest(StockIPOInfo info, DateTime startDate, DateTime endDate)
 {
     //获取数据
     if (startDate < info.IPODate)
     {
         startDate = info.IPODate;
     }
     if (endDate > info.DelistDate)
     {
         endDate = info.DelistDate;
     }
     //获取日线数据
     //var dayNow = stockDailyRepo.GetStockTransactionWithRedis(info.code, startDate, endDate);
     //获取交易日信息
     //var tradedays = dateRepo.GetStockTransactionDate(startDate, endDate);
     var minuteNow = stockMinutelyRepo.GetStockTransactionFromLocalSqlByCode(info.code, startDate, endDate);
     //回测
 }
Exemple #3
0
        public void UpdateStockInfoToNow()
        {
            var codes             = GetCodes();
            var latestTradingDate = dateRepo.GetPreviousTransactionDate(DateTime.Now.AddDays(1));
            var dt          = CreateIPODataTable();
            var IPOInfoList = GetStockListInfoFromSql();

            foreach (string code in codes)
            {
                StockIPOInfo infoObsolete = new StockIPOInfo();
                foreach (var item in IPOInfoList)
                {
                    if (item.code == code)
                    {
                        infoObsolete = item;
                    }
                    if (infoObsolete.code != null)
                    {
                        continue;
                    }
                }
                bool needUpdate = false;
                if (infoObsolete.code == null)
                {
                    needUpdate = true;
                }
                else
                {
                    var span = latestTradingDate - infoObsolete.updateTime;
                    if (span.TotalDays > 100)
                    {
                        needUpdate = true;
                    }
                }
                //Console.WriteLine("code:{0}, needupdate?{1}", code, needUpdate);
                if (needUpdate == true)
                {
                    var rawData = windReader.GetDailyData(code, "sec_name,ipo_date,delist_date", latestTradingDate, latestTradingDate);
                    var info    = (object[])rawData.data;
                    dt.Rows.Add(new object[] { code, info[0], info[1], info[2] });
                }
            }
            InsertToSql(dt);
        }