private StockPortofolio GenerateTradingSimulation(StockSerie stockSerie, System.DateTime startDate, System.DateTime endDate, float amount, bool reinvest, bool amendOrders, bool supportShortSelling, float fixedFee, float taxRate)
        {
            // Manage selected Stock and portofolio
            stockPortofolioList.RemoveAll(p => p.Name == (stockSerie.StockName + "_P"));

            StockPortofolio portofolio = new StockPortofolio(stockSerie.StockName + "_P");
            portofolio.TotalDeposit = amount;
            stockPortofolioList.Add(portofolio);

            stockSerie.GenerateSimulation(SelectedStrategy, startDate, endDate, amount, reinvest,
                                    amendOrders, supportShortSelling, fixedFee, taxRate, portofolio);

            // Create Portofoglio serie
            portofolio.Initialize(stockDictionary);

            return portofolio;
        }
        private StockPortofolio GenerateSimulation(StockSerie stockSerie)
        {
            stockSerie.Initialise();

             // Manage selected Stock and portofolio
             StockPortofolio portofolio = new StockPortofolio(stockSerie.StockName + "_P");
             portofolio.TotalDeposit = this.simulationParameterControl.amount;
             stockPortofolioList.Add(portofolio);

             this.SelectedStrategy = StrategyManager.CreateStrategy(this.simulationParameterControl.SelectedStrategyName, stockSerie, null, simulationParameterControl.supportShortSelling);

             // intialise the serie
             stockSerie.Initialise();

             StockOrder lastOrder = stockSerie.GenerateSimulation(SelectedStrategy, this.simulationParameterControl.StartDate, this.simulationParameterControl.EndDate.AddHours(18), this.simulationParameterControl.amount, this.simulationParameterControl.reinvest,
             this.simulationParameterControl.amendOrders, this.simulationParameterControl.supportShortSelling,
             this.simulationParameterControl.takeProfit, this.simulationParameterControl.profitRate,
             this.simulationParameterControl.stopLoss, this.simulationParameterControl.stopLossRate,
             this.simulationParameterControl.fixedFee, this.simulationParameterControl.taxRate, portofolio);

             // Do a bit of cleanup
             if (lastOrder != null && this.simulationParameterControl.removePendingOrders)
             {
            if (lastOrder.IsBuyOrder())
            {
               lastOrder = null;
            }
            else
            {
               if (lastOrder.State != StockOrder.OrderStatus.Executed)
               {
                  portofolio.OrderList.Remove(portofolio.OrderList.Last());
                  lastOrder = null;
               }
            }
             }

             // Display pending order
             if (this.simulationParameterControl.displayPendingOrders && lastOrder != null && lastOrder.State == StockOrder.OrderStatus.Pending)
             {
            if (SelectedStockChanged != null)
            {
               SelectedStockChanged(lastOrder.StockName, true);
            }
            OrderEditionDlg orderEditionDlg = new OrderEditionDlg(lastOrder);
            orderEditionDlg.StartPosition = FormStartPosition.Manual;
            orderEditionDlg.Location = new Point(0, 0);
            orderEditionDlg.ShowDialog();
             }

             // Create Portofoglio serie
             portofolio.Initialize(stockDictionary);
             if (stockDictionary.Keys.Contains(portofolio.Name))
             {
            stockDictionary.Remove(portofolio.Name);
             }
             stockDictionary.Add(portofolio.Name, portofolio.GeneratePortfolioStockSerie(portofolio.Name, stockSerie, stockSerie.StockGroup));

             // Generate report
             if (this.generateReportCheckBox.Checked)
             {
            this.simulationParameterControl.GenerateReportLine("BatchReport_" + SelectedStrategy + ".csv", stockSerie, portofolio);
             }

             return portofolio;
        }