예제 #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;
            }
        }
예제 #2
0
        private async Task _runOptimize(CancellationToken ct)
        {
            IsBusy = true;

            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;
                    }

                    int backNoDays = Convert.ToInt32((EndDate.Date - StartDate.Date).TotalDays);
                    await algo.Optimize(EndDate, backNoDays, 128, 512);
                }
            }
            catch (OperationCanceledException)
            {
                //
            }
            catch (Exception e)
            {
                throw;
            }
            finally
            {
                IsBusy = false;
            }
        }
예제 #3
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);
        }
예제 #4
0
        public RootViewModel(
            AlgoService algoService,
            Func <EditorTabViewModel> editorTabFactory,
            IEventAggregator eventAggregator,
            IIOService ioService,
            ILogger <RootViewModel> logger,
            IMapFactory mapFactory,
            Func <NewFileDialogViewModel> newFileDialogFactory,
            IWindowManager windowManager)
        {
            _editorTabFactory     = editorTabFactory;
            _eventAggregator      = eventAggregator;
            _ioService            = ioService;
            _logger               = logger;
            _mapFactory           = mapFactory;
            _newFileDialogFactory = newFileDialogFactory;
            _windowManager        = windowManager;
            _algoService          = algoService;

            Algos        = _algoService.DisplayNames;
            SelectedAlgo = Algos.Keys.FirstOrDefault();
            _eventAggregator.Subscribe(this);
        }
    private async Task _runOptimize(CancellationToken ct)
    {
      IsBusy = true;

      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;
          }

          int backNoDays = Convert.ToInt32((EndDate.Date - StartDate.Date).TotalDays);
          await algo.Optimize(EndDate, backNoDays, 128, 512);
        }
      }
      catch (OperationCanceledException)
      {
        //
      }
      catch (Exception e)
      {

        throw;
      }
      finally
      {

        IsBusy = false;
      }
    }
    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;
      }
    }