public bool Test() { InputData inData = new InputData(); inData.LoadFromDirectory(this.SourceDirectory, null); List <StratergyParameterRange> ranges = new BuyLimitAndWaitConfigReader().GetRanges(new List <string>()); BuyLimitAndWaitStrategy blwStrategy = new BuyLimitAndWaitStrategy(); StrategyParameter sParam = ranges[0].GetAllParameters()[0]; sParam["InitHistoryMinutes"] = 0; blwStrategy.TesterInit(sParam, null); FuturePredictor fPredictor = new FuturePredictor(inData.Data); EngineFast engineFast = new EngineFast(); engineFast.StartTest(inData, blwStrategy, fPredictor, true, 100); blwStrategy = new BuyLimitAndWaitStrategy(); sParam = ranges[0].GetAllParameters()[0]; sParam["InitHistoryMinutes"] = 0; blwStrategy.TesterInit(sParam, null); Engine engine = new Engine(null, null); engine.StartTest(inData, blwStrategy, new Account(10000000, 3)); return(engineFast.HistoryOpenBuyPoints.Count() + engineFast.HistoryOpenSellPoints.Count() == engine.ClosedOrders.Count()); }
public void AnalyseStrategy(DateTime?fromNullable, DateTime?toNullable) { Dictionary <int, ResetTimeAnalyzer> dictResp = new Dictionary <int, ResetTimeAnalyzer>(); double swap = 0; if (ResetTimeAnalysis.SideAnalyser.Buy == Side && SwapCollection != null) { swap = SwapCollection.GetBuySwap(SymbolName); } if (ResetTimeAnalysis.SideAnalyser.Sell == Side && SwapCollection != null) { swap = SwapCollection.GetSellSwap(SymbolName); } InputData inDataAll = new InputData(); inDataAll.LoadFromDirectory(this.SourceDirectory, null); DateTime from = fromNullable.HasValue ? fromNullable.Value : inDataAll.Data.First().DateTime; DateTime to = toNullable.HasValue ? toNullable.Value : inDataAll.Data.Last().DateTime; inDataAll = inDataAll.Select(from, to); while (from < to) { InputData inData = inDataAll.Select(from, to); if (inData.Data.Count == 0) { continue; } int countDiff = inDataAll.Data.Count - inData.Data.Count; FuturePredictor fPredictor = new FuturePredictor(inData.Data); List <StratergyParameterRange> ranges = new BuyLimitAndWaitConfigReader().GetRanges(new List <string>()); Dictionary <int, ResetTimeAnalyzer> dictRespTest = new Dictionary <int, ResetTimeAnalyzer>(); foreach (StrategyParameter currParam in ranges[0].GetAllParameters()) { if (!dictResp.ContainsKey(currParam["TP"])) { dictResp.Add(currParam["TP"], new ResetTimeAnalyzer(currParam["TP"], 1 / 60d, fPredictor.Bids, fPredictor.Asks, 1, swap)); } IEnumerable <int> buyArray, sellArray; ResetTimeAnalysis.CalculatePoints(currParam, inData, fPredictor, countDiff, out buyArray, out sellArray); dictResp[currParam["TP"]].Process(buyArray, sellArray); } from = from.AddDays(14); } ResetTimeScript rts = new ResetTimeScript(dictResp.Values.ToList(), "", GetScriptDirectory(this.SymbolName, "", fromNullable, toNullable));; rts.Save(); }
static public double CalculateTimeOfOnePips(string sourceDirectory, string symbolName, ResetTimeAnalysis.SideAnalyser side) { InputData inData = new InputData(); inData.LoadFromDirectory(sourceDirectory, null); double swap = 0; if (ResetTimeAnalysis.SideAnalyser.Buy == side) { swap = inData.SwapBuy; } if (ResetTimeAnalysis.SideAnalyser.Sell == side) { swap = inData.SwapSell; } FuturePredictor fPredictor = new FuturePredictor(inData.Data); List <StratergyParameterRange> ranges = new BuyLimitAndWaitConfigReader().GetRanges(new List <string>()); StrategyParameter currParam = ranges[0].GetAllParameters().Last(); IEnumerable <int> buyArray, sellArray; ResetTimeAnalysis.CalculatePoints(currParam, inData, out buyArray, out sellArray); string profitSymbol = ForexSuite.SymbolsManager.GetProfitSymbol(symbolName); double coefToUSD = ForexSuite.QuotesManager.ConvertCurrency(profitSymbol, "USD", DateTime.Now.AddMonths(-7), ForexSuite.SymbolsManager.ValueFromPips(profitSymbol, 1)); ResetTimeAnalyzer rta = new ResetTimeAnalyzer(currParam["TP"], 1 / 60d, fPredictor.Bids, fPredictor.Asks, coefToUSD, swap); if (side == SideAnalyser.Buy) { rta.Process(buyArray, null); } else { rta.Process(null, sellArray); } if (rta.RealProfit == 0) { throw new ApplicationException("RealProfit=0"); } return(rta.AverageTime / rta.RealProfit); }
public void AnalyseAllPoints(DateTime?fromNullable, DateTime?toNullable) { InputData inDataAll = new InputData(); inDataAll.LoadFromDirectory(this.SourceDirectory, null); DateTime from = fromNullable.HasValue ? fromNullable.Value : inDataAll.Data.First().DateTime; DateTime to = toNullable.HasValue ? toNullable.Value : inDataAll.Data.Last().DateTime; InputData inData = inDataAll.Select(from, to); FuturePredictor fPredictor = new FuturePredictor(inData.Data); List <StratergyParameterRange> ranges = new BuyLimitAndWaitConfigReader().GetRanges(new List <string>()); Dictionary <int, ResetTimeAnalyzer> dictResp = new Dictionary <int, ResetTimeAnalyzer>(); foreach (StrategyParameter currParam in ranges[0].GetAllParameters()) { if (!dictResp.ContainsKey(currParam["TP"]) /*&& i++ < inData.Data.Count / 2*/) { string profitSymbol = ForexSuite.SymbolsManager.GetProfitSymbol(this.SymbolName); double coefToUSD = ForexSuite.QuotesManager.ConvertCurrency(profitSymbol, "USD", inData.Data.Last().DateTime, ForexSuite.SymbolsManager.ValueFromPips(profitSymbol, 1)); dictResp.Add(currParam["TP"], new ResetTimeAnalyzer(currParam["TP"], 1 / 60d, fPredictor.Bids, fPredictor.Asks, coefToUSD)); IEnumerable <int> buyArray = null, sellArray = null; switch (Side) { case ResetTimeAnalysis.SideAnalyser.Buy: buyArray = Enumerable.Range(0, (inData.Data.Count - 1)); break; default: sellArray = Enumerable.Range(0, (inData.Data.Count - 1)); break; } dictResp[currParam["TP"]].Process(buyArray, sellArray); } } ResetTimeScript rts = new ResetTimeScript(dictResp.Values.ToList(), "", GetScriptDirectory(this.SymbolName, "AllPoints", fromNullable, toNullable));; rts.Save(); }
private void Form1_Load(object sender, EventArgs e) { if (Settings1.Default.NumberLastMonthToAnalyze > 0) { Log4Smart.Logger.ClearAllResult(); } ButtonStart.Enabled = false; IEnumerable <string> allSymbols = from p in Settings1.Default.Symbols.Split(new char[] { ',' }) select p.Trim().ToLower(); string baseResultPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "result"); SwapCollection swapCollection = new SwapCollection(); swapCollection.LoadSwap(GetSwapFilePath()); foreach (string currPath in GetAllSymbolPath()) { if (!allSymbols.Contains(Path.GetFileName((currPath).ToLower()))) { continue; } try { TestManager tma = new TestManager(Settings1.Default.NumberThreads); InputData inData = new InputData(); inData.LoadFromDirectory(currPath, swapCollection); string baseSymbolResultPath = System.IO.Path.Combine(baseResultPath, inData.Symbol); List <string> extractedParameterNames = new List <string>(); List <StratergyParameterRange> ranges = //new MartinGaleConfigReader().GetRanges(extractedParameterNames); //new SuperAdaptConfigReader().GetRanges(extractedParameterNames); // new SuperStrategyConfigReader().GetRanges(extractedParameterNames); // new BuyAndWaitConfigReader().GetRanges(extractedParameterNames); new BuyLimitAndWaitConfigReader().GetRanges(extractedParameterNames); //new TheoristConfigReader().GetRanges(extractedParameterNames); foreach (StratergyParameterRange currStratergyParameterRange in ranges) { OptimizationFunctionIntNDFactory factory = //new TheoristFunctionFactory(currStratergyParameterRange); //new BuyAndWaitFunctionFactory(currStratergyParameterRange); new BuyLimitAndWaitFunctionFactory(currStratergyParameterRange); // new BuyLimitAndWaitFunctionFactory(currStratergyParameterRange); //new SuperAdaptFunctionFactory(currStratergyParameterRange); //OptimizationFunctionIntNDFactory factory = new MartinGaleFunctionFactory(currStratergyParameterRange); //OptimizationFunctionIntNDFactory factory = new SuperStrategyFunctionFactory(currStratergyParameterRange); //OptimizationFunctionIntNDFactory factory = new MartinGaleFunctionFactory(); //tma.EstimateAll(inData/*inData.Select(inData.Data.Last().DateTime.AddMonths(-1), inData.Data.Last().DateTime)*/, factory); for (int lp = Settings1.Default.LearningPeriodStartDay; lp <= Settings1.Default.LearningPeriodEndDay; lp += Settings1.Default.LearningPeriodStep) { for (int tp = Settings1.Default.TestPeriodStartDay; tp <= Settings1.Default.TestPeriodEndDay; tp += Settings1.Default.TestPeriodStepDay) { DateTime startAnalyzeDateTime = DateTime.Now.AddMonths(-Settings1.Default.NumberLastMonthToAnalyze); if (Settings1.Default.NumberLastMonthToAnalyze == 0) { startAnalyzeDateTime = startAnalyzeDateTime.AddWorkingDay(-tp * 2); } tma.RunGeneticTests(System.IO.Path.Combine(baseSymbolResultPath, currStratergyParameterRange.ToString(extractedParameterNames)), inData, startAnalyzeDateTime, lp, tp, factory); } } } tma.WaitJobFinished(); CalculateSum.Program.SumDirectory(baseSymbolResultPath); //SymbolResult.Load(baseSymbolResultPath).SaveStatistics(baseSymbolResultPath); //CalculateSum.Program.CalculatePortfolio(baseResultPath, 1500000, 0.9, 500000); } catch (Exception exc) { MessageBox.Show(exc.ToString()); } } this.Close(); }