private void RunTest(TradeParams tradeParams, Configurator configurator, TradesPrinter printer) { tradeParams.Validate(); var advisor = new TradeAdvisor(configurator.Repository.Days.First().FiveMins); var robot = new RobotContext(tradeParams, configurator.Factory, advisor); var results = configurator.GetTradeResults(); //foreach (var day in repository.Days) foreach (var day in configurator.Repository.Days.Skip(1)) //TODO перебирать параметры по абсолютному значению, а затем искать регрессию одних на другие { foreach (var candle in day.FiveMins) { var dealEvent = robot.Process(candle) as DealEvent; if (dealEvent != null) { results.AddDeal(dealEvent.Deal); } } var ev = robot.StopTrading() as DealEvent; if (ev != null) { results.AddDeal(ev.Deal); } //printer.PrintDepoWithParamsName(tradeParams, results); Assert.That(results.DealsAreClosed); robot.Reset(); } //File.WriteAllLines("out.txt", results.GetDepositSizes().Select(s => (s - 30000).ToString())); printer.AddRow(tradeParams, results); }
public RobotContext(TradeParams tradeParams, StatesFactory factory, TradeAdvisor advisor, List<Candle> history = null) { Logger.Debug("I'm started"); candles = history ?? new List<Candle>(); //IMPROVE историю хранить не нужно (отправлять за историей к Advisor) Advisor = advisor; Factory = factory; StopLossSize = tradeParams.StopLoss; TrailingStopLoss = (int) (StopLossSize * tradeParams.TrailingStopPercent); BreakevenSize = (int) (StopLossSize * tradeParams.BreakevenPercent); PegtopSize = tradeParams.PegtopSize; EndTime = tradeParams.EndTime; CurrentState = DefaultState; ExtremumsRepository = ((SearchState) CurrentState).ExtremumsRepo; }
public Configurator(string configsName, MainWindow window) { var document = XDocument.Load(configsName); var eventBus = new EventBus(); InitLogs(window); InitConnector(document.Descendants("Connection").Single()); var factory = GetFactory(document.Descendants("Types").Single()); var tradeParams = GetParams(document.Descendants("TradeParams").Single()); var currentDayCandles = Connector.GetCurrentDayCandles(); var advisor = new TradeAdvisor(currentDayCandles); //TODO больше истории RobotContext = new RobotContext(tradeParams, factory, advisor, currentDayCandles); InitTradeController(document.Descendants("TradeController").Single(), eventBus, LogManager.Configuration.Variables["WorkingDirectory"]); }