Пример #1
0
        private bool randomInitial(int inventoryNumber, int leastExchange, int totalPersonNumber, int inititalPrice, Oper[] oper_list)
        {
            int sum    = 0;
            int divide = 0;

            divide = int.Parse((inventoryNumber / totalPersonNumber).ToString());
            divide = inventoryNumber / totalPersonNumber;
            Random ran = new Random();

            for (int i = 0; i < totalPersonNumber; i = i + 2)
            {
                int value = 0;
                int next  = 0;

                try
                {
                    value = ran.Next(leastExchange, divide);
                }
                catch
                {
                }

                next             = divide * 2 - value;
                oper_list[i]     = new Oper();
                oper_list[i + 1] = new Oper();
                oper_list[i].set_Inventory_Number(value);
                oper_list[i].set_Least_Price(inititalPrice);
                oper_list[i + 1].set_Inventory_Number(next);
                oper_list[i + 1].set_Least_Price(inititalPrice);
                sum = value + next;
            }

            if (sum == inventoryNumber)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            initPrice            = int.Parse(this.tBox_initialPrice.Text);
            leastPriceRate       = double.Parse(this.tBox_leastPriceRate.Text) / 100;
            totalPersonNumber    = int.Parse(this.tbox_totalPersonNumber.Text);
            totalExchangeNumber  = int.Parse(this.tbox_totalExchangeNumber.Text);
            exchangeCyc          = int.Parse(this.tBox_exchangeCyc.Text);
            inventoryNumber      = int.Parse(this.tBox_inventoryNumber.Text);
            leastExchange        = int.Parse(this.tBox_leastExchange.Text);
            exchangeRate         = double.Parse(this.tBox_exchangeRate.Text) / 100;
            exchangeFreqByMinite = int.Parse(this.tBox_ExchangeFreq.Text);

            for (int i = 0; i < exchangeCyc; i++)
            {
                cBox_Cyc.Items.Add(i + 1);
            }

            double[] exchangeEndPrice_list   = new double[exchangeCyc]; // 头日收盘价格数组
            double[] exchangeStartPrice_lsit = new double[exchangeCyc]; // 次日开盘价格

            Oper[] oper_list = new Oper[totalPersonNumber];
            exchangeNumber = 0;
            exchangeIncome = 0;

            exchangeHistroy.Clear();
            // Initial Oper list
            randomInitial(inventoryNumber, leastExchange, totalPersonNumber, initPrice, oper_list);

            int cyc = exchangeCyc;

            while (cyc > 0 && exchangeNumber <= totalExchangeNumber)
            {
                if (cyc == exchangeCyc)
                {
                    exchangeStartPrice_lsit[exchangeCyc - cyc] = initPrice;
                }
                else
                {
                    exchangeStartPrice_lsit[exchangeCyc - cyc] = exchangeEndPrice_list[exchangeCyc - 1 - cyc];
                }
                exchangeEndPrice_list[exchangeCyc - cyc] = exchangeByday(leastExchange, leastPriceRate, totalPersonNumber, exchangeFreqByMinite, exchangeStartPrice_lsit[exchangeCyc - cyc], cyc, oper_list);
                cyc--;
            }

            this.lbl_price.Text  = exchangeEndPrice_list[exchangeCyc - 1].ToString();
            this.lbl_income.Text = exchangeIncome.ToString();

            // 画图操作 开盘价格与收盘价格
            chart1.Series.Clear();  // 清除默认的series
            Series exchangeStartPrice = new Series("开盘价格");
            Series exchangeEndPrice   = new Series("收盘价格");

            exchangeStartPrice.ChartType           = SeriesChartType.Spline;
            exchangeStartPrice.IsValueShownAsLabel = true;
            exchangeEndPrice.ChartType             = SeriesChartType.Spline;
            exchangeEndPrice.IsValueShownAsLabel   = true;

            for (int day = 0; day < exchangeCyc; day++)
            {
                exchangeEndPrice.Points.AddXY(day, exchangeEndPrice_list[day]);
                exchangeStartPrice.Points.AddXY(day, exchangeStartPrice_lsit[day]);
            }

            chart1.Series.Add(exchangeStartPrice);
            chart1.Series.Add(exchangeEndPrice);

            // 日交易变化情况
            chart2.Series.Clear();
            Series ex = new Series("交易价格");

            ex.ChartType = SeriesChartType.Spline;
            //ex.IsValueShownAsLabel = true;

            for (int time = 0; time < exchangeHistroy[1].Count; time++)
            {
                ex.Points.AddXY(time, exchangeHistroy[1][time]);
            }
            chart2.Series.Add(ex);
        }