Exemplo n.º 1
0
        private void gaForMultiplePeriod()
        {
            TickData.readTickData(0);

            int start     = 5000000;
            int slide     = 100000;
            int opt_term  = 60000;
            int test_term = 12500;

            using (StreamWriter sw = new StreamWriter("./multi ga.csv", false, Encoding.Default))
            {
                sw.WriteLine("from,to,best pl per min,best total pl,best num trade per hour,best win rate,pl per min,total pl,win rate,total perfoamnce,pl_per_min_P,profit_factor_P,num_trade_per_hour_P");
                for (int i = 0; i < 10; i++)
                {
                    GA  ga   = new GA();
                    int from = TickData.time.Count - start + (i * slide);
                    int to   = TickData.time.Count - start + opt_term + (i * slide);
                    Form1.Form1Instance.setLabel3("#" + i.ToString() + ":doing for " + from.ToString() + " - " + to.ToString());
                    var chro = ga.startGA(20, 50, from, to, false);
                    SIM s    = new SIM();
                    var ac   = s.startContrarianSashine(from, to, chro.Gene_exit_time_sec, chro.Gene_kairi_term, chro.Gene_entry_kairi, chro.Gene_rikaku_percentage, false);
                    var ac2  = s.startContrarianSashine(to, to + test_term, chro.Gene_exit_time_sec, chro.Gene_kairi_term, chro.Gene_entry_kairi, chro.Gene_rikaku_percentage, false);

                    VerifyChrome vc  = new VerifyChrome();
                    var          res = vc.verifyBestChrome(chro, from, to);
                    sw.WriteLine(TickData.time[from].ToString() + "," + TickData.time[to].ToString() + "," + ac.pl_per_min.ToString() + "," + ac.total_pl_log.Values.ToList()[ac.total_pl_log.Values.ToList().Count - 1].ToString() + "," + ac.num_trade.ToString() + "," + ac.win_rate.ToString() +
                                 "," + ac2.pl_per_min.ToString() + "," + ac2.total_pl_log.Values.ToList()[ac2.total_pl_log.Values.ToList().Count - 1].ToString() + "," + ac2.win_rate.ToString()
                                 + "," + res["total performance"].ToString() + ", " + res["pl_per_min"].ToString() + "," + res["profit_factor"].ToString() + "," + res["num_trade_per_hour"]);

                    Form1.Form1Instance.addListBox2("#" + i.ToString() + ", total performance:" + res["total performance"].ToString() + ", pl_per_min_P:" + res["pl_per_min"].ToString() + ", profit_factor_P:" + res["profit_factor"].ToString()
                                                    + ", num_trade_per_hour_P:" + res["num_trade_per_hour"].ToString());
                }
            }
            Form1.Form1Instance.setLabel3("Completed all calc");
        }
Exemplo n.º 2
0
        private void doSIm()
        {
            TickData.readTickData(0);
            // s.startContrarianSashine(TickData.price.Count - 6000000, TickData.price.Count - 5000000, chro.Gene_exit_time_sec, chro.Gene_kairi_term, chro.Gene_entry_kairi, chro.Gene_rikaku_percentage, true);

            SIM    s    = new SIM();
            Chrome chro = new Chrome();

            chro.readBestChromFile();
            s.startContrarianSashine(TickData.price.Count - 4000000, TickData.price.Count - 3000000, chro.Gene_exit_time_sec, chro.Gene_kairi_term, chro.Gene_entry_kairi, chro.Gene_rikaku_percentage, true);
        }
