public static void UpdateHp(string symbol, char dealType, int tp, int sl, string where, System.Data.DataTable dt = null, bool deleteFirst = false) { if (dt == null) { dt = GetUpdateHpMainTable(symbol, where); } System.Console.WriteLine(string.Format("UpdateHp of {0}_{1}_{2}_{3}", symbol, dealType, tp, sl)); if (deleteFirst) { string sql = string.Format("DELETE FROM {0}_HP WHERE DealType = '{1}' AND Tp = {2} AND Sl = {3} AND {4}", symbol, dealType, tp, sl, string.IsNullOrEmpty(where) ? "1=1" : where); DbHelper.Instance.ExecuteNonQuery(sql); } ISimulateStrategy strategy;// = new TpSlSimulateStrategy(0.0070, 0.0035); var simulationData = SimulationData.Instance.Init(symbol); strategy = new TpSlM1SimulateStrategy(symbol, tp * 0.0001, sl * 0.0001, simulationData); //strategy = new BreakEvenM1SimulateStrategy(0.0080, 0.0030, 0.0030); //strategy = new PriceProbSimulationStrategy(60, 0.0600); System.Data.DataTable dt2 = new System.Data.DataTable(); dt2.Columns.Add(new System.Data.DataColumn("Time", typeof(long))); dt2.Columns.Add(new System.Data.DataColumn("DealType", typeof(string))); dt2.Columns.Add(new System.Data.DataColumn("Tp", typeof(int))); dt2.Columns.Add(new System.Data.DataColumn("Sl", typeof(int))); dt2.Columns.Add(new System.Data.DataColumn("hp", typeof(int))); dt2.Columns.Add(new System.Data.DataColumn("hp_date", typeof(DateTime))); foreach (System.Data.DataRow row in dt.Rows) { DateTime date = (DateTime)row["Date"]; DateTime? closeDate; bool? hp; if (dealType == 'B') hp = strategy.DoBuy(date, (double)row["Close"], out closeDate); else if (dealType == 'S') hp = strategy.DoSell(date, (double)row["Close"], out closeDate); else throw new ArgumentException("Invalid dealtype of " + dealType); System.Data.DataRow row2 = dt2.NewRow(); row2["Time"] = row["Time"]; row2["DealType"] = dealType; row2["Tp"] = tp; row2["Sl"] = sl; row2["hp"] = hp == null ? (object)System.DBNull.Value : hp; row2["hp_date"] = closeDate == null ? (object)System.DBNull.Value : closeDate; dt2.Rows.Add(row2); } DbHelper.Instance.BulkCopy(dt2, string.Format("{0}_HP", symbol)); //System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback((o) => // { // System.Console.WriteLine(string.Format("UpdateWriteHp Start of {0}_{1}_{2}_{3}", symbol, dealType, tp, sl)); // DbHelper.Instance.BulkCopy(dt2, string.Format("{0}_HP", symbol)); // System.Console.WriteLine(string.Format("UpdateWriteHp End of {0}_{1}_{2}_{3}", symbol, dealType, tp, sl)); // })); }
public static void CheckHpData2() { string symbol = "EURUSD"; var simulationData = SimulationData.Instance.Init(symbol); int tp = 20; int sl = 20; var x = new TpSlM1SimulateStrategy(symbol, tp * 10, sl * 10, simulationData); var y = new DbSimulationStrategy(symbol, tp * 10, sl * 10); DateTime openDate = WekaUtils.GetDateFromTime(946859400); int ntp = 0, nfp = 0; for (int i = 0; i < 48; ++i) { var d = openDate.AddMinutes(30 * i); DateTime? closeDate; var hp = x.DoBuy(d, -1, out closeDate); if (hp.Value) ntp++; else nfp++; DateTime? closeDate2; var hp2 = y.DoBuy(d, -1, out closeDate2); WekaUtils.DebugAssert(hp == hp2, "hp == hp2"); WekaUtils.DebugAssert(closeDate == closeDate2, "closeDate == closeDate2"); } ntp = 0; nfp = 0; for (int i = 0; i < 48; ++i) { var d = new DateTime(2006, 6, 19).AddMinutes(30 * i); DateTime? closeDate; var hp = x.DoSell(d, -1, out closeDate); if (hp.Value) ntp++; else nfp++; DateTime? closeDate2; var hp2 = y.DoSell(d, -1, out closeDate2); WekaUtils.DebugAssert(hp == hp2, "hp == hp2"); WekaUtils.DebugAssert(closeDate == closeDate2, "closeDate == closeDate2"); } }