Esempio n. 1
0
        /// <summary>
        /// 缓存KDJ分布值
        /// </summary>
        private static void CacheTechnicalIndex_KDJ()
        {
            var lstKDJ = MongoDBHelper.AsQueryable <KDJResult>().ToList();;

            //指标明细
            List <IndexDetailDTO> lstDto  = new List <IndexDetailDTO>();
            List <SelectOption>   lstLeft = GetLeftSelectOption(ConstDefine.Cst_KDJ);

            foreach (SelectOption option in lstLeft)
            {
                IndexDetailDTO dtoKDJ = new IndexDetailDTO();
                lstDto.Add(dtoKDJ);

                dtoKDJ.Code         = ConstDefine.Cst_KDJ;
                dtoKDJ.Name         = ConstDefine.Cst_KDJ;
                dtoKDJ.ParamsValues = GetInputParams(ConstDefine.Cst_KDJ);

                dtoKDJ.SelectTerm        = option.SelectItem;
                dtoKDJ.SelectTermDisplay = option.SelectItem;
                dtoKDJ.SelectTermList    = lstLeft;

                //取分布值
                double[] arrayIndexValues = null;
                switch (option.SelectItem)
                {
                case ConstDefine.Cst_KDJ_K:
                    dtoKDJ.IsDefault = true;
                    arrayIndexValues = lstKDJ.Select(m => m.K).OrderBy(m => m).ToArray();
                    break;

                case ConstDefine.Cst_KDJ_D:
                    arrayIndexValues = lstKDJ.Select(m => m.D).OrderBy(m => m).ToArray();
                    break;

                case ConstDefine.Cst_KDJ_J:
                    arrayIndexValues = lstKDJ.Select(m => m.J).OrderBy(m => m).ToArray();
                    break;
                }

                //设置最大值、最小值、分布值
                SetMaxMinArrValue(dtoKDJ, arrayIndexValues);
            }

            Dictionary <string, string> dicCodeName = new Dictionary <string, string>();

            dicCodeName[ConstDefine.Cst_KDJ_GoldX]      = ConstDefine.Cst_KDJ_GoldX_Name;
            dicCodeName[ConstDefine.Cst_KDJ_BlackX]     = ConstDefine.Cst_KDJ_BlackX_Name;
            dicCodeName[ConstDefine.Cst_KDJ_LowGoldX]   = ConstDefine.Cst_KDJ_LowGoldX_Name;
            dicCodeName[ConstDefine.Cst_KDJ_TopDepart]  = ConstDefine.Cst_KDJ_TopDepart_Name;
            dicCodeName[ConstDefine.Cst_KDJ_DownDepart] = ConstDefine.Cst_KDJ_DownDepart_Name;
            dicCodeName[ConstDefine.Cst_KDJ_Oversold]   = ConstDefine.Cst_KDJ_Oversold_Name;
            dicCodeName[ConstDefine.Cst_KDJ_Overbought] = ConstDefine.Cst_KDJ_Overbought_Name;
            foreach (string indexCode in dicCodeName.Keys)
            {
                IndexDetailDTO dto = new IndexDetailDTO();
                lstDto.Add(dto);

                dto.Code         = indexCode;
                dto.Name         = dicCodeName[indexCode];
                dto.ParamsValues = GetInputParams(ConstDefine.Cst_KDJ);
                dto.IsDefault    = true;
            }

            //删除原有的
            List <string> lstIndexCode = new List <string>();

            lstIndexCode.Add(ConstDefine.Cst_KDJ);
            lstIndexCode.AddRange(dicCodeName.Keys);
            string codes = string.Join("','", lstIndexCode);

            MongoDBHelper.DeleteMany <IndexDetailDTO>("{Code:{$in:['" + codes + "']}}");

            //插入MACD技术指标指标的明细
            MongoDBHelper.InsertManyAsync <IndexDetailDTO>(lstDto);
        }
