예제 #1
0
 public void notifyStatus(String msg, String url, double perc)
 {
     if (TradeSystemActionsTextbox.InvokeRequired)
     {
         try
         {
             DelegateNotifyStatus method = notifyStatus;
             this.Invoke(method, new object[] { msg, url, perc });
         }
         catch (ObjectDisposedException) { }
     }
     else
     {
         if (msg.Equals("TradeSystemAction"))
         {
             TradeSystemActionsTextbox.AppendText(url + "\n");
         }
         else if (msg.Equals("TradeSystemDBPurge"))
         {
             HeartBeat();
         }
     }
 }
예제 #2
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();
            }
        }
예제 #3
0
        private void ManageResults()
        {
            double[] ops_good      = new double[MaxLambda];
            double[] ops_good_gain = new double[MaxLambda];

            double[] ops_bad      = new double[MaxLambda];
            double[] ops_bad_gain = new double[MaxLambda];

            double[] ops_very_good = new double[MaxLambda];
            double[] ops_very_bad  = new double[MaxLambda];

            double[] ops_tot          = new double[MaxLambda];
            double[] delta_t          = new double[MaxLambda];
            double[] total_gain       = new double[MaxLambda];
            double[] total_investment = new double[MaxLambda];

            double[] title_good_tot = new double[MaxLambda];
            double[] title_good_bad = new double[MaxLambda];

            double[] time_day_good_tot   = new double[MaxLambda];
            double[] time_day_good_bad   = new double[MaxLambda];
            double[] time_week_good_tot  = new double[MaxLambda];
            double[] time_week_good_bad  = new double[MaxLambda];
            double[] time_month_good_tot = new double[MaxLambda];
            double[] time_month_good_bad = new double[MaxLambda];

            double[] INDEX = new double[MaxLambda];

            for (int i = 0; i < MaxLambda; i++)
            {
                ops_good[i]      = 0;
                ops_good_gain[i] = 0;

                ops_bad[i]      = 0;
                ops_bad_gain[i] = 0;

                ops_very_good[i] = 0;
                ops_very_bad[i]  = 0;

                ops_tot[i]          = 0;
                delta_t[i]          = 0;
                total_gain[i]       = 0;
                total_investment[i] = 0;

                title_good_tot[i] = 0;
                title_good_bad[i] = 0;

                time_day_good_tot[i]   = 0;
                time_day_good_bad[i]   = 0;
                time_week_good_tot[i]  = 0;
                time_week_good_bad[i]  = 0;
                time_month_good_tot[i] = 0;
                time_month_good_bad[i] = 0;

                INDEX[i] = 0;
            }

            for (int i = 0; i < TotSim; i++)
            {
                int index = sim_results[i].lambda;

                ops_good[index]      += sim_results[i].ops_good;
                ops_good_gain[index] += sim_results[i].ops_good_gain;

                ops_bad[index]      += sim_results[i].ops_bad;
                ops_bad_gain[index] += sim_results[i].ops_bad_gain;

                ops_very_good[index] += sim_results[i].ops_very_good;
                ops_very_bad[index]  += sim_results[i].ops_very_bad;

                ops_tot[index]          += sim_results[i].ops_tot;
                delta_t[index]          += sim_results[i].delta_t;
                total_gain[index]       += sim_results[i].total_gain;
                total_investment[index] += sim_results[i].total_investment;

                title_good_tot[index] += sim_results[i].title_good_tot;
                title_good_bad[index] += sim_results[i].title_good_bad;

                time_day_good_tot[index]   += sim_results[i].time_day_good_tot;
                time_day_good_bad[index]   += sim_results[i].time_day_good_bad;
                time_week_good_tot[index]  += sim_results[i].time_week_good_tot;
                time_week_good_bad[index]  += sim_results[i].time_week_good_bad;
                time_month_good_tot[index] += sim_results[i].time_month_good_tot;
                time_month_good_bad[index] += sim_results[i].time_month_good_bad;

                INDEX[index] += sim_results[i].INDEX;
            }

            for (int i = InitLambda; i < MaxLambda; i++)
            {
                ops_good[i]      /= RunN;
                ops_good_gain[i] /= RunN;

                ops_bad[i]      /= RunN;
                ops_bad_gain[i] /= RunN;

                ops_very_good[i] /= RunN;
                ops_very_bad[i]  /= RunN;

                ops_tot[i]          /= RunN;
                delta_t[i]          /= RunN;
                total_gain[i]       /= RunN;
                total_investment[i] /= RunN;

                title_good_tot[i] /= RunN;
                title_good_bad[i] /= RunN;

                time_day_good_tot[i]   /= RunN;
                time_day_good_bad[i]   /= RunN;
                time_week_good_tot[i]  /= RunN;
                time_week_good_bad[i]  /= RunN;
                time_month_good_tot[i] /= RunN;
                time_month_good_bad[i] /= RunN;

                INDEX[i] /= RunN;
            }

            StreamWriter SW = null;

            try { SW = new StreamWriter(simulationfilenameTextbox.Text); }
            catch (Exception) { SW = null; }


            for (int i = InitLambda; i < MaxLambda; i++)
            {
                TradeSystemActionsTextbox.AppendText("[" + i + "] PROFIT: " + ((int)(total_gain[i])) + "\n");

                SW.Write(i + " ");                                                     // 1
                SW.Write(total_gain[i] + " " + total_investment[i] + " ");             // 2 3
                SW.Write(ops_good[i] + " " + ops_bad[i] + " " + ops_tot[i] + " ");     // 4 5 6
                SW.Write(ops_good_gain[i] + " " + ops_bad_gain[i] + " ");              // 7 8
                SW.Write(ops_very_good[i] + " " + ops_very_bad[i] + " ");              // 9 10
                SW.Write(title_good_tot[i] + " " + time_day_good_bad[i] + " ");        // 11 12
                SW.Write(time_day_good_tot[i] + " " + time_day_good_bad[i] + " ");     // 13 14
                SW.Write(time_week_good_tot[i] + " " + time_week_good_bad[i] + " ");   // 15 16
                SW.Write(time_month_good_tot[i] + " " + time_month_good_bad[i] + " "); // 17 18
                SW.Write(delta_t[i] + " ");                                            // 19
                SW.Write(INDEX[i] + " ");                                              // 20
                SW.WriteLine();
            }

            SW.Close();
        }
