Esempio n. 1
0
 private void editToolStripMenuItem_Click(object sender, EventArgs e)
 {
     StockOrder stockOrder = GetSelectedStockOrder();
      if (stockOrder != null)
      {
     OrderEditionDlg orderEditionDlg = new OrderEditionDlg(stockOrder);
     orderEditionDlg.ShowDialog();
      }
      InitializeListView();
 }
        private void createOrdersBtn_Click(object sender, EventArgs e)
        {
            string text = this.ordersTextBox.Text.Replace(",", ".").Trim();
             text = text.Replace("\r\n    ", "\r\n");
             text = text.Replace(" étranger", "");
             text = text.Replace(" Achat  ", "|Buy|");
             text = text.Replace(" Vente  ", "|Sell|");
             text = text.Replace("    ", "|");
             text = text.Replace("||", "|");
             text = text.Replace(" Exécuté à ", "|");
             text = text.Replace(" €", "");
             text = text.Replace(" \r\n", "\r\n");
             text = text.Replace("...", "");

             this.ordersTextBox.Text = text;
             this.Refresh();

             StringReader sr = new StringReader(this.ordersTextBox.Text);
             string line = string.Empty;
             string errorMsg = string.Empty;
             while ((line = sr.ReadLine()) != null)
             {
            StockOrder stockOrder = StockOrder.CreateFromCAPCA(line, ref errorMsg);
            if (stockOrder != null)
            {
               OrderEditionDlg orderEditionDlg = new OrderEditionDlg(stockOrder.StockName, new string[] { this.stockPortofolio.Name }, null);
               orderEditionDlg.Order = stockOrder;
               orderEditionDlg.ShowDialog();
               if (orderEditionDlg.DialogResult == DialogResult.OK)
               {
                  this.stockPortofolio.OrderList.Add(stockOrder);
               }
            }
            else
            {
               System.Windows.Forms.MessageBox.Show(errorMsg, "Error creating the order");
               break;
            }
             }
        }
        private void GenerateSimulation()
        {
            // Manage selected Stock and portofolio
             // Get selected portofolio
             StockPortofolio portofolio = this.stockPortofolioList.Get(this.portofolioComboBox.SelectedItem.ToString());
             portofolio.OrderList.Clear();

             // Get selected Stock
             StockSerie stockSerie = this.stockDictionary[this.SelectedStockName];
             if (!stockSerie.Initialise()) { return; }

             if (this.SelectedStrategy == null)
             {
            this.simulationParameterControl_SelectedStrategyChanged(this.simulationParameterControl.SelectedStrategyName);
             }

             StockOrder lastOrder = stockSerie.GenerateSimulation(this.SelectedStrategy,
            simulationParameterControl.StartDate, simulationParameterControl.EndDate.AddHours(18),
            simulationParameterControl.amount, simulationParameterControl.reinvest,
            simulationParameterControl.amendOrders, simulationParameterControl.supportShortSelling,
            simulationParameterControl.takeProfit, simulationParameterControl.profitRate,
            simulationParameterControl.stopLoss, simulationParameterControl.stopLossRate,
            simulationParameterControl.fixedFee, 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;
               }
            }
             }

             if (this.simulationParameterControl.displayPendingOrders && lastOrder != null && lastOrder.State == StockOrder.OrderStatus.Pending)
             {
            OrderEditionDlg orderEditionDlg = new OrderEditionDlg(lastOrder);
            orderEditionDlg.StartPosition = FormStartPosition.Manual;
            orderEditionDlg.Location = new Point(0, 0);
            orderEditionDlg.ShowDialog();
             }
        }
        private void generateOrderBtn_Click(object sender, EventArgs e)
        {
            // Manage selected Stock and portofolio
             // Get selected Stock
             StockSerie stockSerie = this.stockDictionary[this.SelectedStockName];
             stockSerie.Initialise();

             // Create dedicated portofolio
             StockPortofolio portofolio = this.stockPortofolioList.Get(this.portofolioComboBox.SelectedItem.ToString());
             StockPortofolio tmpPortofolio = this.stockPortofolioList.Find(p => p.Name == stockSerie.StockName + "_P");
             if (tmpPortofolio == null)
             {
            tmpPortofolio = new StockPortofolio(stockSerie.StockName + "_P");
            this.portofolioComboBox.Items.Add(tmpPortofolio.Name);
            this.stockPortofolioList.Add(tmpPortofolio);
             }
             this.portofolioComboBox.SelectedIndex = this.portofolioComboBox.Items.IndexOf(tmpPortofolio.Name);
             tmpPortofolio.OrderList = portofolio.OrderList.GetSummaryOrderList(stockSerie.StockName, true);

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

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

             if (this.simulationParameterControl.displayPendingOrders && lastOrder != null && lastOrder.State == StockOrder.OrderStatus.Pending)
             {
            OrderEditionDlg orderEditionDlg = new OrderEditionDlg(lastOrder);
            orderEditionDlg.StartPosition = FormStartPosition.Manual;
            orderEditionDlg.Location = new Point(0, 0);
            orderEditionDlg.ShowDialog();
             }
             // Send event
             if (SimulationCompleted != null)
             {
            SimulationCompleted();
             }
        }
        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;
        }
Esempio n. 6
0
        public void newOrderMenuItem_Click(object sender, EventArgs e)
        {
            OrderEditionDlg orderCreationDlg = new OrderEditionDlg(this.stockNameComboBox.SelectedItem.ToString(),
               this.StockPortofolioList.GetPortofolioNames(), null);
            if (orderCreationDlg.ShowDialog() == DialogResult.OK)
            {
                StockPortofolio portofolio = this.StockPortofolioList.Get(orderCreationDlg.PortofolioName);
                // Retrieve new sotck order
                portofolio.OrderList.Add(orderCreationDlg.Order);
                portofolio.OrderList.SortByDate();

                // Regenerate the stock serie for the current portoflio
                StockDictionary.CreatePortofolioSerie(portofolio);

                // Save Portofolios
                SavePortofolios();

                // Refresh the screen
                OnNeedReinitialise(false);
            }
        }