Esempio n. 2
0
        /// <summary>
        /// 缓存DMI分布值
        /// </summary>
        private static void CacheTechnicalIndex_DMI()
        {
            var lstDMI = MongoDBHelper.AsQueryable <DMIResult>().ToList();;

            //指标明细
            List <IndexDetailDTO> lstDto  = new List <IndexDetailDTO>();
            List <SelectOption>   lstLeft = GetLeftSelectOption(ConstDefine.Cst_DMI);

            foreach (SelectOption option in lstLeft)
            {
                IndexDetailDTO dtoBOLL = new IndexDetailDTO();
                lstDto.Add(dtoBOLL);

                dtoBOLL.Code         = ConstDefine.Cst_DMI;
                dtoBOLL.Name         = ConstDefine.Cst_DMI;
                dtoBOLL.ParamsValues = GetInputParams(ConstDefine.Cst_DMI);

                dtoBOLL.SelectTerm        = option.SelectItem;
                dtoBOLL.SelectTermDisplay = option.SelectItem;
                dtoBOLL.SelectTermList    = lstLeft;

                //取分布值
                double[] arrayIndexValues = null;
                switch (option.SelectItem)
                {
                case ConstDefine.Cst_DMI_PDI:
                    dtoBOLL.IsDefault = true;
                    arrayIndexValues  = lstDMI.Select(m => m.PDI).OrderBy(m => m).ToArray();
                    break;

                case ConstDefine.Cst_DMI_MDI:
                    arrayIndexValues = lstDMI.Select(m => m.MDI).OrderBy(m => m).ToArray();
                    break;

                case ConstDefine.Cst_DMI_ADX:
                    arrayIndexValues = lstDMI.Where(m => m.ADX.HasValue).Select(m => m.ADX.Value).OrderBy(m => m).ToArray();
                    break;
                }
                //设置最大值、最小值、分布值
                SetMaxMinArrValue(dtoBOLL, arrayIndexValues);
            }

            Dictionary <string, string> dicCodeName = new Dictionary <string, string>();

            dicCodeName[ConstDefine.Cst_DMI_GoldX]  = ConstDefine.Cst_DMI_GoldX_Name;
            dicCodeName[ConstDefine.Cst_DMI_BlackX] = ConstDefine.Cst_DMI_BlackX_Name;
            foreach (string indexCode in dicCodeName.Keys)
            {
                IndexDetailDTO dto = new IndexDetailDTO();
                lstDto.Add(dto);

                dto.Code         = indexCode;
                dto.Name         = dicCodeName[indexCode];
                dto.ParamsValues = GetInputParams(ConstDefine.Cst_DMI);
                dto.IsDefault    = true;
            }

            //删除原有的
            List <string> lstIndexCode = new List <string>();

            lstIndexCode.Add(ConstDefine.Cst_DMI);
            lstIndexCode.AddRange(dicCodeName.Keys);
            string codes = string.Join("','", lstIndexCode);

            MongoDBHelper.DeleteMany <IndexDetailDTO>("{Code:{$in:['" + codes + "']}}");

            //插入MACD技术指标指标的明细
            MongoDBHelper.InsertManyAsync <IndexDetailDTO>(lstDto);
        }
Esempio n. 3
0
        /// <summary>
        /// 缓存行情指标的明细
        /// </summary>
        public static void CacheDataByTimeIndex()
        {
            LogHelper.Info("总运行", "开始:生成行情指标明细");

            //取得财务指标编号、名称
            var lstIndexLite = from dto in MongoDBHelper.AsQueryable <IndexTreeDTO>()
                               where dto.TypeCode == ConstDefine.CstCode_MarketIndex
                               select new IndexLiteDTO()
            {
                Code = dto.Code,
                Name = dto.Name
            };

            //遍历指标编号,生成选股条件信息
            foreach (IndexLiteDTO indexLite in lstIndexLite)
            {
                //取指定指标的所有指标股票信息
                var lstDataByTimeIndex = MongoDBHelper.AsQueryable <DataByTimeIndexInfo>().Where(m => m.IndexCode == indexLite.Code).ToList();
                if (lstDataByTimeIndex.Count == 0)
                {
                    continue;
                }

                //按交易日分组
                var groupByTradingDateIndex = (from index in lstDataByTimeIndex
                                               group index by index.TradingDate into g
                                               orderby g.Key descending
                                               select new
                {
                    TradingDate = g.Key,
                    TradingDateName = g.First().TradingDateName,
                    groupList = g
                }).Take(5);

                //交易日分组列表
                var lstSelectTerm = from groupIndex in groupByTradingDateIndex
                                    orderby groupIndex.TradingDate descending
                                    select new SelectOption()
                {
                    SelectItem    = TransferHelper.DateTimeToString(groupIndex.TradingDate),
                    SelectDisplay = groupIndex.TradingDateName
                };
                List <SelectOption> selectTermList = lstSelectTerm.ToList();

                //指标明细
                List <IndexDetailDTO> lstDto = new List <IndexDetailDTO>();
                //按交易日遍历
                foreach (var groupByEndDate in groupByTradingDateIndex)
                {
                    IndexDetailDTO dto = new IndexDetailDTO();
                    lstDto.Add(dto);

                    dto.Code              = indexLite.Code;
                    dto.Name              = indexLite.Name;
                    dto.SelectTerm        = TransferHelper.DateTimeToString(groupByEndDate.TradingDate);
                    dto.SelectTermDisplay = groupByEndDate.TradingDateName;
                    dto.SelectTermList    = selectTermList;

                    //取分布值
                    var arrayIndexValues = groupByEndDate.groupList.Select(m => m.IndexValue).OrderBy(m => m).ToArray();
                    //设置最大值、最小值、分布值
                    SetMaxMinArrValue(dto, arrayIndexValues);
                }

                //设置默认选项(第一个)
                if (lstDto.Count > 0)
                {
                    lstDto[0].IsDefault = true;
                }

                //删除原有的
                MongoDBHelper.DeleteMany <IndexDetailDTO>("{Code:'" + indexLite.Code + "'}");
                //插入行情指标的明细
                MongoDBHelper.InsertManyAsync <IndexDetailDTO>(lstDto);
            }

            LogHelper.Info("总运行", "结束:生成行情指标明细");
        }