Exemple #1
0
        public void Excute(string message)
        {
            this.Log().Info("计算开始");

            var msg = JsonConvert.DeserializeObject <CatePriceUpdate>(message);

            IList <data.PriceInfo> priceInfoList = GetPriceList(msg.Code);

            cateService.UpdateCategoryPrice(priceInfoList);
            cateService.AddPriceByDay <data.data_category_day_latest>(priceInfoList);
            cateService.AddPriceByWeek <data.data_category_week_latest>(priceInfoList);
            cateService.AddPriceByMonth <data.data_category_month_latest>(priceInfoList);

            this.Log().Info("计算结束");
        }
        public void Execute(IJobExecutionContext context)
        {
            LoggingExtensions.Logging.Log.InitializeWith <LoggingExtensions.log4net.Log4NetLog>();

            this.Log().Info("计算开始");
            //获取行业列表
            IList <data.stockcategory> list;

            if (string.IsNullOrEmpty(this.CategoryCode) || this.CategoryCode == "-1")
            {
                list = cateService.GetCategoryList("tencent");
            }
            else
            {
                string[] cates = this.CategoryCode.Split(',');
                list = cateService.GetCategoryList("tencent").Where(p => cates.Contains(p.code)).ToList();
            }


            //遍历列表,获取行业下的股票,计算指数,更新指数

            IList <data.PriceInfo> priceInfoList = new List <data.PriceInfo>();

            foreach (var item in list)
            {
                //IList<data.stock> stocks = stockService.GetStockByCategory(item.code);
                DateTime today     = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                decimal  yestclose = GetYestclose(item.code, today);

                //获取基期的值
                int     i         = -1;
                bool    isOk      = false;
                decimal baseValue = 0;
                while (!isOk)
                {
                    var priceList = stockService.GetStockPriceByDate(item.code, data.TechCycle.day, DateTime.Now.AddDays(i--));
                    if (priceList == null || priceList.Count == 0)
                    {
                        continue;
                    }
                    decimal total = 0, baseIndex = 100;
                    foreach (var priceInfo in priceList)
                    {
                        total += priceInfo.price ?? 1 * priceInfo.volume ?? 1;
                    }
                    baseValue = (total * 100) / yestclose;
                    isOk      = true;
                }

                //index = (total / baseValue) * 100;


                var     priceList0 = stockService.GetStockPriceByDate(item.code, data.TechCycle.day, today);
                decimal vol = 0, turnover = 0;
                decimal total1 = 0;
                foreach (var priceInfo in priceList0)
                {
                    total1   += priceInfo.price ?? 1 * priceInfo.volume ?? 1;
                    vol      += priceInfo.volume ?? 1;
                    turnover += priceInfo.turnover ?? 1;
                }

                decimal index = (total1 / baseValue) * 100;

                var percent = (index - yestclose) * 100 / yestclose;
                var info    = new data.PriceInfo
                {
                    code      = item.code,
                    date      = today,
                    price     = Math.Round(index, 2),
                    high      = 0,
                    low       = 0,
                    yestclose = yestclose,
                    volume    = vol,
                    turnover  = turnover,
                    percent   = percent,
                    open      = Math.Round(index, 2),
                };

                priceInfoList.Add(info);
                this.Log().Info(string.Format("行业:{0},值:{1}", item.code, info.price));
            }
            cateService.UpdateCategoryPrice(priceInfoList);
            cateService.AddPriceByDay <data.data_category_day_latest>(priceInfoList);
            cateService.AddPriceByWeek <data.data_category_week_latest>(priceInfoList);
            cateService.AddPriceByMonth <data.data_category_month_latest>(priceInfoList);
            this.Log().Info("计算结束");
        }
Exemple #3
0
        /// <summary>
        /// 计算某行业,每周期的指数值
        /// </summary>
        /// <param name="categoryCode"></param>
        /// <param name="cycle"></param>
        private void InitCategoryIndexByCycle(string categoryCode, data.TechCycle cycle)
        {
            //获取某只股票的所有价格列表

            var     stocks    = stockService.GetPriceInfo("0600000", cycle);
            decimal yestclose = 0;
            decimal baseIndex = 100;
            decimal baseValue = 0;

            //计算每个周期的指数值
            for (int i = 0; i < stocks.Count; i++)
            {
                var stock     = stocks[i];
                var priceList = stockService.GetStockPriceByDate(categoryCode, cycle, stock.date);
                if (priceList == null || priceList.Count == 0)
                {
                    continue;
                }
                decimal total = 0, vol = 0, turnover = 0, index = 0;
                foreach (var priceInfo in priceList)
                {
                    total    += priceInfo.price ?? 1 * priceInfo.volume ?? 1;
                    vol      += priceInfo.volume ?? 1;
                    turnover += priceInfo.turnover ?? 1;
                }

                if (baseValue == 0)
                {
                    baseValue = total;
                    index     = 100;
                }
                else
                {
                    index = (total / baseValue) * 100;
                }

                var info = new data.PriceInfo
                {
                    code      = categoryCode,
                    date      = stock.date,
                    price     = Math.Round(index, 2),
                    high      = 0,
                    low       = 0,
                    yestclose = yestclose,
                    volume    = vol,
                    turnover  = turnover,
                    open      = Math.Round(index, 2),
                };

                yestclose = index;

                try
                {
                    //cateService.AddPriceInfo(categoryCode, info, cycle);
                    if (cycle == TechCycle.day)
                    {
                        cateService.AddPriceByDay <data_category_day_latest>(new List <PriceInfo>()
                        {
                            info
                        }, true);
                    }
                    else if (cycle == TechCycle.week)
                    {
                        cateService.AddPriceByWeek <data_category_week_latest>(new List <PriceInfo>()
                        {
                            info
                        }, true);
                    }
                    else if (cycle == TechCycle.month)
                    {
                        cateService.AddPriceByMonth <data_category_month_latest>(new List <PriceInfo>()
                        {
                            info
                        }, true);
                    }

                    this.Log().Info(string.Format("行业指数:周期:{0},日期:{1},类别:{2},数值:{3}", cycle, info.date, categoryCode, info.price));
                }
                catch (Exception ex)
                {
                    //(new System.Collections.Generic.Mscorlib_CollectionDebugView<System.Data.Entity.Validation.DbEntityValidationResult>(((System.Data.Entity.Validation.DbEntityValidationException)(ex)).EntityValidationErrors as System.Collections.Generic.List<System.Data.Entity.Validation.DbEntityValidationResult>)).Items[0].ValidationErrors


                    this.Log().Error(ex.Message);
                }
            }
        }