Esempio n. 1
0
        /// <summary>
        /// 获取周线的历史数据
        /// </summary>
        /// <param name="weekDatas">周线历史数据</param>
        /// <param name="dayDatas">日线历史数据</param>
        /// <returns>状态</returns>
        public static int GetHistoryWeekDatas(List <SecurityData> weekDatas, List <SecurityData> dayDatas)
        {
            int weekDatasSize = dayDatas.Count;

            if (weekDatasSize > 0)
            {
                SecurityData weekData = new SecurityData();
                weekData.Copy(dayDatas[0]);
                int lDayOfWeek = 0, lDays = 0;
                for (int i = 0; i < weekDatasSize; i++)
                {
                    SecurityData dayData = new SecurityData();
                    dayData.Copy(dayDatas[i]);
                    int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, ms = 0, days = (int)dayData.m_date / (3600 * 24);
                    CStrA.M130(dayData.m_date, ref year, ref month, ref day, ref hour, ref minute, ref second, ref ms);
                    int  dayOfWeek  = DayOfWeek(year, month, day);
                    bool isNextWeek = true;
                    bool add        = false;
                    if (days - lDays <= 5)
                    {
                        if (days != lDays)
                        {
                            isNextWeek = dayOfWeek <= lDayOfWeek;
                        }
                    }
                    if (isNextWeek || i == weekDatasSize - 1)
                    {
                        add = true;
                    }
                    if (!isNextWeek)
                    {
                        weekData.m_close   = dayData.m_close;
                        weekData.m_amount += dayData.m_amount;
                        weekData.m_volume += dayData.m_volume;
                        if (weekData.m_high < dayData.m_high)
                        {
                            weekData.m_high = dayData.m_high;
                        }
                        if (weekData.m_low > dayData.m_low)
                        {
                            weekData.m_low = dayData.m_low;
                        }
                    }
                    if (add)
                    {
                        weekDatas.Add(weekData);
                        weekData = dayData;
                    }
                    if (isNextWeek && i == weekDatasSize - 1)
                    {
                        weekData = dayData;
                        weekDatas.Add(weekData);
                    }
                    lDayOfWeek = dayOfWeek;
                    lDays      = days;
                }
            }
            return(1);
        }
Esempio n. 2
0
        /// <summary>
        /// 获取月线的历史数据
        /// </summary>
        /// <param name="weekDatas">月线历史数据</param>
        /// <param name="dayDatas">日线历史数据</param>
        /// <returns>状态</returns>
        public static int GetHistoryMonthDatas(List <SecurityData> monthDatas, List <SecurityData> dayDatas)
        {
            int monthDatasSize = dayDatas.Count;

            if (monthDatasSize > 0)
            {
                SecurityData monthData = new SecurityData();
                monthData.Copy(dayDatas[0]);
                int lYear = 0, lMonth = 0, lDay = 0;
                for (int i = 0; i < monthDatasSize; i++)
                {
                    SecurityData dayData = new SecurityData();
                    dayData.Copy(dayDatas[i]);
                    int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, ms = 0;
                    CStrA.M130(dayData.m_date, ref year, ref month, ref day, ref hour, ref minute, ref second, ref ms);
                    bool isNextMonth = year * 12 + month > lYear * 12 + lMonth;
                    bool add         = false;
                    if (i == monthDatasSize - 1 || (i > 0 && isNextMonth))
                    {
                        add = true;
                    }
                    if (!isNextMonth)
                    {
                        monthData.m_close   = dayData.m_close;
                        monthData.m_amount += dayData.m_amount;
                        monthData.m_volume += dayData.m_volume;
                        if (monthData.m_high < dayData.m_high)
                        {
                            monthData.m_high = dayData.m_high;
                        }
                        if (monthData.m_low > dayData.m_low)
                        {
                            monthData.m_low = dayData.m_low;
                        }
                    }
                    if (add)
                    {
                        monthDatas.Add(monthData);
                        monthData = dayData;
                    }
                    if (isNextMonth && i == monthDatasSize - 1)
                    {
                        monthData = dayData;
                        monthDatas.Add(monthData);
                    }
                    lYear  = year;
                    lMonth = month;
                    lDay   = day;
                }
            }
            return(1);
        }
