Пример #1
0
        private static List <dynamic> GetStyleExcessReturn(string index, DateTime begin, DateTime end)
        {
            var indexQuotations = DataDao.GetIndexQuotations("000985", begin, end);
            var styleQuotations = DataDao.GetIndexQuotations(index, begin, end);
            var result          = new List <dynamic>();

            while (begin <= end)
            {
                var quotations = indexQuotations.Where(x => x.Date >= begin && x.Date <= begin.AddDays(7)).ToList();
                if (!quotations.Any())
                {
                    begin = begin.AddDays(7);
                    continue;
                }

                var indexRate   = quotations.Last().Close / quotations.First().Close - 1;
                var quotations2 = styleQuotations.Where(x => x.Date >= begin && x.Date <= begin.AddDays(7)).ToList();
                if (!quotations2.Any())
                {
                    break;
                }

                dynamic excessReturn = new ExpandoObject();
                excessReturn.Begin        = begin.AddDays(1);
                excessReturn.End          = begin.AddDays(7);
                excessReturn.ExcessReturn = quotations2.Last().Close / quotations2.First().Close - 1 - indexRate;
                result.Add(excessReturn);

                begin = begin.AddDays(7);
            }

            return(result);
        }
Пример #2
0
        private static async Task <List <dynamic> > GetFundExcessReturn(string fundCode, DateTime begin, DateTime end)
        {
            var indexQuotations = DataDao.GetIndexQuotations("000985", begin, end);
            var navs            = await DataService.GetFundNavs(fundCode);

            var result = new List <dynamic>();

            while (begin <= end)
            {
                var quotations = indexQuotations.Where(x => x.Date >= begin && x.Date <= begin.AddDays(7)).ToList();
                if (!quotations.Any())
                {
                    begin = begin.AddDays(7);
                    continue;
                }

                var indexRate = quotations.Last().Close / quotations.First().Close - 1;
                var subNavs   = navs.Where(x => x.Date >= begin && x.Date <= begin.AddDays(7)).ToList();
                if (!subNavs.Any())
                {
                    begin = begin.AddDays(7);
                    continue;
                }

                dynamic excessReturn = new ExpandoObject();
                excessReturn.Begin        = begin.AddDays(1);
                excessReturn.End          = begin.AddDays(7);
                excessReturn.ExcessReturn = subNavs.Last().AccUnitNav / subNavs[0].AccUnitNav - 1 - indexRate;
                result.Add(excessReturn);

                begin = begin.AddDays(7);
            }

            return(result);
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="indexCode"></param>
        /// <param name="begin"></param>
        /// <param name="end"></param>
        /// <param name="source">数据来源 0 数据库 1 接口</param>
        /// <returns></returns>
        public static async Task <List <IndexQuotation> > GetIndexQuotations(string indexCode, DateTime begin, DateTime end, int source = 1)
        {
            var quotations = DataDao.GetIndexQuotations(indexCode, begin, end);

            if (DataHelper.IsDataReady(quotations?.OrderBy(x => x.UpdateTime).FirstOrDefault()))
            {
                return(quotations);
            }
            else if (source == 1)
            {
                quotations = await SwService.GetIndexQuotations(begin, end, indexCode);

                DataDao.UpdateIndexQuotations(quotations);
                return(quotations);
            }
            else
            {
                return(new List <IndexQuotation>());
            }
        }
Пример #4
0
        private static List <StyleInflection> GetStyleInflections(string index)
        {
            var result     = new List <StyleInflection>();
            var quotations = DataDao.GetIndexQuotations(index, DateTime.Now.Date.AddYears(-5), DateTime.Now.Date);

            if (quotations.IsNullOrEmpty())
            {
                Log.Warning($"获取不到近五年的 {index} 行情数据,无法计算拐点");
                return(result);
            }
            var lastDate = quotations.Last().Date;

            if (lastDate < DateTime.Now.AddMonths(-1).Date)
            {
                Log.Warning($"{index} 最新的行情日期为 {lastDate.ToString("yyyy-MM-dd")},请及时更新数据");
            }
            else
            {
                Log.Information($"{index} 最新的行情日期为 {lastDate.ToString("yyyy-MM-dd")}");
            }

            var rates      = MathHelper.GetIncreaseRates(quotations);
            var inflection = GetInflection(rates, 0);

            while (inflection.Begin > DateTime.MinValue)
            {
                var q = quotations.FirstOrDefault(x => x.Date == inflection.Begin);
                result.Add(new StyleInflection
                {
                    Date      = inflection.Begin,
                    Close     = q?.Close ?? 0,
                    Type      = inflection.Type,
                    IndexCode = q?.IndexCode,
                    IndexName = q?.IndexName
                });

                inflection = GetInflection(rates.FindAll(x => x.Date > inflection.End), -inflection.Type);
            }
            return(result);
        }