Exemplo n.º 1
0
        protected override List <StockDaily> readFromWind(string code, DateTime dateStart, DateTime dateEnd, string tag = null, IDictionary <string, object> options = null)
        {
            WindAPI  w        = Platforms.GetWindAPI();
            WindData wd       = w.wsd(code, "open,high,low,close,volume,amt,adjfactor,settle,pre_close,pre_settle", dateStart, dateEnd, "Fill=Previous");
            int      len      = wd.timeList.Length;
            int      fieldLen = wd.fieldList.Length;

            var items = new List <StockDaily>(len * fieldLen);

            if (wd.data is double[])
            {
                double[]   dataList = (double[])wd.data;
                DateTime[] timeList = wd.timeList;
                for (int k = 0; k < len; k++)
                {
                    items.Add(new StockDaily
                    {
                        time         = timeList[k],
                        open         = dataList[k * fieldLen + 0],
                        high         = dataList[k * fieldLen + 1],
                        low          = dataList[k * fieldLen + 2],
                        close        = dataList[k * fieldLen + 3],
                        volume       = dataList[k * fieldLen + 4],
                        amount       = dataList[k * fieldLen + 5],
                        adjustFactor = dataList[k * fieldLen + 6],
                        settle       = dataList[k * fieldLen + 7],
                        preClose     = dataList[k * fieldLen + 8],
                        preSettle    = dataList[k * fieldLen + 9]
                    });
                }
            }

            return(items);
        }
        public override List <FuturesDaily> readFromWind(string code, DateTime dateStart, DateTime dateEnd, string tag = null, IDictionary <string, object> options = null)
        {
            WindAPI  w        = Platforms.GetWindAPI();
            WindData wd       = w.wsd(code, "open,high,low,close,volume,amt", dateStart, dateEnd, "Fill=Previous");
            int      len      = wd.timeList.Length;
            int      fieldLen = wd.fieldList.Length;

            var items = new List <FuturesDaily>(len * fieldLen);

            if (wd.data is double[])
            {
                double[]   dataList = (double[])wd.data;
                DateTime[] timeList = wd.timeList;
                for (int k = 0; k < len; k++)
                {
                    items.Add(new FuturesDaily
                    {
                        time   = timeList[k],
                        open   = (double)dataList[k * fieldLen + 0],
                        high   = (double)dataList[k * fieldLen + 1],
                        low    = (double)dataList[k * fieldLen + 2],
                        close  = (double)dataList[k * fieldLen + 3],
                        volume = (double)dataList[k * fieldLen + 4],
                        amount = (double)dataList[k * fieldLen + 5]
                    });
                }
            }
            return(items);
        }
Exemplo n.º 3
0
        public static string[] Query(string code, string field, string start, string end)
        {
            WindData result;

            lock (_threadLock)
            {
                result = _api.wsd(code, field, start, end, "");
            }

            return(DataHelper.ParseInfo(result, "wsd"));;
        }
Exemplo n.º 4
0
        static void DoAPISameple()
        {
            WindAPI w = new WindAPI();

            w.start();

            //wset取沪深300指数成分
            //WindData wd = w.wset("IndexConstituent", "date=20141215;windcode=000300.SH");
            //OutputWindData(wd, "wset");

            WindData wd = w.wsd("I2009.DCE", "open", "2020-05-24", "2020-05-24", "");

            OutputWindData(wd, "wsd");

            w.stop();
        }
