public IEnumerable <Tick> GetData(Setup setup) { var ticks = new List <Tick>(); if (!DicTicks.TryGetValue(setup.SetupId, out ticks)) { var s = DicStrategies[setup.SetupId]; s.setup = setup; ticks = s.GetData(setup.OfflineStartTime).ToList(); if (ticks.Count > 0) { DicTicks.TryAdd(setup.SetupId, ticks); } } return(ticks); }
public double Fitness(double[] genes) { try { var id = OptimizationSetup.SetupId; var strategy = DicStrategies[id]; var ticks = new List <Tick>(); DicTicks.TryGetValue(id, out ticks); var monthly = ticks.GroupBy(t => t.Time.ToString("mm-yy")).ToList().Select(t => { var trade = new Trade(1, t.First(), new Setup(id, "B&H")); return(trade); }); strategy.type = 0; strategy.trades = new List <Trade>(); strategy.setup = strategy.Gene2Setup(OptimizationSetup, genes); strategy.StatusChanged += (status) => OnInfoChanged(status); strategy.WarmUp(ticks); foreach (var tick in ticks) { strategy.Run(tick); } var result = strategy.Statistics(false); ticks = null; strategy = null; if (result != null && result.TotalNetProfit > result.MaxDrawndown) { OnInfoChanged(result.ToShortString()); } return(result == null ? -1e10 : id == 1 || id == 14 ? (double)result.TotalNetProfit.Value : (double)result.SharpeRatio.Value); } catch (Exception e) { OnInfoChanged(e.Message + Environment.NewLine + e.StackTrace); return(double.MinValue); } }