예제 #1
0
        public static string Analysis(DateTime?date, string Code)
        {
            var thisdate = date == null ? DateTime.Now : date.Value;

            string CHName = CodeHelper.CodeDic[Code];

            int[]           ago        = { 1, 3, 6, 12, 36, 60 };
            string[]        agomessage = { "近1月百分比:", "近3月百分比:", "近6月百分比:", "近1年百分比:", "近3年百分比:", "近5年百分比:" };
            List <DateTime> dateTimes  = new List <DateTime>();



            for (int i = 0; i < ago.Length; i++)
            {
                dateTimes.Add(thisdate.AddDays(30 * ago[i] * -1));
            }

            var data = DBHelper._db.SHAs.Where(tb => tb.Code == CodeHelper.CodeToDBCode(Code)).Select(tb => new
            {
                tb.Date,
                tb.Closing
            }).OrderByDescending(tb => tb.Date).ToList();

            var thisdata = data[0];

            string Message = "<br><h3>" + CHName + " " + thisdata.Date.ToString("yyyy-MM-dd") + " 收盘:" + thisdata.Closing.ToString("f2") + "</h3>";

            //if (Code == "000001")
            {
                var buyline = BuyLine(thisdata.Date, Code);
                if (thisdata.Closing >= buyline && thisdata.Closing / buyline < 1.01)
                {
                    Message += "<h4  style='color:green'>注意:即将进入买入区间</h4>";
                }
                if (thisdata.Closing < buyline)
                {
                    Message += "<h4  style='color:green'>" + "下一交易日参考买点:" + buyline.ToString("f2") + "</h4>";
                }
                else
                {
                    Message += "<h4  style='color:red'>" + "下一交易日参考买点:" + buyline.ToString("f2") + "</h4>";
                }
            }

            for (int i = 0; i < dateTimes.Count; i++)
            {
                var currentData = data.Where(tb => tb.Date >= dateTimes[i]).ToList();
                var rank        = ((double)currentData.Where(tb => tb.Closing < thisdata.Closing).ToList().Count * 100) / currentData.Count;
                if (rank < 30)
                {
                    Message += "<h5 style='color:green'>" + agomessage[i] + rank.ToString("f2") + "%</h5>";
                }
                else if (rank < 70)
                {
                    Message += "<h5 style='color:orange'>" + agomessage[i] + rank.ToString("f2") + "%</h5>";
                }
                else
                {
                    Message += "<h5 style='color:red'>" + agomessage[i] + rank.ToString("f2") + "%</h5>";
                }
            }

            return(Message);
        }
예제 #2
0
        public static void UpdateData(string Code)
        {
            string start = "19700101";

            //var datetime = new DateTime(2019, 10, 1);
            //var datas = DBHelper._db.SHAs.Where(tb => tb.Date >= datetime).ToList();
            //DBHelper._db.SHAs.RemoveRange(datas);
            //DBHelper._db.SaveChanges();
            //return;
            try
            {
                start = DBHelper._db.SHAs.Where(tb => tb.Code == CodeHelper.CodeToDBCode(Code)).Max(tb => tb.Date).AddDays(1).ToString("yyyyMMdd");
            }
            catch (Exception e)
            {
            }


            string end = DateTime.Now.AddDays(1).ToString("yyyyMMdd");

            if (start == end)
            {
                return;
            }

            HttpWebRequest request  = (HttpWebRequest)WebRequest.Create(string.Format(url, CodeHelper.CodeToWebCode(Code), start, end));
            WebResponse    response = request.GetResponse();

            Stream resStream = response.GetResponseStream();

            StreamReader reader = new StreamReader(resStream, Encoding.GetEncoding("GB2312"));

            var result = reader.ReadToEnd();

            result = result.Replace("None", "-1");
            var rows = result.Split("\r\n");

            for (int i = 1; i < rows.Length; i++)
            {
                if (rows[i] == "")
                {
                    continue;
                }
                var columns = rows[i].Split(",");

                SHA sha = new SHA();
                sha.Date         = DateTime.Parse(columns[0]);
                sha.Code         = columns[1];
                sha.Name         = columns[2];
                sha.Closing      = double.Parse(columns[3]);
                sha.Highest      = double.Parse(columns[4]);
                sha.Lowest       = double.Parse(columns[5]);
                sha.Opening      = double.Parse(columns[6]);
                sha.FrontOpening = double.Parse(columns[7]);
                sha.UpDown       = double.Parse(columns[8]);
                sha.UpDownWidth  = double.Parse(columns[9]);
                sha.Volume       = double.Parse(columns[10]);
                sha.Turnover     = double.Parse(columns[11]);
                sha.MA5          = 0;
                sha.MA10         = 0;
                sha.MA20         = 0;
                sha.MA30         = 0;
                sha.MA60         = 0;
                sha.MA90         = 0;
                sha.MA120        = 0;
                sha.MA200        = 0;
                sha.MA250        = 0;


                if (Code == "000001")
                {
                    var daydiff   = (sha.Date - new DateTime(1993, 2, 15)).Days;
                    var todaylow  = (daydiff * 23.2091 + 21114.3729) / 100;
                    var todayhigh = (daydiff * 22.2049 + 153682) / 100;
                    sha.ReferUp   = todayhigh;
                    sha.ReferDown = todaylow;
                }

                DBHelper._db.Add(sha);
            }

            DBHelper._db.SaveChanges();
            UpdateMA(Code);
            Console.WriteLine("");
        }