Exemplo n.º 5
0
        protected override List <StockDailyWithFactor> readFromWind(string code, DateTime dateStart, DateTime dateEnd, string tag = null, IDictionary <string, object> options = null)
        {
            WindAPI  w        = Platforms.GetWindAPI();
            WindData wd       = w.wsd(code, "open,high,low,close,volume,amt,adjfactor,settle,pre_close,pre_settle,mkt_cap_CSRC,mkt_cap_float,pe_ttm,pb,ps_ttm,industry2", dateStart, dateEnd, "Fill=Previous;currencyType=;ruleType=3;industryType=1;industryStandard=1");
            int      len      = wd.timeList.Length;
            int      fieldLen = wd.fieldList.Length;

            var items = new List <StockDailyWithFactor>(len * fieldLen);

            // if (wd.data is double[])
            {
                object[]   dataList = (object[])wd.data;
                DateTime[] timeList = wd.timeList;

                for (int k = 0; k < len; k++)
                {
                    items.Add(new StockDailyWithFactor
                    {
                        time             = timeList[k],
                        open             = (double)dataList[k * fieldLen + 0],
                        high             = (double)dataList[k * fieldLen + 1],
                        low              = (double)dataList[k * fieldLen + 2],
                        close            = (double)dataList[k * fieldLen + 3],
                        volume           = (double)dataList[k * fieldLen + 4],
                        amount           = (double)dataList[k * fieldLen + 5],
                        adjustFactor     = (double)dataList[k * fieldLen + 6],
                        settle           = Convert.IsDBNull(dataList[k * fieldLen + 7])?0:(double)dataList[k * fieldLen + 7],
                        preClose         = (double)dataList[k * fieldLen + 8],
                        preSettle        = Convert.IsDBNull(dataList[k * fieldLen + 9])?0:(double)dataList[k * fieldLen + 9],
                        marketValue      = (double)dataList[k * fieldLen + 10],
                        floatMarketValue = (double)dataList[k * fieldLen + 11],
                        PE       = (double)dataList[k * fieldLen + 12],
                        PB       = (double)dataList[k * fieldLen + 13],
                        PS       = (double)dataList[k * fieldLen + 14],
                        industry = (string)dataList[k * fieldLen + 15]
                    });
                }
            }

            return(items);
        }
Exemplo n.º 6
0
        public override List <StockDailyMarket> readFromWind(string code, DateTime startDate, DateTime endDate, string tag = null, IDictionary <string, object> options = null)
        {
            if (Caches.WindConnection == false && Caches.WindConnectionTry == true)
            {
                return(null);
            }
            WindAPI  w        = Platforms.GetWindAPI();
            WindData wd       = w.wsd(code, "pre_close,open,high,low,close,volume,amt,dealnum,chg,pct_chg,swing,vwap,adjfactor,turn,free_turn,trade_status,susp_reason,susp_days,maxupordown", startDate.ToString("yyyy-MM-dd"), endDate.ToString("yyyy-MM-dd"), "");
            int      len      = wd.timeList.Length;
            int      fieldLen = wd.fieldList.Length;
            var      items    = new List <StockDailyMarket>(len * fieldLen);

            DateTime[] timeList = wd.timeList;
            object[]   dataList = (object[])wd.data;
            for (int k = 0; k < len; k++)
            {
                //if (code == "000059.SZ" && k == 2049)
                //{
                //    var mycode = code;
                //    var mytime = timeList[k];
                //    var mypreClose = (double)Kit.DBNullToZero(dataList[k * fieldLen + 0]);
                //    Console.WriteLine(Kit.DBNullToZero(dataList[k * fieldLen + 1]).GetType());
                //    Console.WriteLine(Convert.ToDouble(dataList[k * fieldLen + 1]));
                //    var myopen = (double)Kit.DBNullToZero(dataList[k * fieldLen + 1]);
                //    var myhigh = (double)dataList[k * fieldLen + 2];
                //    var mylow = (double)dataList[k * fieldLen + 3];
                //    var myclose = (double)dataList[k * fieldLen + 4];
                //    var myvolume = (double)dataList[k * fieldLen + 5];
                //    var myamount = (double)dataList[k * fieldLen + 6];
                //    var mydealnum = dataList[k * fieldLen + 7] is DBNull ? 0 : (double)dataList[k * fieldLen + 7];
                //    var myupsAndDowns = (double)dataList[k * fieldLen + 8];
                //    var mypercentUpsAndDowns = (double)dataList[k * fieldLen + 9];
                //    var myswing = (double)dataList[k * fieldLen + 10];
                //    var myvwap = dataList[k * fieldLen + 11] is DBNull ? 0 : (double)dataList[k * fieldLen + 11];
                //    var myadjfactor = (double)dataList[k * fieldLen + 12];
                //    var myturn = (double)dataList[k * fieldLen + 13];
                //    var myfree_turn = (double)dataList[k * fieldLen + 14];
                //    var mytrade_status = dataList[k * fieldLen + 15] is DBNull ? string.Empty : Convert.ToString(dataList[k * fieldLen + 15]);
                //    var mysusp_reason = dataList[k * fieldLen + 16] is DBNull ? string.Empty : Convert.ToString(dataList[k * fieldLen + 16]);
                //    var mysusp_days = dataList[k * fieldLen + 17] is DBNull ? 0 : (int)dataList[k * fieldLen + 17];
                //    var mymaxUpOrDown = (int)dataList[k * fieldLen + 18];
                //}
                items.Add(new StockDailyMarket
                {
                    code               = code,
                    time               = timeList[k],
                    preClose           = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 0])),
                    open               = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 1])),
                    high               = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 2])),
                    low                = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 3])),
                    close              = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 4])),
                    volume             = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 5])),
                    amount             = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 6])),
                    dealnum            = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 7])),
                    upsAndDowns        = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 8])),
                    percentUpsAndDowns = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 9])),
                    swing              = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 10])),
                    vwap               = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 11])),
                    adjfactor          = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 12])),
                    turn               = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 13])),
                    free_turn          = Convert.ToDouble(Kit.DBNullToZero(dataList[k * fieldLen + 14])),
                    trade_status       = dataList[k * fieldLen + 15] is DBNull ? string.Empty : Convert.ToString(dataList[k * fieldLen + 15]),
                    susp_reason        = dataList[k * fieldLen + 16] is DBNull ? string.Empty : Convert.ToString(dataList[k * fieldLen + 16]),
                    susp_days          = Convert.ToInt32(Kit.DBNullToZero(dataList[k * fieldLen + 17])),
                    maxUpOrDown        = Convert.ToInt32(Kit.DBNullToZero(dataList[k * fieldLen + 18]))
                });
                // Console.Write("{0}  ", k);
            }
            return(items);
        }