Esempio n. 3
0
        public static double SumHistoryData(CTable dataSource, double date, int cycle, int field)
        {
            double sumValue = 0;
            double value = 0;
            int    year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, ms = 0;

            CStrA.M130(date, ref year, ref month, ref day, ref hour, ref minute, ref second, ref ms);
            if (cycle == CYCLE_WEEK)
            {
                int dayOfWeek = DayOfWeek(year, month, day);
                if (dayOfWeek >= 5)
                {
                    dayOfWeek = 4;
                }
                for (int i = 1; i <= dayOfWeek; i++)
                {
                    double calcDate = CStrA.M129(year, month, day - i, 0, 0, 0, 0);
                    value = dataSource.Get(calcDate, field);
                    if (!double.IsNaN(value))
                    {
                        sumValue += value;
                    }
                }
            }
            else if (cycle == CYCLE_MONTH)
            {
                for (int i = 1; i < day; i++)
                {
                    double calcDate = CStrA.M129(year, month, i, 0, 0, 0, 0);
                    value = dataSource.Get(calcDate, field);
                    if (!double.IsNaN(value))
                    {
                        sumValue += value;
                    }
                }
            }
            else if (cycle == 0)
            {
                int rowCount = dataSource.RowsCount;
                for (int i = 0; i < rowCount; i++)
                {
                    value = dataSource.Get2(i, field);
                    if (!double.IsNaN(value))
                    {
                        sumValue += value;
                    }
                }
            }
            return(sumValue);
        }
Esempio n. 4
0
        public static double GetMinuteVol(CTable dataSource, double date, int field, double volume)
        {
            int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, ms = 0;

            CStrA.M130(date, ref year, ref month, ref day, ref hour, ref minute, ref second, ref ms);
            double startDate = 0;
            double endDate   = date;

            if (hour >= 6)
            {
                startDate = CStrA.M129(year, month, day, 6, 0, 0, 0);
            }
            else
            {
                double preDate = date - 86400;
                int    lyear = 0, lmonth = 0, lday = 0, lhour = 0, lminute = 0, lsecond = 0, lms = 0;
                CStrA.M130(preDate, ref lyear, ref lmonth, ref lday, ref lhour, ref lminute, ref lsecond, ref lms);
                startDate = CStrA.M129(lyear, lmonth, lday, 6, 0, 0, 0);
            }
            int  dataSize    = dataSource.RowsCount;
            bool containsFlg = false;

            for (int i = dataSize - 1; i >= 0; i--)
            {
                containsFlg = false;
                double ldate = dataSource.GetXValue(i);
                if (startDate <= ldate && ldate <= endDate)
                {
                    containsFlg = true;
                }
                if (!containsFlg)
                {
                    break;
                }
                else
                {
                    double vol = dataSource.Get2(i, KeyFields.VOL_INDEX);
                    volume = volume - vol;
                }
            }
            return(volume);
        }
Esempio n. 5
0
        /// <summary>
        /// 获取分时线的历史数据
        /// </summary>
        /// <param name="str">数据字符串</param>
        /// <param name="datas">历史数据</param>
        /// <returns>状态</returns>
        public static int GetHistoryDatasByMinuteStr(String str, List <SecurityData> datas)
        {
            String[] strs = str.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            int      strLen = strs.Length;
            double   lClose = 0, lHigh = 0, lLow = 0, lOpen = 0;
            double   lVolume = 0, lAmount = 0, fVolume = 0, fAmount = 0, sum = 0;
            int      lYear = 0, lMonth = 0, lDay = 0, lHour = 0, lMinute = 0;
            int      startIndex = 0;

            for (int i = startIndex; i < strLen; i++)
            {
                String[] strs2 = strs[i].Split(',');
                if (strs2.Length == 4)
                {
                    double date = CStrA.ConvertStrToDouble(strs2[0]);
                    double close = CStrA.ConvertStrToDouble(strs2[1]);
                    double volume = CStrA.ConvertStrToDouble(strs2[2]);
                    double amount = CStrA.ConvertStrToDouble(strs2[3]);
                    int    year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, ms = 0;
                    CStrA.M130(date, ref year, ref month, ref day, ref hour, ref minute, ref second, ref ms);
                    if (hour * 60 + minute >= 899)
                    {
                        hour   = 14;
                        minute = 59;
                    }
                    if (i == startIndex)
                    {
                        lClose  = close;
                        lHigh   = close;
                        lLow    = close;
                        lOpen   = close;
                        lVolume = volume;
                        lAmount = amount;
                        lYear   = year;
                        lMonth  = month;
                        lDay    = day;
                        lHour   = hour;
                        lMinute = minute;
                    }
                    bool inSameTime = false;
                    if (hour == lHour && minute == lMinute)
                    {
                        inSameTime = true;
                        if (close > lHigh)
                        {
                            lHigh = close;
                        }
                        if (close < lLow)
                        {
                            lLow = close;
                        }
                    }
                    if (!inSameTime || i == strLen - 1)
                    {
                        SecurityData data = new SecurityData();
                        data.m_date  = CStrA.M129(lYear, lMonth, lDay, lHour, lMinute, 0, 0);
                        data.m_close = lClose;
                        if (lHigh != 0)
                        {
                            data.m_high = lHigh;
                        }
                        else
                        {
                            data.m_high = lClose;
                        }
                        if (lLow != 0)
                        {
                            data.m_low = lLow;
                        }
                        else
                        {
                            data.m_low = lClose;
                        }
                        if (lOpen != 0)
                        {
                            data.m_open = lOpen;
                        }
                        else
                        {
                            data.m_open = lClose;
                        }
                        data.m_volume = lVolume - fVolume;
                        data.m_amount = lAmount - fAmount;
                        if (data.m_close != 0 && data.m_volume != 0)
                        {
                            sum            += data.m_close;
                            data.m_avgPrice = sum / (datas.Count + 1);
                            datas.Add(data);
                        }
                        fVolume = lVolume;
                        fAmount = lAmount;
                    }
                    if (!inSameTime)
                    {
                        lHigh   = close;
                        lLow    = close;
                        lOpen   = close;
                        lYear   = year;
                        lMonth  = month;
                        lDay    = day;
                        lHour   = hour;
                        lMinute = minute;
                    }
                    lClose  = close;
                    lVolume = volume;
                    lAmount = amount;
                }
            }
            return(1);
        }
