コード例 #1
0
        public void DoEffectiveLine()
        {
            try
            {
                results = new List <Portfolio>(); //new List<double[]>();


                if (start == 0)
                {
                    start = step;
                }
                if (start > finish)
                {
                    finish = 1;
                }

                results = ClassAssistant.DoListPortfolio(finalArray, selectedAssets, start, finish, step, constraints);

                GraphPane gp = zGC.GraphPane;
                gp.CurveList.Clear();

                zGC.AxisChange();
                zGC.Invalidate();

                if (results.Count == 0)
                {
                    MessageBox.Show("Решения для данных параметров не найдены", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    zGC.IsShowPointValues = true;

                    double[] x = new double[results.Count];
                    double[] y = new double[results.Count];
                    int      i = 0;
                    foreach (var a in results)
                    {
                        x[i] = a.Risk;
                        y[i] = a.Profit;
                        i++;
                    }
                    LineItem line = gp.AddCurve("Эффективная граница", x, y, Color.Red);
                    line.Symbol.Fill.Type = FillType.Solid;

                    CurveList cl = gp.CurveList;
                    zGC.AxisChange();
                    zGC.Invalidate();

                    double[] xSP = new double[1];
                    double[] ySP = new double[1];
                    xSP[0] = sp.Risk;
                    ySP[0] = sp.Profit;
                    LineItem lineSP = gp.AddCurve("ЕП", xSP, ySP, Color.Blue);
                    lineSP.Symbol.Fill.Type = FillType.Solid;

                    cl = gp.CurveList;
                    zGC.AxisChange();
                    zGC.Invalidate();
                    label_.Text = "Портфели: " + Convert.ToString(results.Count);
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("Неверный формат числа!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
        public async void DoList()
        {
            this.Cursor = Cursors.WaitCursor;
            try
            {
                int j = 0;
                comboBox_test.Items.Clear();

                //ClassAssistant.DownloadAllAssets(selectedAssets, path, year, false);

                await DownloadTask(selectedAssets, path, year);

                finalArray = ClassAssistant.ReadData(selectedAssets, path);

                double start = -0.02, finish = 1, step = 0.001;
                results = ClassAssistant.DoListPortfolio(finalArray, selectedAssets, start, finish, step, constraints);

                if (results.Count == 0)
                {
                    MessageBox.Show("Решения не найдены", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                }
                else
                {
                    j = 1;
                    foreach (var t in results)
                    {
                        comboBox_test.Items.Add(j + ": " + t.Profit.ToString() + "; " + t.Risk.ToString());
                        j++;
                    }
                }
                dataGridView.Cursor = Cursors.Default;
                this.Cursor         = Cursors.Default;
            }
            catch (System.IO.IOException ex)
            {
                string[] exception = ex.Message.Split(' ');
                count++;
                if (count == 3)
                {
                    // DialogResult dr = MessageBox.Show("Нет данных для " + exception[exception.Length - 1] + ". Замените этот актив.", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    DialogResult dr = MessageBox.Show(ex.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    count = 0;
                    if (dr == System.Windows.Forms.DialogResult.OK)
                    {
                        this.Close();
                    }
                }
                else
                {
                    DoList();
                }
            }
            catch (Exception ex)
            {
                string[]     exception = ex.Message.Split(' ');
                DialogResult dr        = MessageBox.Show(ex.Message, "Ошибка!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                if (dr == System.Windows.Forms.DialogResult.Retry)
                {
                    DoList();                                               //Form4_test_Load(sender, e);
                }
                // else this.Close();
            }
        }