Esempio n. 1
0
        public List<InstanceModel> Start(int selectionId, DateTime dateFrom, DateTime dateTo)
        {
            SelectionModel selection = selectionService.GetById(selectionId, s=>s.StrategyInfo);

            List<InstanceModel> res = new List<InstanceModel>();

            //Выбрка начальной популяции !!! Мощность популяции в настройки
            List<InstanceModel> first = OptimizationHelper.CreateFirstGeneration(selection,1);

            //1. Определяем значение фитнес-функции
            Dictionary<InstanceModel, IStrategy> listResult = new Dictionary<InstanceModel, IStrategy>();
            foreach (InstanceModel instance in first)
            {
                //получаем стратегию 
                IStrategy strategy = StrategyHelper.CreateStrategy(instance);
                
                //устанавливаем остальные свойства
                Instrument instr = new Instrument(instance.Ticker, instance.TimeFrame);

                Portfolio portf = new Portfolio
                {
                    Balance = instance.Balance,
                    Rent = instance.Rent,
                    Slippage = instance.Slippage
                };

                IManager manager = new TesterManager(strategy, instr, portf);

                manager.DateFrom = dateFrom;
                manager.DateTo = dateTo;

                //Стартуем стратегию
                manager.StartStrategy();

                listResult[instance] = strategy;
                
            }

            //2. Отбираем лучшие

            //3. Кодируем парамеры

            //4. Кроссинговер

            //5. Мутация

            //6. Декодируем параметры

            //Снова 1

            return res;
        }
Esempio n. 2
0
        public ActionResult BeginTest(TesterModel model) //!!!В модели использовать Instance
        {
            if (ModelState.IsValid)
            {
                InstanceModel instance = instanceService.GetById(model.InstanceId, true);

                //получаем стратегию 
                IStrategy strategy = StrategyHelper.CreateStrategy(instance);

                //устанавливаем остальные свойства
                Instrument instr = new Instrument(instance.Ticker, instance.TimeFrame); 

                Portfolio portf = new Portfolio
                {
                    Balance = instance.Balance,
                    Rent = instance.Rent,
                    Slippage = instance.Slippage
                };

                IManager manager = new TesterManager(strategy, instr, portf);

                manager.DateFrom = model.DateFrom;
                manager.DateTo = model.DateTo;

                //Стартуем стратегию
                manager.StartStrategy();

                //***Положить в сессию
                AliveResult aliveResult = new AliveResult
                {
                    AliveId = strategyResultCollection.Count() + 1,
                    StartDate = DateTime.Now,
                    Instance = instance,
                    Strategy = strategy,
                    Manager = manager
                };

                //Извлечь индикаторы из  объекта стратегии
                aliveResult.IndicatorsDict = StrategyHelper.ExtractIndicatorsInStrategy(strategy);

                strategyResultCollection.Add(aliveResult);
                //**

                TempData["message"] = string.Format("Тест успешно запущен. Id={0}",aliveResult.AliveId);

                return RedirectToAction("Index");
            }

            ViewBag.InstanceList = ModelHelper.GetInstanceList(instanceService);

            return View(model);
        }