private void StartBackTesting(IStrategySetting set) { Max = set.EstimatedTime(); button.Text = string.Concat("Estimated Back Testing Time is ", pro.Rate(Max, count).ToString("N0"), " Minutes."); button.ForeColor = Color.Maroon; checkBox.ForeColor = Color.DarkRed; checkBox.Text = "BackTesting"; new Transmit(asset.Account, set.Capital); string path = string.Concat(Path.Combine(Application.StartupPath, @"..\"), @"\Log\", DateTime.Now.Hour > 23 || DateTime.Now.Hour < 9 ? DateTime.Now.AddDays(-1).ToString("yyMMdd") : DateTime.Now.ToString("yyMMdd"), @"\"); InterLink = false; List <Specify> list = new List <Specify>(131072); foreach (int hedge in set.Hedge) { foreach (int reaction in set.Reaction) { foreach (int sTick in set.ShortTick) { foreach (int sDay in set.ShortDay) { foreach (int lTick in set.LongTick) { foreach (int lDay in set.LongDay) { if (sTick < lTick && sDay < lDay) { list.Add(new Specify { Repository = options.Repository, ShortTickPeriod = sTick, ShortDayPeriod = sDay, LongTickPeriod = lTick, LongDayPeriod = lDay, Reaction = reaction, Hedge = hedge, BasicAssets = set.Capital, PathLog = path, Strategy = string.Concat(sDay.ToString("D2"), '^', sTick.ToString("D2"), '^', lDay.ToString("D2"), '^', lTick.ToString("D2"), '^', reaction.ToString("D2"), '^', hedge.ToString("D2")) }); } } } } } } } GC.Collect(); Count = Process.GetCurrentProcess().Threads.Count; new Task(() => { Parallel.ForEach(list, new ParallelOptions { MaxDegreeOfParallelism = (int)(Environment.ProcessorCount * 1.5) }, new Action <Specify>((analysis) => { new Analysize(analysis); pro.ProgressBarValue++; })); list.Clear(); button.ForeColor = Color.Ivory; SetMarketTick(GC.GetTotalMemory(true)); }).Start(); }
private void StartBackTesting(IStrategySetting set) { Max = set.EstimatedTime(); button.Text = string.Concat("Estimated Back Testing Time is ", pro.Rate(Max, count).ToString("N0"), " Minutes."); button.ForeColor = Color.Maroon; checkBox.ForeColor = Color.DarkRed; checkBox.Text = "BackTesting"; new Transmit(asset.Account, set.Capital); string path = string.Concat(Path.Combine(Application.StartupPath, @"..\"), @"\Log\", DateTime.Now.Hour > 23 || DateTime.Now.Hour < 9 ? DateTime.Now.AddDays(-1).ToString("yyMMdd") : DateTime.Now.ToString("yyMMdd"), @"\"); IOptions options = new Options(); GC.Collect(); Count = Process.GetCurrentProcess().Threads.Count; InterLink = false; foreach (int hedge in set.Hedge) { foreach (int reaction in set.Reaction) { foreach (int sTick in set.ShortTick) { foreach (int sDay in set.ShortDay) { foreach (int lTick in set.LongTick) { foreach (int lDay in set.LongDay) { if (sTick >= lTick || sDay >= lDay) { Application.DoEvents(); continue; } new Task(() => { new Analysize(new Specify { Repository = options.Repository, ShortTickPeriod = sTick, ShortDayPeriod = sDay, LongTickPeriod = lTick, LongDayPeriod = lDay, Reaction = reaction, Hedge = hedge, BasicAssets = set.Capital, PathLog = path, Strategy = string.Concat(sDay.ToString("D2"), '^', sTick.ToString("D2"), '^', lDay.ToString("D2"), '^', lTick.ToString("D2"), '^', reaction.ToString("D2"), '^', hedge.ToString("D2")) }); if (Max <= ++pro.ProgressBarValue && InterLink == false) { button.ForeColor = Color.Ivory; SetMarketTick(GC.GetTotalMemory(true)); } }).Start(); Application.DoEvents(); } } } } } } }