예제 #4
0
        public void notifySimulationStatus(String msg, TradeSystem t)
        {
            if (TradeSystemActionsTextbox.InvokeRequired)
            {
                try
                {
                    DelegateSimulationStatus method = notifySimulationStatus;
                    this.Invoke(method, new object[] { msg, t });
                }
                catch (ObjectDisposedException) { }
            }
            else
            {
                if (msg.Equals("DONE"))
                {
                    sim_results[sim_done++] = t.Results;

                    RunN   = Int32.Parse(textBox1.Text);
                    TotSim = (int)((MaxLambda - InitLambda) * RunN);

                    int val0 = (int)(100 * sim_done / TotSim);
                    int val  = val0 - progressBar1.Value;
                    progressBar1.Increment(val);

                    TradeSystemActionsTextbox.Clear();
                    double timeremaining = (TotSim - sim_done) * ((DateTime.Now - time_start).TotalSeconds) / (sim_done);
                    int    min           = (int)(timeremaining / 60);
                    int    sec           = (int)(timeremaining % 60);
                    if (min == 0)
                    {
                        TradeSystemActionsTextbox.AppendText("Time Remaining: " + sec + "''\n");
                    }
                    else
                    {
                        TradeSystemActionsTextbox.AppendText("Time Remaining: " + min + "' " + sec + "''\n");
                    }

                    if (sim_done == 1)
                    {
                        TradeSystemActionsTextbox.Clear();
                        TradeSystemActionsTextbox.AppendText("Time Remaining: -----\n");
                    }


                    if (sim_done == TotSim)
                    {
                        TradeSystemActionsTextbox.Clear();
                        sec = (int)((DateTime.Now - time_start).TotalSeconds);
                        min = (int)(sec / 60);
                        sec = (int)(sec % 60);
                        if (min == 0)
                        {
                            TradeSystemActionsTextbox.AppendText("Simulation Time: " + sec + "''\n");
                        }
                        else
                        {
                            TradeSystemActionsTextbox.AppendText("Simulation Time: " + min + "' " + sec + "''\n");
                        }


                        tradesystem_tasklist = null;

                        ManageResults();

                        FindSimulationFilename();
                        maxlambdaTextbox.ReadOnly  = false;
                        initlambdaTextbox.ReadOnly = false;
                        textBox1.ReadOnly          = false;
//						SomeStuff();
                    }
                    else
                    {
                        int index = sim_done + max_threads - 1;

                        if (index < tradesystem_tasklist.Count)
                        {
                            tradesystem_tasklist.ElementAt(index).run();
                        }
                    }
                }
            }
        }