Beispiel #1
0
        public DonchianChannel(Instrument instr, int period)
            : base(instr)
        {
            Results.Add("up", new IndicatorResult(period));
            Results.Add("down", new IndicatorResult(period));

            up = new List<decimal>(period);
            down = new List<decimal>(period);

        }
Beispiel #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);
        }
Beispiel #3
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;
        }
Beispiel #4
0
        public TesterManager(IStrategy strategy, Instrument instr, Portfolio portf)
        {
            this.Strategy = strategy;
            this.Instr = instr;
            this.Portf = portf;
            this.AliveType = AliveType.Test;
            this.OrderSender = new OrderSender(this);

            Strategy.Instr = Instr;
            Strategy.Manager = this;
            Strategy.Orders = new List<Order>();

            Strategy.Initialize();
            StrategyHelper.SubscriptionToEventAsync(Strategy); //Подписываем на событие формирования свечи асинхронно индикаторы, которые найдем в стратегии.

            cts = new CancellationTokenSource();
        }
Beispiel #5
0
        public EmulManager(IOrderRepository orderRepository,
            IStrategy strategy, Instrument instr, Portfolio portf, IDataProvider connector, AliveStrategy aliveStrategy)
        {
            this.orderRepository = orderRepository;

            this.Strategy = strategy;
            this.Instr = instr;
            this.Portf = portf;
            this.Connector = connector;
            this.AliveType = AliveType.Emul;
            this.OrderSender = new OrderSender(this);

            Strategy.Instr = Instr;
            Strategy.Manager = this;

            Strategy.Initialize();
            StrategyHelper.SubscriptionToEventAsync(Strategy); //Подписываем на событие формирования свечи асинхронно индикаторы, которые найдем в стратегии.

            this.aliveStrategy = aliveStrategy;

            //!!!проверить на наличие подписки
            Connector.TickPoked += Instr.OnTickPoked;
        }
Beispiel #6
0
 /// <summary>
 /// Вызывайте данный конструктор при инициализации собственного индикатора
 /// </summary>
 /// <param name="instr"></param>
 protected IndicatorBase(Instrument instr)
 {
     this.Results = new Dictionary<string, IndicatorResult>();
     this.Instr = instr;
     Instr.CreatedCandle += AddValue;
 }
Beispiel #7
0
        public ActionResult BeginTest(TesterModel model) //!!!В модели использовать Instance
        {
            if (ModelState.IsValid)
            {
                InstanceModel instance = instanceService.GetById(model.InstanceId, true);
                DataProviderModel setting = settingService.GetById(model.SettingId);

                //добавляем живую стратегию
                AliveStrategy aliveStrategy = new AliveStrategy
                {
                    GroupID = instance.GroupID,
                    IsActive = true
                };
                aliveStrategyRepository.Save(aliveStrategy);

                //получаем стратегию 
                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
                };

                IDataProvider connector = new SettingHelper().CreateDataProvider(setting);
                //IDataProvider connector = (IDataProvider)ReflectionHelper.CreateEntity(setting);

                IManager manager = new EmulManager(orderRepository, strategy, instr, portf, connector, aliveStrategy);

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

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

                //***Положить в сессию
                AliveResult aliveResult = new AliveResult
                {
                    AliveId = aliveStrategy.Id,
                    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);
        }
Beispiel #8
0
 public IndicatorMock(Instrument instr, int period)
     : base(instr)
 {
     Results.Add("value1", new IndicatorResult(period));
     Results.Add("value2", new IndicatorResult(period));
 }
        public NotificationHelper(Instrument instr)
        {
            this.instr = instr;

            instr.CreatedCandleReal += OnCreatedCandle;
        }