Exemplo n.º 7
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;
                }
            }
        }
Exemplo n.º 8
0
        public WindData getDataSet()
        {
            WindData wd = w.wsd(_SecCodes, _Fields, _BegT.ToShortDateString(), _EndT.ToShortDateString(), "");

            return(wd);
        }
Exemplo n.º 9
0
        public static unsafe Bar[] DumpBarByWind(string code, string startDate, string endDate, BarType barType)
        {
            var ret = new List <Bar>();

            if (barType == BarType.Day || barType == BarType.Week)
            {
                WindData wd = wind.wsd(code, "open,high,low,close,volume,settle,oi", startDate, endDate, "");

                if (wd.data == null)
                {
                    return(ret.ToArray());
                }

                object[,] data = wd.getDataByFunc("wsd", false) as object[, ];
                var w = wd.fieldList.Length;
                var l = (int)(data.Length / w);

                for (var i = 0; i < l; i++)
                {
                    var bar = new Bar();

                    bar.TradingDay = int.Parse(wd.timeList[i].ToString("yyyyMMdd"));
                    bar.D          = wd.timeList[i];

                    bar.Settle   = data[i, 5].GetDouble();
                    bar.O        = data[i, 0].GetDouble();
                    bar.H        = data[i, 1].GetDouble();
                    bar.L        = data[i, 2].GetDouble();
                    bar.C        = data[i, 3].GetDouble();
                    bar.V        = data[i, 4].GetDouble();
                    bar.I        = data[i, 6].GetDouble();
                    bar.WindCode = code;
                    bar.BarType  = barType;
                    ret.Add(bar);
                }
            }
            else
            {
                var wd = wind.wsi(code, "open,high,low,close,volume,oi", startDate, endDate, $"BarSize={(int)barType}");

                if (wd.data == null)
                {
                    return(ret.ToArray());
                }

                object[,] data = wd.getDataByFunc("wsi", false) as object[, ];
                if (data == null)
                {
                    Console.WriteLine($"{code} not find wsi {startDate} ~ {endDate}");
                    return(ret.ToArray());
                }

                var w = wd.fieldList.Length;
                var l = (int)(data.Length / w);

                for (var i = 0; i < l; i++)
                {
                    var bar = new Bar();

                    bar.TradingDay = int.Parse(wd.timeList[i].ToString("yyyyMMdd"));
                    bar.D          = wd.timeList[i];

                    bar.O        = data[i, 0].GetDouble();
                    bar.H        = data[i, 1].GetDouble();
                    bar.L        = data[i, 2].GetDouble();
                    bar.C        = data[i, 3].GetDouble();
                    bar.V        = data[i, 4].GetDouble();
                    bar.I        = data[i, 5].GetDouble();
                    bar.WindCode = code;
                    bar.BarType  = barType;
                    ret.Add(bar);
                }
            }

            return(ret.ToArray());
        }
