コード例 #1
0
        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));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 public void Save(MonteCarloSimulationDto dto)
 {
     if (dto.IsNew)
     {
         MonteCarloSimulation monteCarloSimulation = dto.MapTo <MonteCarloSimulation>();
         int id = this._repository.InsertAndGetId(monteCarloSimulation);
         this.RunSimulationEnqueue(new MonteCarloSimulationDto()
         {
             Id = id
         });
     }
     else
     {
         MonteCarloSimulation monteCarloSimulation = this._repository.Get(dto.Id);
         dto.MapTo(monteCarloSimulation);
     }
 }
コード例 #4
0
        public ActionResult MonteCarloSimulation_Destroy([DataSourceRequest] DataSourceRequest request, MonteCarloSimulationDto model)
        {
            if (model != null)
            {
                this._repository.Delete(model.Id);
            }

            return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
        }
コード例 #5
0
        public ActionResult MonteCarloSimulation_Update([DataSourceRequest] DataSourceRequest request, MonteCarloSimulationDto model)
        {
            if (model != null && ModelState.IsValid)
            {
                this._monteCarloSimulationAppService.Save(model);
            }

            return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
        }
コード例 #6
0
 public void RunSimulationEnqueue(MonteCarloSimulationDto dto)
 {
     _backgroundJobManager.Enqueue <RunMonteCarloSimulationBackgroundJob, MonteCarloSimulationDto>(dto);
 }