public ActionResult MonteCarloSimulationModal(int id)
        {
            MonteCarloSimulationDto model = new MonteCarloSimulationDto();

            if (id == 0)
            {
                TradingAccountDto tradingAccount = this._tradingAccountAppService.GetActive();
                List <Market>     markets        = this._marketRepository.GetAll().Where(x => x.Active).ToList();

                model.TimeStamp                  = DateTime.Now;
                model.TradingAccountId           = tradingAccount.Id;
                model.NumberOfTradesInSample     = this._tradeRepository.GetAll().Count(x => x.TradingAccountId == model.TradingAccountId && x.ExitReason != TradeExitReasons.None);
                model.NumberOfTradesPerIteration = 30;
                model.NumberOfIterations         = 1000;
                model.CumulativeProfitK          = .95m;
                model.ConsecutiveLossesK         = 1m;
                model.MaxDrawdownK               = .99m;
                model.AccountSize                = tradingAccount.CurrentCapital;
                model.RuinPoint                  = markets.Average(x => x.InitialMargin) + 10m;
                model.MaxDrawdownMultiple        = 2m;
            }
            else
            {
                MonteCarloSimulation monteCarloSimulation = this._repository.Single(x => x.Id == id);
                monteCarloSimulation.MapTo(model);
            }

            return(PartialView("Modals/_MonteCarloSimulationModal", model));
        }
        public void RunSimulation(MonteCarloSimulationDto dto)
        {
            MonteCarloSimulation sim = _repository.Get(dto.Id);

            sim.MapTo(dto);
            List <Trade>  sample  = this._tradeRepository.GetAll().Where(x => x.TradingAccountId == dto.TradingAccountId && x.ExitReason != TradeExitReasons.None).ToList();
            List <Market> markets = this._marketRepository.GetAll().Where(x => x.Active).ToList();

            dto.Simulate(sample, markets, this._consoleHubProxy);
            dto.MapTo(sim);
        }