Esempio n. 6
0
        /// <summary>
        /// 数据落地线程工作
        /// </summary>
        public static void StartWork3()
        {
            //复制数据
            LoadHistoryDatas();
            GetMinuteDatas();
            //新旧数据合并
            foreach (String oCode in m_historyDatas.Keys)
            {
                if (!m_latestDatas.ContainsKey(oCode) || !m_historyDatas.ContainsKey(oCode))
                {
                    continue;
                }
                SecurityLatestData  securityLatestData = m_latestDatas[oCode];
                List <SecurityData> oldSecurityDatas = m_historyDatas[oCode];
                SecurityData        oldSecurityData = oldSecurityDatas[oldSecurityDatas.Count - 1];
                int myear = 0, mmonth = 0, mday = 0, mhour = 0, mmin = 0, msec = 0, mmsec = 0;
                CStrA.M130(oldSecurityData.m_date, ref myear, ref mmonth, ref mday, ref mhour, ref mmin, ref msec, ref mmsec);
                int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0, msec2 = 0;
                CStrA.M130(securityLatestData.m_date, ref year, ref month, ref day, ref hour, ref min, ref sec, ref msec2);
                if (year >= myear && month >= mmonth && day >= mday)
                {
                    SecurityData nSecurityData = new SecurityData();
                    nSecurityData.m_amount = securityLatestData.m_amount;
                    nSecurityData.m_close  = securityLatestData.m_close;
                    nSecurityData.m_date   = securityLatestData.m_date;
                    nSecurityData.m_high   = securityLatestData.m_high;
                    nSecurityData.m_low    = securityLatestData.m_low;
                    nSecurityData.m_open   = securityLatestData.m_open;
                    nSecurityData.m_volume = securityLatestData.m_volume;
                    if (day == mday)
                    {
                        m_historyDatas[oCode].RemoveAt(m_historyDatas[oCode].Count - 1);
                    }
                    m_historyDatas[oCode].Add(nSecurityData);
                }
            }
            String outputFileTemplate = DataCenter.GetAppPath() + "\\day\\{0}.txt";
            String fileInfo           = "{0} {1} 日线 前复权\r\n";
            String title         = "      日期	    开盘	    最高	    最低	    收盘	    成交量	    成交额\r\n";
            String lineTemp      = "{0},{1},{2},{3},{4},{5},{6}\r\n";
            String timeFormatStr = "yyyy-MM-dd";

            //写入文件
            foreach (String code in m_historyDatas.Keys)
            {
                List <SecurityData> temp3   = m_historyDatas[code];
                StringBuilder       strbuff = new StringBuilder();
                strbuff.Append(String.Format(fileInfo, m_codedMap[code].m_code, m_codedMap[code].m_name));
                strbuff.Append(title);
                foreach (SecurityData sdt in temp3)
                {
                    strbuff.Append(String.Format(lineTemp,                                                  //
                                                 CStr.ConvertNumToDate(sdt.m_date).ToString(timeFormatStr), //
                                                 sdt.m_open,                                                //
                                                 sdt.m_high,                                                //
                                                 sdt.m_low,                                                 //
                                                 sdt.m_close,                                               //
                                                 sdt.m_volume,                                              //
                                                 sdt.m_amount));
                }
                strbuff.Append("数据来源:通达信\r\n");
                CFileA.Write(String.Format(outputFileTemplate, code), strbuff.ToString());
            }
        }