Exemplo n.º 3
0
        public Dictionary <string, double> verifyBestChrome(Chrome chro, int ga_from, int ga_to)
        {
            Dictionary <string, double> res = new Dictionary <string, double>();

            SIM sim_ga = new SIM();
            var ac_ga  = sim_ga.startContrarianSashine(ga_from, ga_to, chro.Gene_exit_time_sec, chro.Gene_kairi_term, chro.Gene_entry_kairi, chro.Gene_rikaku_percentage, false);

            SIM sim = new SIM();
            var ac  = sim.startContrarianSashine(ga_to, ga_to + 180000, chro.Gene_exit_time_sec, chro.Gene_kairi_term, chro.Gene_entry_kairi, chro.Gene_rikaku_percentage, false);

            res.Add("pl_per_min", ac.pl_per_min / ac_ga.pl_per_min);
            res.Add("profit_factor", ac.profit_factor / ac_ga.profit_factor);
            res.Add("num_trade_per_hour", ac.num_trade_per_hour / ac_ga.num_trade_per_hour);
            res.Add("total performance", res.Values.ToList().Sum());

            return(res);
        }
Exemplo n.º 4
0
        public Account startContrarianSashine(int from, int to, int num_chrom, int num_generation, int search_period, int pl_check_period, bool write_result)
        {
            Account ac = new Account();
            int     last_str_changed_ind = from;
            int     last_str_num_trade   = 0;
            Chrome  chro = new Chrome();

            chro = getOptStrategy(from - search_period, from - 1, num_chrom, num_generation);
            SIM     sim        = new SIM();
            Account ac_best    = sim.startContrarianSashine(from - search_period, from - 1, chro.Gene_exit_time_sec, chro.Gene_kairi_term, chro.Gene_entry_kairi, chro.Gene_rikaku_percentage, false);
            int     num_recalc = 0;

            for (int i = from; i < to; i++)
            {
                var tdd = Strategy.contrarianSashine(ac, i, chro.Gene_exit_time_sec, chro.Gene_kairi_term, chro.Gene_entry_kairi, chro.Gene_rikaku_percentage);
                if (tdd.position == "Exit_All")
                {
                    ac.exitAllOrder(i);
                }
                else if (tdd.price_tracing_order)
                {
                    if (tdd.position == "Long" || tdd.position == "Short")
                    {
                        ac.entryPriceTracingOrder(i, tdd.position, tdd.lot);
                    }
                }
                else
                {
                    if (tdd.position == "Cancel" && tdd.cancel_index >= 0)
                    {
                        ac.cancelOrder(i, tdd.cancel_index);
                    }
                    else if (tdd.position == "Cancel_All")
                    {
                        ac.cancelAllOrders(i);
                    }
                    else if (tdd.position == "Cancel_PriceTracingOrder")
                    {
                        ac.cancelPriceTracingOrder(i);
                    }
                    else if (tdd.position == "Long" || tdd.position == "Short")
                    {
                        ac.entryOrder(i, tdd.position, tdd.price, tdd.lot);
                    }
                }
                if (checkUpdateStrategy(i, last_str_changed_ind, from, pl_check_period, last_str_num_trade, ac, ac_best))
                {
                    ac.cancelAllOrders(i);
                    num_recalc++;
                    last_str_changed_ind = i;
                    last_str_num_trade   = ac.num_trade;
                    chro = getOptStrategy(i - search_period, i, num_chrom, num_generation);
                    sim  = new SIM();
                    Form1.Form1Instance.addListBox2("recalc=" + num_recalc);
                    ac_best = sim.startContrarianSashine(i - search_period, i, chro.Gene_exit_time_sec, chro.Gene_kairi_term, chro.Gene_entry_kairi, chro.Gene_rikaku_percentage, false);
                    ac.takeActionLog(i, "applied new strategy:num trade=" + ac_best.num_trade.ToString() + " :pl per min=" + ac_best.pl_per_min.ToString() + " :win rate=" + ac_best.win_rate.ToString());
                }
                ac.moveToNext(i);
                Form1.Form1Instance.addListBox2(TickData.time[i] + ":total pl=" + Math.Round(ac.total_pl_log.Values.ToList()[ac.total_pl_log.Count - 1], 2) + " :num trade=" + ac.num_trade.ToString());
            }
            ac.lastDayOperation(to, write_result);
            return(ac);
        }