Exemplo n.º 1
0
        public static double BuyLine(DateTime date, string Code)
        {
            int[]         line     = { 20, 250 };
            List <double> buyLines = new List <double>();
            List <string> result   = new List <string>();
            var           data     = DBHelper._db.SHAs.Where(tb => tb.Code == CodeHelper.CodeToDBCode(Code)).Select(tb => new
            {
                tb.Date,
                tb.Closing
            }).ToList();

            for (int i = 0; i < line.Length; i++)
            {
                var before = data.Where(tb => tb.Date <= date).OrderByDescending(tb => tb.Date).Take(line[i]).ToList();
                var avg    = before.Sum(tb => tb.Closing) / before.Count;

                buyLines.Add(avg);
            }

            return(buyLines.Min());
        }
Exemplo n.º 2
0
        public static void UpdateMA(string Code)
        {
            var alldata = DBHelper._db.SHAs.Where(tb => tb.Code == CodeHelper.CodeToDBCode(Code)).OrderByDescending(tb => tb.Date).ToList();
            var needcal = alldata.Where(tb => tb.MA5 == 0).ToList();

            foreach (var a in needcal)
            {
                if (a.MA5 == -1 || a.MA5 > 0)
                {
                    continue;
                }
                var current = alldata.Where(tb => tb.Date <= a.Date).OrderByDescending(tb => tb.Date).ToList();
                if (current.Count < 250)
                {
                    a.MA5   = -1;
                    a.MA10  = -1;
                    a.MA20  = -1;
                    a.MA30  = -1;
                    a.MA60  = -1;
                    a.MA90  = -1;
                    a.MA120 = -1;
                    a.MA200 = -1;
                    a.MA250 = -1;
                }
                else
                {
                    a.MA5   = current.Take(5).Sum(tb => tb.Closing) / 5;
                    a.MA10  = current.Take(10).Sum(tb => tb.Closing) / 10;
                    a.MA20  = current.Take(20).Sum(tb => tb.Closing) / 20;
                    a.MA30  = current.Take(30).Sum(tb => tb.Closing) / 30;
                    a.MA60  = current.Take(60).Sum(tb => tb.Closing) / 60;
                    a.MA90  = current.Take(90).Sum(tb => tb.Closing) / 90;
                    a.MA120 = current.Take(120).Sum(tb => tb.Closing) / 120;
                    a.MA200 = current.Take(200).Sum(tb => tb.Closing) / 200;
                    a.MA250 = current.Take(250).Sum(tb => tb.Closing) / 250;
                }
                DBHelper._db.Update(a);
            }
            DBHelper._db.SaveChanges();
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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("");
        }