Ejemplo n.º 1
0
        public WindData getDataSet()
        {
            //WindAPI w = new WindAPI();
            //w.start();
            string   strExecInfo = string.Format(strInfo, SecCode, Date.ToShortDateString());
            WindData wd          = w.wset(strType, strExecInfo);

            return(wd);
        }
Ejemplo n.º 2
0
        private void GetStockList()
        {
            TradeDays myTradeDays = new TradeDays(20130601, 20160626);

            int[] changeDate = new int[7] {
                20130628, 20131213, 20140613, 20141212, 20150612, 20151211, 20160608
            };
            w.start();
            foreach (int date in changeDate)
            {
                int           today        = date;
                int           tomorrow     = TradeDays.GetNextTradeDay(date);
                string        todayStr     = DateTime.ParseExact(today.ToString(), "yyyyMMdd", null).ToString("yyyy-MM-dd");
                string        tomorrowStr  = DateTime.ParseExact(tomorrow.ToString(), "yyyyMMdd", null).ToString("yyyy-MM-dd");
                List <string> todayList    = new List <string>();
                List <string> tomorrowList = new List <string>();
                List <string> stockIn      = new List <string>();
                List <string> stockOut     = new List <string>();
                WindData      wd           = w.wset("sectorconstituent", "date=" + todayStr + ";windcode=" + indexName);
                object[]      stockList    = wd.data as object[];
                int           num          = stockList.Length / 3;
                for (int i = 0; i < num; i++)
                {
                    todayList.Add(Convert.ToString(stockList[i * 3 + 1]));
                }
                wd        = w.wset("sectorconstituent", "date=" + tomorrowStr + ";windcode=" + indexName);
                stockList = wd.data as object[];
                num       = stockList.Length / 3;
                for (int i = 0; i < num; i++)
                {
                    tomorrowList.Add(Convert.ToString(stockList[i * 3 + 1]));
                }
                foreach (string code in tomorrowList)
                {
                    if (todayList.Contains(code) == false)
                    {
                        stockIn.Add(code);
                    }
                }
                foreach (string code in todayList)
                {
                    if (tomorrowList.Contains(code) == false)
                    {
                        stockOut.Add(code);
                    }
                }
                stockModifyList myList = new stockModifyList(today, stockIn, stockOut);
                changeList.Add(today, myList);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取股票列表的信息。
        /// </summary>
        /// <param name="market">市场</param>
        /// <returns>商品期货信息列表</returns>
        public List <stockFormat> GetStockList(string indexName)
        {
            List <stockFormat> myList = new List <stockFormat>();
            //按日期遍历,添加股票信息。
            WindAPI w = new WindAPI();

            w.start();
            string[] dateStr = { "2013-06-01", "2013-12-01", "2014-06-01", "2014-12-01", "2015-06-01", "2015-12-01", "2016-06-01", "2016-06-20" };
            foreach (var item in dateStr)
            {
                WindData wd        = w.wset("sectorconstituent", "date=" + item + ";windcode=" + indexName);
                object[] stockList = wd.data as object[];
                int      num       = stockList.Length / 3;
                for (int i = 0; i < num; i++)
                {
                    stockFormat myStock = new stockFormat();
                    myStock.market = "SH";
                    myStock.code   = Convert.ToString(stockList[i * 3 + 1]).Substring(0, 6);
                    myStock.name   = (string)stockList[i * 3 + 2];
                    if (myList.Contains(myStock) == false)
                    {
                        myList.Add(myStock);
                    }
                }
            }
            w.stop();
            return(myList);
        }
Ejemplo n.º 4
0
        public List <OptionInfo> readFromWind(string underlying = "510050.SH", string market = "sse")
        {
            string marketStr = "";

            if (market == "sse")
            {
                marketStr = ".SH";
            }
            WindAPI           wapi     = Platforms.GetWindAPI();
            WindData          wd       = wapi.wset("optioncontractbasicinfo", "exchange=" + market + ";windcode=" + underlying + ";status=all");
            int               len      = wd.codeList.Length;
            int               fieldLen = wd.fieldList.Length;
            List <OptionInfo> items    = new List <OptionInfo>(len);

            object[] dm = (object[])wd.data;
            for (int k = 0; k < len; k++)
            {
                items.Add(new OptionInfo
                {
                    optionCode         = (string)dm[k * fieldLen + 0] + marketStr,
                    optionName         = (string)dm[k * fieldLen + 1],
                    executeType        = (string)dm[k * fieldLen + 5],
                    strike             = (double)dm[k * fieldLen + 6],
                    contractMultiplier = (double)dm[k * fieldLen + 7],
                    optionType         = (string)dm[k * fieldLen + 4],
                    startDate          = (DateTime)dm[k * fieldLen + 9],
                    endDate            = (DateTime)dm[k * fieldLen + 10]
                });
            }
            return(items);
        }
Ejemplo n.º 5
0
        protected List <OptionInfo> readFromWindOnly50ETFOption(string underlying = "510050.SH", string market = "sse")
        {
            DateTime timeOf50ETFDividend2016    = new DateTime(2016, 11, 29);//2016年50ETF分红时间
            double   standardContractMultiplier = 10000;
            string   marketStr = "";

            if (market == "sse")
            {
                marketStr = ".SH";
            }
            if (Caches.WindConnection == false)
            {
                return(null);
            }
            WindAPI           wapi     = Platforms.GetWindAPI();
            WindData          wd       = wapi.wset("optioncontractbasicinfo", "exchange=" + market + ";windcode=" + underlying + ";status=all");
            int               len      = wd.codeList.Length;
            int               fieldLen = wd.fieldList.Length;
            List <OptionInfo> items    = new List <OptionInfo>(len);

            object[] dm = (object[])wd.data;
            for (int k = 0; k < len; k++)
            {
                items.Add(new OptionInfo
                {
                    optionCode         = (string)dm[k * fieldLen + 0] + marketStr,
                    optionName         = (string)dm[k * fieldLen + 1],
                    executeType        = (string)dm[k * fieldLen + 5],
                    strike             = (double)dm[k * fieldLen + 6],
                    contractMultiplier = (double)dm[k * fieldLen + 7],
                    optionType         = (string)dm[k * fieldLen + 4],
                    startDate          = (DateTime)dm[k * fieldLen + 9],
                    endDate            = (DateTime)dm[k * fieldLen + 10]
                });
            }
            for (int i = 0; i < items.Count(); i++)
            {
                var item = items[i];
                if (item.startDate < timeOf50ETFDividend2016 && item.endDate >= timeOf50ETFDividend2016)
                {
                    item.modifiedDate         = timeOf50ETFDividend2016;
                    item.strikeBeforeModified = Math.Round(item.strike * item.contractMultiplier / standardContractMultiplier, 2);
                }
                else
                {
                    item.strikeBeforeModified = item.strike;
                }
                items[i] = item;
            }
            return(items);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 按日期遍历,添加期权信息。写入静态哈希表myOptionList。
        /// </summary>
        /// <param name="startDate">开始日期</param>
        /// <param name="endDate">结束日期</param>
        private void GetOptionInformationList(int startDate, int endDate)
        {
            //定义交易日期的类。
            TradeDays myTradeDays = new TradeDays(startDate, endDate);

            //从数据库表中获取信息,如果已经是完整信息就不需要连接万德数据库。
            if (GetOptionListFromTable(startDate, endDate) == true)
            {
                return;
            }
            //按日期遍历,添加期权信息。
            WindAPI w = new WindAPI();

            w.start();
            foreach (int today in myTradeDays.myTradeDays)
            {
                if (TradeDays.IsOptionExerciseDate(today) || today == myTradeDays.myTradeDays[myTradeDays.myTradeDays.Count - 1])
                {
                    WindData optionToday = w.wset("OptionChain", "date=" + today.ToString() + ";us_code=" + Configuration.underlyingAsset + ";option_var=;month=全部;call_put=全部");
                    object[] optionList  = optionToday.data as object[];
                    int      num         = optionList.Length / 13;
                    for (int i = 0; i < num; i++)
                    {
                        optionFormat option     = new optionFormat();
                        string       codeString = (string)optionList[i * 13 + 4 - 1];
                        option.optionCode  = Convert.ToInt32(codeString.Substring(0, 8));
                        option.market      = codeString.Substring(9, 2);
                        option.optionName  = (string)optionList[i * 13 + 5 - 1];
                        option.executeType = (string)optionList[i * 13 + 6 - 1];
                        option.strike      = (double)optionList[i * 13 + 7 - 1];
                        option.optionType  = (string)optionList[i * 13 + 9 - 1];
                        option.startDate   = TradeDays.DateTimeToInt((DateTime)optionList[i * 13 + 10 - 1]);
                        option.endDate     = TradeDays.DateTimeToInt((DateTime)optionList[i * 13 + 11 - 1]);
                        if (myOptionList.ContainsKey(option.optionCode) == false)
                        {
                            myOptionList.Add(option.optionCode, option);
                        }
                    }
                }
            }
            w.stop();
        }
Ejemplo n.º 7
0
        private void GetBonusFromWind()
        {
            string   startDateStr = DateTime.ParseExact(startDate.ToString(), "yyyyMMdd", null).ToString("yyyy-MM-dd");
            string   endDateStr   = DateTime.ParseExact(endDate.ToString(), "yyyyMMdd", null).ToString("yyyy-MM-dd");
            WindData wd           = w.wset("corporationaction", "startdate=" + startDateStr + ";enddate=" + endDateStr + ";windcode=" + code);

            object[] stockList = wd.data as object[];
            int      num       = stockList == null?0:stockList.Length / 11;

            for (int i = 0; i < num; i++)
            {
                stockChangeFormat change = new stockChangeFormat();
                change.code = code;
                string[] date = Convert.ToString(stockList[i * 11]).Split(new char[] { '/', ' ' });
                change.date    = Convert.ToInt32(date[0]) * 10000 + Convert.ToInt32(date[1]) * 100 + Convert.ToInt32(date[2]);
                change.bonus   = Convert.ToDouble(stockList[i * 11 + 3]);
                change.divisor = 1.0 + Convert.ToDouble(stockList[i * 11 + 4]);
                stockChangeList.Add(change);
            }
        }
Ejemplo n.º 8
0
        protected List <OptionInfo> readFromWindOnlyByDate(string underlying, DateTime startDate, DateTime endDate)
        {
            if (Caches.WindConnection == false)
            {
                return(null);
            }
            underlying = underlying.ToUpper();
            var               tradeDays          = DateUtils.GetTradeDays(startDate, endDate);
            WindAPI           wapi               = Platforms.GetWindAPI();
            List <OptionInfo> items              = new List <OptionInfo>();
            Dictionary <string, OptionInfo> list = new Dictionary <string, OptionInfo>();

            foreach (var date in tradeDays)
            {
                string   dateStr  = date.ToString("yyyy-MM-dd");
                WindData wd       = wapi.wset("optionchain", "date=" + dateStr + ";us_code=" + underlying + ";option_var=全部;call_put=全部");
                object[] dm       = (object[])wd.data;
                int      len      = wd.codeList.Length;
                int      fieldLen = wd.fieldList.Length;
                for (int k = 0; k < len; k++)
                {
                    OptionInfo myInfo = new OptionInfo
                    {
                        optionCode         = (string)dm[k * fieldLen + 2],
                        optionName         = (string)dm[k * fieldLen + 4],
                        executeType        = (string)dm[k * fieldLen + 5],
                        strike             = (double)dm[k * fieldLen + 6],
                        contractMultiplier = (double)dm[k * fieldLen + 13],
                        optionType         = (string)dm[k * fieldLen + 8],
                        startDate          = (DateTime)dm[k * fieldLen + 9],
                        endDate            = (DateTime)dm[k * fieldLen + 10]
                    };
                    if (list.ContainsKey(myInfo.optionName) == false)
                    {
                        list.Add(myInfo.optionName, myInfo);
                        items.Add(myInfo);
                    }
                }
            }
            return(items);
        }
Ejemplo n.º 9
0
        private static List <CodeInfo> GetSectorCodeInfo(WindAPI wind, DateTime date, string sectorId)
        {
            var wd = wind.wset("sectorconstituent", $"date={date.ToString("yyyy-MM-dd")};sectorid={sectorId}");    // 获得上海交易所数据
            var df = (object[, ])wd.getDataByFunc("wset", false);

            var length = df.GetUpperBound(0);

            List <CodeInfo> rets = new List <CodeInfo>();

            for (var i = 0; i <= length; i++)
            {
                var ci = new CodeInfo()
                {
                    WindCode = df[i, 1].ToString(),
                    Name     = df[i, 2].ToString(),
                };

                rets.Add(ci);
            }

            return(rets);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 根据程序运行日期,获取截止至昨日的指数成分股的列表
        /// </summary>
        /// <returns>指数成分股列表</returns>
        private Dictionary <string, stockFormat> getExitsStocks()
        {
            Dictionary <string, stockFormat> list = new Dictionary <string, stockFormat>();
            int yesterday = TradeDays.GetPreviousTradeDay(Convert.ToInt32(DateTime.Now.ToString("yyyyMMdd")));

            foreach (int day in myTradeDays.myTradeDays)
            {
                string todayStr = DateTime.ParseExact(day.ToString(), "yyyyMMdd", null).ToString("yyyy-MM-dd");

                if (day <= yesterday)
                {
                    WindData wd        = w.wset("sectorconstituent", "date=" + todayStr + ";windcode=" + indexName);
                    object[] stockList = wd.data as object[];
                    int      num       = stockList.Length / 3;
                    for (int i = 0; i < num; i++)
                    {
                        stockFormat myStock = new stockFormat();
                        myStock.code = Convert.ToString(stockList[i * 3 + 1]);
                        myStock.name = (string)stockList[i * 3 + 2];
                        if (list.ContainsKey(myStock.code) == false)
                        {
                            myStock.existsDate = new List <int>();
                            myStock.existsDate.Add(day);
                            myStock.existsDate.Add(day);
                            list.Add(myStock.code, myStock);
                        }
                        else
                        {
                            int enterDate = list[myStock.code].existsDate[list[myStock.code].existsDate.Count() - 2];
                            int quitDate  = list[myStock.code].existsDate[list[myStock.code].existsDate.Count() - 1];
                            if (day > TradeDays.GetNextTradeDay(quitDate))
                            {
                                list[myStock.code].existsDate.Add(day);
                                list[myStock.code].existsDate.Add(day);
                            }
                            else
                            {
                                list[myStock.code].existsDate[list[myStock.code].existsDate.Count() - 1] = day;
                            }
                        }
                    }
                }
            }
            //若计算时间不包括历史时间,必须读取昨日的数据作为基准
            if (list.Count == 0)
            {
                string   yesterdayStr = DateTime.ParseExact(yesterday.ToString(), "yyyyMMdd", null).ToString("yyyy-MM-dd"); List <stockFormat> myList = new List <stockFormat>();
                WindData wd        = w.wset("sectorconstituent", "date=" + yesterdayStr + ";windcode=" + indexName);
                object[] stockList = wd.data as object[];
                int      num       = stockList.Length / 3;
                for (int i = 0; i < num; i++)
                {
                    stockFormat myStock = new stockFormat();
                    myStock.code       = Convert.ToString(stockList[i * 3 + 1]).Substring(0, 6);
                    myStock.name       = (string)stockList[i * 3 + 2];
                    myStock.existsDate = new List <int>();
                    myStock.existsDate.Add(yesterday);
                    myStock.existsDate.Add(yesterday);
                }
            }
            //从stockModify.csv中读取指数成分股变动股票和日期
            DataTable dt = CsvApplication.OpenCSV("stockModify.csv");
            SortedDictionary <int, List <stockModify> > stockModifyList = new SortedDictionary <int, List <stockModify> >();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                stockModify stock = new stockModify();
                stock.code      = dt.Rows[i][0].ToString();
                stock.name      = dt.Rows[i][1].ToString();
                stock.date      = Convert.ToInt32(dt.Rows[i][2].ToString());
                stock.direction = dt.Rows[i][3].ToString();
                if (stockModifyList.ContainsKey(stock.date))
                {
                    stockModifyList[stock.date].Add(stock);
                }
                else
                {
                    List <stockModify> stockList0 = new List <stockModify>();
                    stockList0.Add(stock);
                    stockModifyList.Add(stock.date, stockList0);
                }
            }
            //根据文档对我的数据进行处理,如果变动时间大于昨日时间,需要对我的股票列表进行修正
            int maxDate = yesterday;

            foreach (var stockList in stockModifyList)
            {
                if (stockList.Value[0].date > yesterday)
                {
                    foreach (var stock in stockList.Value)
                    {
                        if (stock.direction == "out")
                        {
                            if (list.ContainsKey(stock.code) == true)
                            {
                                list[stock.code].existsDate[list[stock.code].existsDate.Count() - 1] = stock.date;
                            }
                        }
                        if (stock.direction == "in")
                        {
                            if (stockList.Value[0].date > maxDate)
                            {
                                maxDate = stockList.Value[0].date;
                            }
                            if (list.ContainsKey(stock.code) == true)
                            {
                                list[stock.code].existsDate.Add(stock.date);
                                list[stock.code].existsDate.Add(stock.date);
                            }
                            else
                            {
                                stockFormat myStock = new stockFormat();
                                myStock.name       = stock.name;
                                myStock.code       = stock.code;
                                myStock.existsDate = new List <int>();
                                myStock.existsDate.Add(stock.date);
                                myStock.existsDate.Add(stock.date);
                            }
                        }
                    }
                }
            }

            //按照回测日期给股票列表进行修正
            foreach (var stock in list)
            {
                if (stock.Value.existsDate[stock.Value.existsDate.Count() - 1] == yesterday || stock.Value.existsDate[stock.Value.existsDate.Count() - 1] == maxDate)
                {
                    stock.Value.existsDate[stock.Value.existsDate.Count() - 1] = endDate;
                }
            }
            return(list);
        }
Ejemplo n.º 11
0
        private void EvaluateBonus()
        {
            //利用万德wset的“分红送转”抓取数据
            foreach (var item in GetStocks.stockList)
            {
                stockBonus    bonus               = bonusList[item.Key];
                List <int>    dateList            = new List <int>();
                List <double> historicalBonusList = new List <double>();
                WindData      wd        = w.wset("corporationaction", "startdate=2014-01-01;enddate=2020-06-20;windcode=" + bonus.code + ";field=ex_dividend_date,wind_code,sec_name,cash_payout_ratio,ex_dividend_note");
                object[]      stockList = wd.data as object[];
                int           num       = (stockList == null ? 0 : stockList.Length / 5);
                for (int i = 0; i < num; i++)
                {
                    string[] dateStr   = Convert.ToString(stockList[i * 5]).Split(new char[] { '/', ' ' });
                    int      date      = Convert.ToInt32(dateStr[0]) * 10000 + Convert.ToInt32(dateStr[1]) * 100 + Convert.ToInt32(dateStr[2]);
                    double   planBonus = (stockList[i * 5 + 3] == null ? 0 : (double)stockList[i * 5 + 3]);
                    dateList.Add(date);
                    historicalBonusList.Add(planBonus);
                }
                //判断去年是否有2次分红
                int thisYear = 0, lastYear = 0;
                for (int i = 0; i < dateList.Count; i++)
                {
                    int    date    = dateList[i];
                    double myBonus = historicalBonusList[i];
                    if (date / 10000 + 1 == yesterday / 10000 && myBonus > 0)
                    {
                        lastYear += 1;
                    }
                    if (date / 10000 == yesterday / 10000 && myBonus > 0)
                    {
                        thisYear += 1;
                    }
                }
                if (lastYear == 1 &&  thisYear == 1)
                {
                    bonus.firstBonus  = historicalBonusList[historicalBonusList.Count() - 1];
                    bonus.firstDate   = dateList[dateList.Count() - 1];
                    bonus.firstStatus = "明确";
                }
                if (lastYear == 1 && thisYear == 0)
                {
                    if (bonus.planBonus != 0)
                    {
                        bonus.firstBonus  = bonus.planBonus;
                        bonus.firstDate   = TradeDays.GetRecentTradeDay(dateList[dateList.Count() - 1] + 10000);
                        bonus.firstStatus = "有预案但日期未明确";
                    }
                    else
                    {
                        string   str     = DateTime.ParseExact(yesterday.ToString(), "yyyyMMdd", null).ToString("yyyy-MM-dd");
                        WindData eps     = w.wsd(bonus.code, "eps_ttm", "ED-0TD", str, "Days=Alldays");//利用EPS来估算分红
                        double[] epsList = eps.data as double[];
                        double   thisEps = epsList[0];
                        if (thisEps < 0)
                        {
                            bonus.firstStatus = "去年亏损无分红";
                            bonus.firstBonus  = 0;
                            bonus.firstDate   = 0;
                        }
                        else
                        {
                            str     = DateTime.ParseExact((yesterday - 10000).ToString(), "yyyyMMdd", null).ToString("yyyy-MM-dd");
                            eps     = w.wsd(bonus.code, "eps_ttm", "ED-0TD", str, "Days=Alldays");
                            epsList = eps.data as double[];
                            double lastEps = (epsList == null?0:epsList[0]);
                            if (lastEps == 0)
                            {
                                bonus.firstStatus = "去年无EPS数据无法预测";
                                bonus.firstBonus  = 0;
                                bonus.firstDate   = 0;
                            }
                            else
                            {
                                bonus.firstBonus  = historicalBonusList[historicalBonusList.Count() - 1] / lastEps * thisEps;
                                bonus.firstDate   = TradeDays.GetRecentTradeDay(dateList[dateList.Count() - 1] + 10000);
                                bonus.firstStatus = "无预案按上次分红预测";
                            }
                        }
                    }
                }
                if (lastYear >= 2 && thisYear == 2)
                {
                    bonus.firstBonus   = historicalBonusList[historicalBonusList.Count() - 2];
                    bonus.firstDate    = dateList[dateList.Count() - 2];
                    bonus.firstStatus  = "明确";
                    bonus.secondBonus  = historicalBonusList[historicalBonusList.Count() - 1];
                    bonus.secondDate   = dateList[dateList.Count() - 1];
                    bonus.secondStatus = "明确";
                }
                if (lastYear >= 2 && thisYear == 1)
                {
                    bonus.firstBonus  = historicalBonusList[historicalBonusList.Count() - 1];
                    bonus.firstDate   = dateList[dateList.Count() - 1];
                    bonus.firstStatus = "明确";
                    if (bonus.planBonus != 0)
                    {
                        bonus.secondBonus  = bonus.planBonus;
                        bonus.secondDate   = TradeDays.GetRecentTradeDay(dateList[dateList.Count() - 2] + 10000);
                        bonus.secondStatus = "有预案但日期未明确";
                    }
                    else
                    {
                        bonus.secondDate   = TradeDays.GetRecentTradeDay(dateList[dateList.Count() - 2] + 10000);
                        bonus.secondStatus = "无预案按上次分红预测";
                        bonus.secondBonus  = historicalBonusList[historicalBonusList.Count() - 2] / historicalBonusList[historicalBonusList.Count() - 3] * historicalBonusList[historicalBonusList.Count() - 1];
                    }
                }
                if (lastYear >= 2 && thisYear == 0)
                {
                    if (bonus.planBonus != 0)
                    {
                        bonus.firstBonus   = bonus.planBonus;
                        bonus.firstDate    = TradeDays.GetRecentTradeDay(dateList[dateList.Count() - 2] + 10000);
                        bonus.firstStatus  = "有预案但日期未明确";
                        bonus.secondDate   = TradeDays.GetRecentTradeDay(dateList[dateList.Count() - 1] + 10000);
                        bonus.secondStatus = "无预案按上次分红预测";
                        bonus.secondBonus  = historicalBonusList[historicalBonusList.Count() - 1] / historicalBonusList[historicalBonusList.Count() - 2] * bonus.planBonus;
                    }
                    else
                    {
                        string   str     = DateTime.ParseExact(yesterday.ToString(), "yyyyMMdd", null).ToString("yyyy-MM-dd");
                        WindData eps     = w.wsd(bonus.code, "eps_ttm", "ED-0TD", str, "Days=Alldays");
                        double[] epsList = eps.data as double[];
                        double   thisEps = epsList[0];
                        if (thisEps < 0)
                        {
                            bonus.firstStatus  = "去年亏损无分红";
                            bonus.firstBonus   = 0;
                            bonus.firstDate    = 0;
                            bonus.secondStatus = "去年亏损无分红";
                            bonus.secondBonus  = 0;
                            bonus.secondDate   = 0;
                        }
                        else
                        {
                            str     = DateTime.ParseExact((yesterday - 10000).ToString(), "yyyyMMdd", null).ToString("yyyy-MM-dd");
                            eps     = w.wsd(bonus.code, "eps_ttm", "ED-0TD", str, "Days=Alldays");
                            epsList = eps.data as double[];
                            double lastEps = (epsList == null ? 0 : epsList[0]);
                            if (lastEps == 0)
                            {
                                bonus.firstStatus  = "去年无EPS数据无法预测";
                                bonus.firstBonus   = 0;
                                bonus.firstDate    = 0;
                                bonus.secondStatus = "去年无EPS数据无法预测";
                                bonus.secondBonus  = 0;
                                bonus.secondDate   = 0;
                            }
                            else
                            {
                                bonus.firstBonus   = historicalBonusList[historicalBonusList.Count() - 2] / lastEps * thisEps;
                                bonus.firstDate    = TradeDays.GetRecentTradeDay(dateList[dateList.Count() - 2] + 10000);
                                bonus.firstStatus  = "无预案按上次分红预测";
                                bonus.secondBonus  = historicalBonusList[historicalBonusList.Count() - 1] / lastEps * thisEps;
                                bonus.secondDate   = TradeDays.GetRecentTradeDay(dateList[dateList.Count() - 1] + 10000);
                                bonus.secondStatus = "无预案按上次分红预测";
                            }
                        }
                    }
                }
                if (lastYear == 0 && thisYear == 0)
                {
                    if (bonus.planBonus > 0)
                    {
                        bonus.firstBonus  = bonus.planBonus;
                        bonus.firstDate   = 0;
                        bonus.firstStatus = "有预案但日期未明确";
                    }
                    else
                    {
                        bonus.firstStatus = "无预案无分红数据";
                    }
                }
                if (lastYear == 0 && thisYear == 1)
                {
                    bonus.firstBonus  = historicalBonusList[historicalBonusList.Count() - 1];
                    bonus.firstDate   = dateList[dateList.Count() - 1];
                    bonus.firstStatus = "明确";
                    if (bonus.planBonus > 0)
                    {
                        bonus.secondBonus  = bonus.planBonus;
                        bonus.secondDate   = 0;
                        bonus.secondStatus = "有预案但日期未明确";
                    }
                }
                if (lastYear == 0 &&  thisYear == 2)
                {
                    bonus.firstBonus   = historicalBonusList[historicalBonusList.Count() - 2];
                    bonus.firstDate    = dateList[dateList.Count() - 2];
                    bonus.firstStatus  = "明确";
                    bonus.secondBonus  = historicalBonusList[historicalBonusList.Count() - 1];
                    bonus.secondDate   = dateList[dateList.Count() - 1];
                    bonus.secondStatus = "明确";
                }
                if (bonus.firstStatus == "有预案但日期未明确" || bonus.firstStatus == "无预案按上次分红预测")
                {
                    if (bonus.firstDate <= yesterday)
                    {
                        bonus.firstDate    = 0;
                        bonus.firstStatus += "预测日期已过";
                    }
                }
                if (bonus.secondStatus == "有预案但日期未明确" || bonus.secondStatus == "无预案按上次分红预测")
                {
                    if (bonus.secondDate <= yesterday)
                    {
                        bonus.secondDate    = 0;
                        bonus.secondStatus += "预测日期已过";
                    }
                }
                evaluateBonusList.Add(bonus.code, bonus);
            }

            //预处理,默认除息除权日是分红的前一天
            foreach (var item in GetStocks.stockList)
            {
                stockBonus bonus = evaluateBonusList[item.Key];

                if (bonus.firstDate > 0)
                {
                    bonus.firstRegisterDate = TradeDays.GetPreviousTradeDay(bonus.firstDate);
                }
                if (bonus.secondDate > 0)
                {
                    bonus.SecondRegisterDate = TradeDays.GetPreviousTradeDay(bonus.secondDate);
                }
                evaluateBonusList[item.Key] = bonus;
            }


            //利用万德接口wset的“分红实施”来获取股权登记日
            string   lastYearStr = (yesterday / 10000 - 1).ToString();
            WindData register    = w.wset("bonus", "orderby=报告期;year=" + lastYearStr + ";period=y1;sectorid=a001010100000000;field=wind_code,sec_name,shareregister_date,dividend_payment_date");

            object[] stockList2 = register.data as object[];
            int      num2       = (stockList2 == null?0:stockList2.Length / 4);

            for (int i = 0; i < num2; i++)
            {
                string code = Convert.ToString(stockList2[i * 4]);
                if (evaluateBonusList.ContainsKey(code))
                {
                    string[]   date     = Convert.ToString(stockList2[i * 4 + 3]).Split(new char[] { '/', ' ' });
                    int        planDate = Convert.ToInt32(date[0]) * 10000 + Convert.ToInt32(date[1]) * 100 + Convert.ToInt32(date[2]);
                    stockBonus bonus    = evaluateBonusList[code];
                    if (planDate == bonus.firstDate)
                    {
                        date = Convert.ToString(stockList2[i * 4 + 2]).Split(new char[] { '/', ' ' });
                        bonus.firstRegisterDate = Convert.ToInt32(date[0]) * 10000 + Convert.ToInt32(date[1]) * 100 + Convert.ToInt32(date[2]);
                    }
                    if (planDate == bonus.secondDate)
                    {
                        date = Convert.ToString(stockList2[i * 4 + 2]).Split(new char[] { '/', ' ' });
                        bonus.SecondRegisterDate = Convert.ToInt32(date[0]) * 10000 + Convert.ToInt32(date[1]) * 100 + Convert.ToInt32(date[2]);
                    }
                    evaluateBonusList[code] = bonus;
                }
            }
        }
Ejemplo n.º 12
0
        public List <StockBasicInfo> readFromWind(DateTime date, string tag = null, List <string> existCode = null, List <StockBasicInfo> preList = null, IDictionary <string, object> options = null)
        {
            if (Caches.WindConnection == false && Caches.WindConnectionTry == true)
            {
                return(null);
            }
            date = DateUtils.PreviousOrCurrentTradeDay(date);//获取最近的交易日
            WindAPI       w        = Platforms.GetWindAPI();
            WindData      delist   = w.wset("sectorconstituent", "date=" + date.ToString("yyyy-MM-dd") + ";sectorid=a001010m00000000");
            WindData      list     = w.wset("sectorconstituent", "date=" + date.ToString("yyyy-MM-dd") + ";sectorid=a001010100000000");
            List <string> codeList = new List <string>();
            int           len      = delist.codeList.Length;
            int           fieldLen = delist.fieldList.Length;

            object[] dataList = (object[])delist.data;
            for (int k = 0; k < len; k++)
            {
                var code = dataList[k * fieldLen + 1].ToString();
                if ((existCode != null && existCode.Contains(code) == true) || existCode == null)
                {
                    codeList.Add(code);
                }
            }
            len      = list.codeList.Length;
            fieldLen = list.fieldList.Length;
            dataList = (object[])list.data;
            for (int k = 0; k < len; k++)
            {
                var code = dataList[k * fieldLen + 1].ToString();
                if ((existCode != null && existCode.Contains(code) == false) || existCode == null)
                {
                    codeList.Add(code);
                }
            }
            codeList.Sort();
            List <StockBasicInfo> items = new List <StockBasicInfo>();
            WindData wd = new WindData();

            foreach (var code in codeList)
            {
                wd       = w.wsd(code, "sec_name,ipo_date,delist_date", date.ToString("yyyy-MM-dd"), date.ToString("yyyy-MM-dd"), "");
                dataList = (object[])wd.data;
                items.Add(new StockBasicInfo
                {
                    code       = code,
                    name       = dataList[0].ToString(),
                    listDate   = (DateTime)dataList[1],
                    delistDate = dataList[2] is DBNull ? new DateTime(2099, 12, 31) : (DateTime)dataList[2]
                });
            }
            if (preList != null)
            {
                foreach (var stock in preList)
                {
                    if (items.Find(x => x.code == stock.code) == null)
                    {
                        items.Add(stock);
                    }
                }
            }
            return(items.OrderBy(x => x.code).ToList());
        }