/// <summary> /// 获取对应日期下的权息资料 /// </summary> /// <param name="Dtm"></param> /// <param name="LSWI"></param> /// <returns></returns> public static StockWeightInfo GetWeightInfo(DateTime Dtm, List <StockWeightInfo> LSWI) { //2010-05-08 //1985-10-29 //1988-10-22 //2005-10-10 //2010-04-08 //2010-10-10 //2011-05-01 StockWeightInfo RtInfo = new StockWeightInfo(); foreach (StockWeightInfo SWI in LSWI) { if (Dtm >= SWI.m_date)// { RtInfo = SWI; } } return(RtInfo); }
/// <summary> /// 读取权息资料 /// </summary> /// <param name="strPath"></param> /// <param name="p_strMarket"></param> public static List <StockWeightInfo> ReadStockWeights(string strPath) { string[] parts = strPath.Split('\\'); string strStockCode = null; for (int i = parts.Length - 1; i >= 0; i--) { string strTemp = parts[i]; if (strTemp.ToUpper().EndsWith(".WGT")) { strStockCode = strTemp.Substring(0, strTemp.Length - 4); break; } } //Console.WriteLine("Read stock weight from file '" + strPath + "'"); FileStream stream = new FileStream(strPath, FileMode.Open, FileAccess.Read); BinaryReader b_reader = new BinaryReader(stream); List <StockWeightInfo> weightInfos = new List <StockWeightInfo>(); try { while (stream.CanRead && stream.Position < stream.Length) { int[] oneRow = new int[9]; for (int i = 0; i < 9; i++) { oneRow[i] = b_reader.ReadInt32(); } if (oneRow[8] != 0) { throw new Exception("Last entry is not empty"); } int nYear = oneRow[0] >> 20; int nMon = (int)(((uint)(oneRow[0] << 12)) >> 28); int nDay = (oneRow[0] & 0xffff) >> 11; DateTime wgtDate; if (nYear == 0 && nMon == 0 && nDay == 0) { wgtDate = DateTime.MinValue; } else { wgtDate = new DateTime(nYear, nMon, nDay); } StockWeightInfo wgtInfo = new StockWeightInfo(); wgtInfo.m_date = wgtDate; wgtInfo.m_stockCountAsGift = oneRow[1]; /**/ ///10000.0f; wgtInfo.m_stockCountForSell = oneRow[2]; /**/ ///10000.0f; wgtInfo.m_priceForSell = oneRow[3]; /**/ ///1000.0f; wgtInfo.m_bonus = oneRow[4]; /**/ ///1000.0f; wgtInfo.m_stockCountOfIncreasement = oneRow[5]; /**/ ///10000.0f; wgtInfo.m_stockOwnership = (ulong)oneRow[6]; wgtInfo.m_freeStockCount = (ulong)oneRow[7]; if (!weightInfos.Contains(wgtInfo)) { weightInfos.Add(wgtInfo); //Console.WriteLine(); //Console.Write("时间:" + wgtInfo.m_date.ToString() + ",流通股:" + wgtInfo.m_freeStockCount + ",m_priceForSell:" + wgtInfo.m_priceForSell + ",分红:" + wgtInfo.m_bonus + ",送股数:" + wgtInfo.m_stockCountAsGift + ",m_stockCountForSell:" + wgtInfo.m_stockCountForSell + ",转增数:" + wgtInfo.m_stockCountOfIncreasement + ",总股本:" + wgtInfo.m_stockOwnership);//测试部分 } } weightInfos.Sort(); } catch (EndOfStreamException) { Console.WriteLine("Unexpected end of stream"); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { stream.Close(); } return(weightInfos); }