Exemple #1
0
        public Operations calcaulate(History history, DateTime date, Holds holds)
        {
            Operations operations = new Operations();

            foreach (Hold hold in holds.holds)
            {
                var day = history.getDay(hold.stockName, date);
                if (day == null)
                {
                    continue;
                }
                if (hold.buyTime.AddDays(20) > date)
                {
                    continue;
                }
                operations.operations.Add(sell(hold));
            }


            foreach (var stockName in history.stocks.Keys)
            {
                DayResult currentDay = history.getDay(stockName, date);
                if (currentDay == null || currentDay.volume == 0 || currentDay.volume * currentDay.adjClose < 100000000)
                {
                    continue;
                }
                DateTime currentDate = currentDay.date;
                operations.operations.Add(buy(stockName, currentDay.adjClose, holds.cash));
            }
            return(operations);
        }
Exemple #2
0
        private static KeyValuePair <string, Dictionary <DateTime, DayResult> > getStock(string stockName, string result)
        {
            string[] lines = result.Split('\n');
            KeyValuePair <string, Dictionary <DateTime, DayResult> > dataList = new KeyValuePair <string, Dictionary <DateTime, DayResult> >(stockName, new Dictionary <DateTime, DayResult>());

            for (int i = 0; i < lines.Count(); i++)
            {
                if (i == 0)
                {
                    continue;
                }
                string line = lines[i];
                if (String.IsNullOrEmpty(line))
                {
                    continue;
                }
                DayResult data  = new DayResult();
                string[]  items = line.Split(',');
                if (items.Length < 6)
                {
                    continue;
                }

                String[] dayTexts = items[0].Split('-');
                data.date = new DateTime(Convert.ToInt32(dayTexts[0]), Convert.ToInt32(dayTexts[1]), Convert.ToInt32(dayTexts[2]));

                try
                {
                    data.open     = Convert.ToDecimal(items[1]);
                    data.high     = Convert.ToDecimal(items[2]);
                    data.low      = Convert.ToDecimal(items[3]);
                    data.close    = Convert.ToDecimal(items[4]);
                    data.volume   = Convert.ToDecimal(items[5]);
                    data.adjClose = Convert.ToDecimal(items[6]);
                }
                catch (Exception)
                {
                    continue;
                }
                dataList.Value.Add(data.date, data);
            }
            return(dataList);
        }
Exemple #3
0
 public static void Match(History quickDay, DateTime time, Operations operations, Holds holds)
 {
     foreach (Operation operation in operations.operations)
     {
         DayResult day = quickDay.getDay(operation.StockName, time);
         if (day == null)
         {
             continue;
         }
         decimal price = day.adjClose;
         if (operation.Type == OperationType.Buy)
         {
             buy(time, holds, operation, price);
         }
         else
         {
             sell(time, holds, operation, price);
         }
     }
 }
Exemple #4
0
        public static async Task run()
        {
            ResultContainer.Instance.addOutput("开始");
            //DateTime startTime = new DateTime(1990, 12, 19);
            //DateTime endTime = new DateTime(2016, 8, 1);
            DateTime startTime = new DateTime(2006, 1, 1);
            DateTime endTime   = new DateTime(2016, 1, 1);
            History  quickDay  = new History();
            await quickDay.load();

            Holds holds = new Holds();

            holds.cash = 100000;
            DateTime lastDay = startTime.AddDays(-1);

            while (startTime < endTime)
            {
                quickDay.SetLimitDate(startTime);
                Operations operations = new ZhihuAlgorithm().calcaulate(quickDay, startTime, holds);

                Exchange.ExchangeExecutor.Match(quickDay, startTime, operations, holds);
                if (startTime.Year != lastDay.Year || startTime.Month != lastDay.Month)
                {
                    ResultContainer.Instance.addOutput(startTime.ToString());
                    decimal   currentMoney = calculateResult(startTime, quickDay, holds);
                    DayResult marketResult = quickDay.market.Value.SingleOrDefault(c => c.Key == startTime).Value;
                    if (currentMoney != -1 && marketResult != null)
                    {
                        lastDay = startTime;
                        ResultContainer.Instance.addMonthResult(new MonthResult {
                            year = lastDay.Year, month = lastDay.Month, money = currentMoney, market = marketResult.adjClose
                        });
                    }
                }
                startTime = startTime.AddDays(1);
            }
            //减3是因为截止到7月最后一天,+1就到了8月一日,而7月底的最后两天是假期
            calculateResult(endTime, quickDay, holds);
            ResultContainer.Instance.addOutput("全部结束");
        }
        public DayResult Get(DateTime date)
        {
            if (date == DateTime.MinValue)
            {
                date = DateTime.UtcNow.Date;
            }

            var day = _supportSlotRepository.GetSupportDay(date.Date);

            if (day == null)
            {
                if (date.Date.Date < DateTime.UtcNow.Date)
                {
                    return(new DayResult
                    {
                        Date = date.Date
                    });
                }

                var currentDate             = date.Date;
                var lastScheduledSupportDay = _supportSlotRepository.GetLastSupportDay();
                var slidingSupportCycle     = _supportCycleFactory.GetSupportCycle();
                while (day == null || day.Date.Date != date.Date)
                {
                    day = slidingSupportCycle.GenerateNewDay();
                }
            }

            var res = new DayResult
            {
                Date      = date.Date,
                Engeneers = day.Slots.Select(x => x.Engeneer.Name).ToList()
            };

            return(res);
        }
Exemple #6
0
        public Operations calcaulate(History history, DateTime date, Holds holds)
        {
            Operations operations = new Operations();

            foreach (Hold hold in holds.holds)
            {
                var day = history.getDay(hold.stockName, date);
                if (day == null)
                {
                    continue;
                }
                decimal currentPrice = day.adjClose;
                if (currentPrice > hold.buyPrice * (decimal)1.1 || currentPrice < hold.buyPrice * (decimal)0.9)
                {
                    operations.operations.Add(sell(hold));
                }
            }
            foreach (var stockName in history.stocks.Keys)
            {
                List <DayResult> days       = new List <DayResult>();
                DayResult        currentDay = history.getDay(stockName, date.AddDays(0));
                if (currentDay == null || currentDay.volume == 0)
                {
                    continue;
                }
                for (int i = 1; i < 50; i++)
                {
                    DayResult day = history.getDay(stockName, date.AddDays(-i));
                    if (day != null && day.volume != 0)
                    {
                        days.Add(day);
                    }
                }
                if (days.Count < 20)
                {
                    continue;
                }
                bool isNotMatch = false;
                foreach (DayResult day in days)
                {
                    if (day.volume > currentDay.volume / 3)
                    {
                        isNotMatch = true;
                    }
                    if (day.adjClose > currentDay.adjClose)
                    {
                        isNotMatch = true;
                    }
                    if (day.adjClose < currentDay.adjClose * (decimal)0.7)
                    {
                        isNotMatch = true;
                    }
                }
                if (currentDay.adjClose * currentDay.volume < 10000000)
                {
                    isNotMatch = true;
                }
                if (isNotMatch)
                {
                    continue;
                }
                operations.operations.Add(buy(stockName, currentDay.adjClose));
            }
            return(operations);
        }