/// <summary> /// returns true if sim event binding is needed /// </summary> /// <param name="sim"></param> /// <param name="ga"></param> bool prepsim_needsbind(ref HistSim sim, GauntArgs ga) { // see if filter or folder has changed string thistff = TickFileFilter.Serialize(ga.Filter) + ga.Folder; bool fullreset = lasttff != thistff; if ((sim == null) || fullreset) { if (_portfoliosim.Checked) { if (_siminmemory.Checked) { sim = new HistSimMemory(ga.Folder, ga.Filter); } else { debug("Using portfolio simulation. (realistic)"); sim = new MultiSimImpl(ga.Folder, ga.Filter); } } else { debug("Using sequential symbol simulation. (faster)"); sim = new SingleSimImpl(ga.Folder, ga.Filter); } lasttff = thistff; return(true); } else { sim.Reset(); } return(false); }
// runs after simulation is complete void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { debug(_sb.ToString()); _sb = new System.Text.StringBuilder(10000000); GauntArgs gargs = (GauntArgs)e.Result; if (!e.Cancelled) { List <Trade> list = SimBroker.GetTradeList(); tradeResults1.NewResultTrades(LogFile("Trades"), list); if (gargs.Trades) { debug("writing " + list.Count + " trades..."); Util.ClosedPLToText(list, ',', LogFile("Trades")); } if (gargs.Orders) { List <Order> olist = SimBroker.GetOrderList(); debug("writing " + olist.Count + " orders..."); StreamWriter sw = new StreamWriter(LogFile("Orders"), false); string[] cols = Enum.GetNames(typeof(OrderField)); sw.WriteLine(string.Join(",", cols)); for (int i = 0; i < olist.Count; i++) { sw.WriteLine(OrderImpl.Serialize(olist[i])); } sw.Close(); } string msg = "Done. Ticks: " + gargs.TicksProcessed + " Speed:" + gargs.TicksSecond.ToString("N0") + " t/s Fills: " + gargs.Executions.ToString(); debug(msg); status(msg); } else { debug("Canceled."); } // close indicators if (indf != null) { indf.Close(); indf = null; } // reset simulation h.Reset(); count = 0; lastp = 0; if (args.isUnattended) { Close(); return; } // enable new runs ProgressBar1.Enabled = false; ProgressBar1.Value = 0; queuebut.Enabled = true; Invalidate(true); }
// runs the simulation in background void bw_DoWork(object sender, DoWorkEventArgs e) { // get simulation arguments GauntArgs ga = (GauntArgs)e.Argument; // notify user debug("Run started: " + ga.Name); // prepare simulator h = new HistSim(ga.Folder, ga.Filter); h.GotDebug += new DebugDelegate(h_GotDebug); h.GotTick += new TickDelegate(h_GotTick); // start simulation h.PlayTo(ga.PlayTo); // end simulation ga.Stopped = DateTime.Now; ga.TicksProcessed = h.TicksProcessed; ga.Executions = h.FillCount; // save result e.Result = ga; }
// runs after simulation is complete void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { debug(_sb.ToString()); _sb = new System.Text.StringBuilder(10000000); GauntArgs gargs = (GauntArgs)e.Result; if (!e.Cancelled) { List <Trade> list = SimBroker.GetTradeList(); updatecompletedtrades(list, gargs.Trades, gargs.Orders); string msg = "Done. Ticks: " + gargs.TicksProcessed + " Speed:" + gargs.TicksSecond.ToString("N0") + " t/s Fills: " + gargs.Executions.ToString(); debug(msg); status(msg); } else { debug("Canceled."); } // close indicators if (indf != null) { indf.Close(); indf = null; } // reset simulation h.Reset(); count = 0; lastp = 0; if (args.isUnattended) { Close(); return; } // enable new runs ProgressBar1.Enabled = false; ProgressBar1.Value = 0; queuebut.Enabled = true; Invalidate(true); }
// runs the simulation in background void bw_DoWork(object sender, DoWorkEventArgs e) { FillCount = 0; // get simulation arguments GauntArgs ga = (GauntArgs)e.Argument; // notify user debug("Run started: " + ga.Name); status("Started: " + ga.ResponseName); // prepare simulator if (prepsim_needsbind(ref h, ga)) { bindsim(ref h); } // prep broker SimBroker = new Broker(); SimBroker.UseBidAskFills = _usebidask.Checked; SimBroker.UseHighLiquidityFillsEOD = _usehighliquidityEOD.Checked; SimBroker.GotFill += new FillDelegate(SimBroker_GotFill); SimBroker.GotOrder += new OrderDelegate(SimBroker_GotOrder); SimBroker.GotOrderCancel += new OrderCancelDelegate(SimBroker_GotOrderCancel); // start simulation try { h.PlayTo(ga.PlayTo); } catch (DirectoryNotFoundException ex) { debug("Error locating tick files, err: " + ex.Message + ex.StackTrace); debug("You may want to ensure your tick files are in the TradeLinkTicks folder."); } // end simulation ga.Stopped = DateTime.Now; ga.TicksProcessed = h.TicksProcessed; ga.Executions = FillCount; // save result e.Result = ga; }
// runs the simulation in background void bw_DoWork(object sender, DoWorkEventArgs e) { FillCount = 0; // get simulation arguments GauntArgs ga = (GauntArgs)e.Argument; // notify user debug("Run started: " + ga.Name); status("Started: " + ga.ResponseName); // prepare simulator bool portreal = _portfoliosim.Checked; if (_portfoliosim.Checked) { debug("Using portfolio simulation. (realistic)"); h = new MultiSimImpl(ga.Folder, ga.Filter); } else { debug("Using sequential symbol simulation. (faster)"); h = new SingleSimImpl(ga.Folder, ga.Filter); } h.GotDebug += new DebugDelegate(h_GotDebug); SimBroker.UseBidAskFills = _usebidask.Checked; h.GotTick += new TickDelegate(h_GotTick); SimBroker.GotFill += new FillDelegate(SimBroker_GotFill); SimBroker.GotOrder += new OrderDelegate(args.Response.GotOrder); SimBroker.GotOrderCancel += new OrderCancelDelegate(SimBroker_GotOrderCancel); // start simulation h.PlayTo(ga.PlayTo); // end simulation ga.Stopped = DateTime.Now; ga.TicksProcessed = h.TicksProcessed; ga.Executions = FillCount; // save result e.Result = ga; }
/// <summary> /// returns true if sim event binding is needed /// </summary> /// <param name="sim"></param> /// <param name="ga"></param> bool prepsim_needsbind(ref HistSim sim, GauntArgs ga) { // see if filter or folder has changed string thistff = TickFileFilter.Serialize(ga.Filter)+ga.Folder; bool fullreset = lasttff != thistff; if ((sim==null) || fullreset) { if (_portfoliosim.Checked) { if (_siminmemory.Checked) { sim = new HistSimMemory(ga.Folder, ga.Filter); } else { debug("Using portfolio simulation. (realistic)"); sim = new MultiSimImpl(ga.Folder, ga.Filter); } } else { debug("Using sequential symbol simulation. (faster)"); sim = new SingleSimImpl(ga.Folder, ga.Filter); } lasttff = thistff; return true; } else { sim.Reset(); } return false; }