Пример #1
0
        private void TradeSystemActionsRun_Click(object sender, EventArgs e)
        {
            TradeSystemActionsTextbox.Clear();
            sim_results = null;
            sim_done    = 0;


            if (!first_run)
            {
                first_run = false;
                db.Clear();
                db.ImportCSVDir(CSV_Dirname);
            }

            int RunN;

            try { RunN = Int32.Parse(textBox1.Text); }
            catch (Exception) { RunN = 1; }

            try { InitLambda = Int32.Parse(initlambdaTextbox.Text); }
            catch (Exception) { InitLambda = 1; }

            try { MaxLambda = Int32.Parse(maxlambdaTextbox.Text); }
            catch (Exception) { MaxLambda = InitLambda + 1; }

            if (MaxLambda <= InitLambda)
            {
                MaxLambda = InitLambda + 1;
            }

            sim_done                   = 0;
            textBox1.ReadOnly          = true;
            sim_results                = new RunResults[RunN * MaxLambda];
            maxlambdaTextbox.ReadOnly  = true;
            initlambdaTextbox.ReadOnly = true;


            if (tradesystem_tasklist != null)
            {
                MessageBox.Show("Treads still running");
                return;
            }
            tradesystem_tasklist = new LinkedList <TradeSystem>();

            for (int k = InitLambda; k < MaxLambda; k++)
            {
                for (int i = 0; i < RunN; i++)
                {
                    TradeSystem tss = null;
                    if (TradesystemTypeComboBox.SelectedItem.ToString().Equals("Random"))
                    {
                        if ((k == InitLambda) && (i == 0))
                        {
                            InitDB();
                        }
                        tss = new TradeSystemRandom(db, this);
                    }
                    else if (TradesystemTypeComboBox.SelectedItem.ToString().Equals("Analytic"))
                    {
                        if ((k == InitLambda) && (i == 0))
                        {
                            InitAnalytic();
                        }

                        tss = new TradeSystemAnalytic(db, this);
                    }
                    else if (TradesystemTypeComboBox.SelectedItem.ToString().Equals("Delu"))
                    {
                        if ((k == InitLambda) && (i == 0))
                        {
                            InitDelu();
                        }
                        tss = new TradeSystemDelu(db, this);
                        System.Threading.Thread.Sleep(1);
                    }
                    else if (TradesystemTypeComboBox.SelectedItem.ToString().Equals("Silly"))
                    {
                        if ((k == InitLambda) && (i == 0))
                        {
                            InitDB();
                        }
                        tss = new TradeSystemSilly(db, this);
                    }

                    else if (TradesystemTypeComboBox.SelectedItem.ToString().Equals("Neural"))
                    {
                        double[] prova = new double[100];
                        for (int zz = 0; zz < prova.Length; zz++)
                        {
                            prova[zz] = zz;
                        }

                        double[] prova1  = TI.calculate_mm(prova, 30);
                        double[] prova11 = TI.calculate_mm_base(prova, 30, 1);
                        double[] prova2  = TI.calculate_mm_base_new(prova, 30, 1);
                        double[] prova3  = TI.calculate_emm(prova, 30, 0.5);
                        double[] prova33 = TI.calculate_mm_base(prova, 30, 2);
                        double[] prova4  = TI.calculate_mm_base_new(prova, 30, 2);

                        System.Console.WriteLine(prova1[99] + " " + prova11[99] + " " + prova2[99]);
                        System.Console.WriteLine(prova3[99] + " " + prova33[99] + " " + prova4[99]);

                        /*
                         * StreamWriter SW = null;
                         * try { SW = new StreamWriter("test"); }
                         * catch (Exception) { SW = null; }
                         *
                         *
                         * for(int z=0;z<vals.Length;z++)
                         *      SW.WriteLine(vals[z] + " " + oldmean[z] + " " + newmean[z]);
                         */
                        if ((k == InitLambda) && (i == 0))
                        {
                            InitDB();
                        }
                        tss = new TradeSystemRandom(db, this);
                    }

                    else
                    {
                        continue;
                    }

//	                try { tss.InitialCapital = Double.Parse(textBoxInitialCapital.Text); }
//	                catch (Exception) { tss.InitialCapital = 0; }

                    try { tss.MaxInvestment = Double.Parse(textBox2.Text); }
                    catch (Exception) { tss.MaxInvestment = 0; }

                    tss.AdvancedStatistics = checkBox2.Checked;
                    tss.ScatterPlot        = checkBox1.Checked;
                    tss.BeginLambda        = InitLambda;
                    tss.Lambda             = k;

                    tradesystem_tasklist.AddLast(tss);
                }
            }

            time_start = DateTime.Now;
            int thread_num = Math.Min(max_threads, tradesystem_tasklist.Count);

            for (int i = 0; i < thread_num; i++)
            {
                tradesystem_tasklist.ElementAt(i).run();
            }
        }