Exemplo n.º 1
0
        private async Task _runTest(CancellationToken ct)
        {
            IsBusy = true;

            TickProcessor tickPro = new TickProcessor(Leverage, StartBalance);

            if (_summaryWin == null)
            {
                _summaryWin = new SummaryWin();
            }
            else
            {
                _summaryWin.Reset();
            }

            _summaryWin.Show();

            try {
                _setProgress();
                using (AlgoService algo = new AlgoService(_onMessage, TickFilePath))
                {
                    switch (AlgoType)
                    {
                    case 0:
                        await algo.InitHybrid(CompleteHour, ExitLev, ObserWin, ExitLev2, Threshold1, Threshold2);

                        break;

                    case 1:
                        await algo.InitDayRange(CompleteHour, ExitLev);

                        break;

                    case 2:
                        await algo.InitBollinger(ObserWin, ExitLev2, Threshold1, Threshold2);

                        break;
                    }

                    _setProgress();
                    List <Tick> ticks = await Util.ReadTickCsv(TickFilePath, StartDate, EndDate, ct);
                    await _runTicks(ticks, algo, tickPro, ct);
                }
            }
            catch (OperationCanceledException)
            {
                //
            }
            catch (Exception e) {
                throw;
            }
            finally{
                IsBusy = false;
            }
        }
Exemplo n.º 2
0
        private async Task _runTicks(List <Tick> ticks, AlgoService algo, TickProcessor tickPro,
                                     CancellationToken ct)
        {
            await Task.Factory.StartNew(() =>
            {
                var lastOptimizeDate = StartDate;

                for (int i = 0; i < ticks.Count; i++)
                {
                    if (ct.IsCancellationRequested == true)
                    {
                        ct.ThrowIfCancellationRequested();
                    }

                    Tick tick = ticks[i];

                    //if (RunTestWithOptimizer &&
                    //    tick.Time.Date.AddDays(0 - OptimizeInterval) > lastOptimizeDate &&
                    //    tick.Time.Date.AddDays(0 - OptimizeLookback) > StartDate)
                    //{
                    //  //TODO new algo instance need to be created here
                    //  //algo.Optimize(tick.Time.Date, AlgoType,
                    //  //  CompleteHour, EntryLev, ExitLev,
                    //  //  CompleteHour2, EntryLev2, ExitLev2, OptimizeLookback).Wait(ct);

                    //  algo.ResetAlgoParams();
                    //  lastOptimizeDate = tick.Time.Date;
                    //}

                    bool isClosePos = false;
                    double riskLev  = -1;
                    var signal      = algo.OnTick(tick, out isClosePos, out riskLev, SL);
                    tickPro.OnTick(tick, signal, isClosePos, riskLev);

                    if (i % 100 == 0)
                    {
                        _setProgress(i * 100 / ticks.Count);
                    }
                }

                _setProgress(100);
            }, ct);
        }
    private async Task _runTicks(List<Tick> ticks, AlgoService algo, TickProcessor tickPro, 
      CancellationToken ct)
    {
      await Task.Factory.StartNew(() =>
                                  {
                                    var lastOptimizeDate = StartDate;

                                    for (int i = 0; i < ticks.Count; i++)
                                    {
                                      if (ct.IsCancellationRequested == true)
                                      {
                                        ct.ThrowIfCancellationRequested();
                                      }

                                      Tick tick = ticks[i];

                                      //if (RunTestWithOptimizer &&
                                      //    tick.Time.Date.AddDays(0 - OptimizeInterval) > lastOptimizeDate &&
                                      //    tick.Time.Date.AddDays(0 - OptimizeLookback) > StartDate)
                                      //{
                                      //  //TODO new algo instance need to be created here
                                      //  //algo.Optimize(tick.Time.Date, AlgoType,
                                      //  //  CompleteHour, EntryLev, ExitLev,
                                      //  //  CompleteHour2, EntryLev2, ExitLev2, OptimizeLookback).Wait(ct);

                                      //  algo.ResetAlgoParams();
                                      //  lastOptimizeDate = tick.Time.Date;
                                      //}

                                      bool isClosePos = false;
                                      double riskLev = -1;
                                      var signal = algo.OnTick(tick, out isClosePos, out riskLev, SL);
                                      tickPro.OnTick(tick, signal, isClosePos, riskLev);

                                      if(i % 100 == 0)
                                        _setProgress(i*100/ticks.Count);
                                    }

                                    _setProgress(100);
                                  }, ct);
    }
    private async Task _runTest(CancellationToken ct) {

      IsBusy = true;

      TickProcessor tickPro = new TickProcessor(Leverage, StartBalance);

      if (_summaryWin == null)
      {
        _summaryWin = new SummaryWin();
      }
      else
      {
        _summaryWin.Reset();
      }

      _summaryWin.Show();
      
      try {

        _setProgress();
        using (AlgoService algo = new AlgoService(_onMessage, TickFilePath))
        {
          switch (AlgoType)
          {
            case 0:
              await algo.InitHybrid(CompleteHour, ExitLev, ObserWin, ExitLev2, Threshold1, Threshold2);
              break;
            case 1:
              await algo.InitDayRange(CompleteHour, ExitLev);
              break;
            case 2:
              await algo.InitBollinger(ObserWin, ExitLev2, Threshold1, Threshold2);
              break;
          }

          _setProgress();
          List<Tick> ticks = await Util.ReadTickCsv(TickFilePath, StartDate, EndDate, ct);
          await _runTicks(ticks, algo, tickPro, ct);
        }
      }
      catch (OperationCanceledException)
      {
        //
      }
      catch(Exception e) {

        throw;
      }
      finally{
      
        IsBusy = false;
      }
    }