private void gaIsland2() { TickData.readTickData(0); using (StreamWriter sw = new StreamWriter("./multi ga.csv", false, Encoding.Default)) { int opt_period = 420000; int sim_period = 180000; int slide = 100000; sw.WriteLine("pl per min,num trade,vola,fired[0],fired[1],fired[2],pl per min,num trade,vola,fired[0],fired[1],fired[2]"); for (int i = 0; i < 30; i++) { var gim = new GAIslandMaster2(); int from = TickData.price.Count - 6000000 + i * slide; int to = from + opt_period; var chro = gim.startGA(from, to, 3, 15, 15, 3, 0.05, 10, 30, 10, 10, false); var s = new SIM2(); var ac = s.startContrarianTrendFollowSashine(from, to, chro, false, false); Form1.Form1Instance.addListBox2(i.ToString() + " - " + "GA period - pl per min=" + Math.Round(ac.pl_per_min, 2) + ",num trade=" + Math.Round(ac.num_trade_per_hour, 2) + ", vola=" + Math.Round(ac.total_pl_vola, 2) + ", fired box num=" + ac.fired_box_ind_num[0] + " : " + ac.fired_box_ind_num[1] + " : " + ac.fired_box_ind_num[2]); s = new SIM2(); var ac2 = s.startContrarianTrendFollowSashine(to, to + sim_period, chro, true, false); //var ac2 = s.startContrarianTrendFollowSashine(from, to, chro, true, false); Form1.Form1Instance.addListBox2("SIM period - pl per min=" + Math.Round(ac2.pl_per_min, 2) + ",num trade=" + Math.Round(ac2.num_trade_per_hour, 2) + ", vola=" + Math.Round(ac2.total_pl_vola, 2) + ", fired box num=" + ac2.fired_box_ind_num[0] + " : " + ac2.fired_box_ind_num[1] + " : " + ac2.fired_box_ind_num[2]); sw.WriteLine(Math.Round(ac.pl_per_min, 2) + "," + Math.Round(ac.num_trade_per_hour, 6) + "," + Math.Round(ac.total_pl_vola) + "," + ac.fired_box_ind_num[0] + "," + ac.fired_box_ind_num[1] + "," + ac.fired_box_ind_num[2] + "," + Math.Round(ac2.pl_per_min, 2) + "," + Math.Round(ac2.num_trade_per_hour, 6) + "," + Math.Round(ac2.total_pl_vola) + "," + ac2.fired_box_ind_num[0] + "," + ac2.fired_box_ind_num[1] + "," + ac2.fired_box_ind_num[2]); } } }
public Account2 startContrarianSashine(int from, int to, int num_chrom, int num_generation, int num_islands, int elite_crossover_start, double immigration_rate, int num_box, int search_period, bool write_result) { var ac = new Account2(new Chrome2(from, to, num_box)); int last_str_changed_ind = from; int last_str_num_trade = 0; var chro = new Chrome2(from - search_period, from - 1, num_box); chro = getOptStrategy(from - search_period, from - 1, num_chrom, num_generation, num_box, num_islands, immigration_rate, elite_crossover_start, 30, 10, 10); var sim = new SIM2(); Account2 ac_best = sim.startContrarianTrendFollowSashine(from - search_period, from - 1, chro, false, false); int num_recalc = 0; var pre_dd = new DecisionData2(); for (int i = from; i < to; i++) { var tdd = Strategy2.contrarianSashine(ac, i, chro, pre_dd, true); if (tdd.fired_box_ind >= 0) { chro.box_fired_num[tdd.fired_box_ind]++; } pre_dd = tdd; 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, 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, num_box, num_islands, immigration_rate, elite_crossover_start, 30, 10, 10); sim = new SIM2(); Form1.Form1Instance.addListBox2("recalc=" + num_recalc); ac_best = sim.startContrarianTrendFollowSashine(i - search_period, i, chro, false, 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, tdd.fired_box_ind); 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, chro, pre_dd.fired_box_ind, write_result); return(ac); }