Exemplo n.º 10
0
        private SortedDictionary <string, stockEquity> GetStockData()
        {
            SortedDictionary <string, stockEquity> myData = new SortedDictionary <string, stockEquity>();
            string yesterdayStr = DateTime.ParseExact(yesterday.ToString(), "yyyyMMdd", null).ToString("yyyy-MM-dd");
            string firstDate    = "2017-01-01";

            foreach (var item in GetStocks.stockList)
            {
                string   code      = item.Key;
                WindData wd        = w.wsd(code, "close,free_float_shares,float_a_shares", "ED-0D", firstDate, "Days=Alldays");
                double[] stockList = wd.data as double[];
                int      num       = (stockList == null ? 0 : stockList.Length / 3);
                if (num == 1)
                {
                    stockEquity myEquity = new stockEquity();
                    myEquity.code       = item.Value.code;
                    myEquity.name       = item.Value.name;
                    myEquity.date       = yesterday;
                    myEquity.closePrice = (double)stockList[0];
                    myEquity.freeEquity = (double)stockList[1];
                    myEquity.equity     = (double)stockList[2];
                    double percentage = myEquity.freeEquity / myEquity.equity;
                    if (percentage <= 0.15)
                    {
                        myEquity.percentage = Math.Ceiling(percentage * 100) / 100;
                    }
                    else if (percentage <= 0.2)
                    {
                        myEquity.percentage = 0.2;
                    }
                    else if (percentage <= 0.8)
                    {
                        myEquity.percentage = Math.Ceiling(percentage * 10) / 10;
                    }
                    else
                    {
                        myEquity.percentage = 1;
                    }
                    myData.Add(code, myEquity);
                }
                else
                {
                    Console.WriteLine("There is something wrong with {0}", code);
                }
            }

            WindData wd2 = w.wsd(indexName, "close,free_float_shares,float_a_shares", "ED-0D", firstDate, "Days=Alldays");

            double[] stockList2 = wd2.data as double[];
            double   num2       = (stockList2 == null ? 0 : stockList2.Length / 3);

            if (num2 == 1)
            {
                stockEquity myEquity = new stockEquity();
                myEquity.code       = indexName;
                myEquity.name       = indexName;
                myEquity.date       = yesterday;
                myEquity.closePrice = (double)stockList2[0];
                myEquity.freeEquity = (double)stockList2[1];
                myEquity.equity     = (double)stockList2[2];
                double percentage = myEquity.freeEquity / myEquity.equity;
                if (percentage <= 0.15)
                {
                    myEquity.percentage = Math.Ceiling(percentage * 100) / 100;
                }
                else if (percentage <= 0.2)
                {
                    myEquity.percentage = 0.2;
                }
                else if (percentage <= 0.8)
                {
                    myEquity.percentage = Math.Ceiling(percentage * 10) / 10;
                }
                else
                {
                    myEquity.percentage = 1;
                }
                myData.Add(indexName, myEquity);
            }
            else
            {
                Console.WriteLine("There is something wrong with {0}", indexName);
            }
            return(myData);
        }
Exemplo n.º 11
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());
        }