public GauntletEngine(TradeLink.API.Response r, TickFileFilter tff) { _r = r; _r.SendOrder += new OrderDelegate(_r_SendOrder); _r.SendCancel += new UIntDelegate(_r_SendCancel); _tff = tff; _h = new HistSim(_tff); _h.GotTick += new TickDelegate(_h_GotTick); _h.SimBroker.GotOrderCancel += new OrderCancelDelegate(SimBroker_GotOrderCancel); _h.SimBroker.GotOrder += new OrderDelegate(_r.GotOrder); _h.SimBroker.GotFill += new FillDelegate(_r.GotFill); }
public GauntletEngine(TradeLink.API.Response r, HistSim h) { responseengine = r; bindresponse(ref responseengine); myhistsim = h; bindsim(ref myhistsim); SimBroker = new Broker(); SimBroker.GotOrderCancel += new OrderCancelDelegate(SimBroker_GotOrderCancel); SimBroker.GotOrder += new OrderDelegate(responseengine.GotOrder); SimBroker.GotFill += new FillDelegate(responseengine.GotFill); }
public GauntletEngine(TradeLink.API.Response r, TickFileFilter inittff) { responseengine = r; responseengine.SendOrderEvent += new OrderSourceDelegate(_r_SendOrder); responseengine.SendCancelEvent += new LongSourceDelegate(_r_SendCancel); responseengine.SendDebugEvent += new DebugDelegate(_r_SendDebugEvent); tff = inittff; myhistsim = new MultiSimImpl(tff); myhistsim.GotTick += new TickDelegate(_h_GotTick); SimBroker.GotOrderCancel += new OrderCancelDelegate(SimBroker_GotOrderCancel); SimBroker.GotOrder += new OrderDelegate(responseengine.GotOrder); SimBroker.GotFill += new FillDelegate(responseengine.GotFill); }
public void RawPerformance() { HistSim h = new HistSim(Environment.CurrentDirectory+"\\"); h.Initialize(); h.GotTick += new TradeLink.API.TickDelegate(raw_GotTick); tickcount = 0; syms.Clear(); lasttime = 0; Assert.AreEqual(0, tickcount); Assert.AreEqual(0, syms.Count); Assert.AreEqual(0, lasttime); Assert.Greater(h.TicksPresent, 0); if (Environment.ProcessorCount == 1) EXPECTRAW *= 2.5; DateTime start = DateTime.Now; h.PlayTo(HistSim.ENDSIM); double time = DateTime.Now.Subtract(start).TotalSeconds; // make sure ticks arrived in order Assert.IsTrue(GOODTIME,"Tick arrived out-of-order."); // check running time Assert.LessOrEqual(time, EXPECTRAW,"may fail on slow machines"); Assert.AreEqual(3,syms.Count); // tick count is = 42610 (FTI) + 5001 (SPX) + 8041 (ABN) Assert.AreEqual(42610 + 4991 + 8041, tickcount); // variance from approximate count should be less than 1% Assert.Less((tickcount - h.TicksPresent) / h.TicksPresent, .01); // actual count should equal simulation count Assert.AreEqual(h.TicksProcessed, tickcount); // last time is 1649 on SPX Assert.AreEqual(20080318155843, lasttime); // printout simulation runtime Console.WriteLine("Raw runtime: " + time.ToString("N2") + "sec, versus: " + EXPECTRAW + "sec expected."); Console.WriteLine("Raw speed: " + ((double)tickcount / time).ToString("N0") + " ticks/sec"); }
private bool loadfile(string path) { string f = path; if (isResponse(f)) { responsedll = f; reslist.DropDownItems.Clear(); List<string> l = Util.GetResponseList(responsedll); if (System.IO.File.Exists(f)) if (!isRecent(f)) recent.DropDownItems.Add(f); for (int i = 0; i < l.Count; i++) reslist.DropDownItems.Add(l[i]); status("Found " + l.Count + " responses. Please select one from Responses drop-down."); return true; } else if (isEPF(f)) { if (System.IO.File.Exists(f)) if (!isRecent(f) && Util.SecurityFromFileName(f).isValid) recent.DropDownItems.Add(f); epffiles.Add(f); h = new HistSim(epffiles.ToArray()); h.SimBroker.GotOrder += new OrderDelegate(broker_GotOrder); h.SimBroker.GotFill += new FillDelegate(broker_GotFill); h.GotTick += new TickDelegate(h_GotTick); h.SimBroker.GotOrderCancel += new OrderCancelDelegate(broker_GotOrderCancel); updatetitle(); status("Loaded tickdata: "+PrettyEPF()); return true; } return false; }
public bool Start() { //ensure everything is ready to start the optimization if (!isValid) { debug("Invalid optimization, Must configure this optimization completely before re-starting."); status("Optimization not configured."); return false; } SIM = myhistsim; DLL = Dll; RNAME = ResponseName; debug("Starting optimization, Queueing up all "+this.OptimizeCount+" combinations..."); //queue up all the possibilities /* List<List<string[]>> paramListList = new List<List<string[]>>(); foreach (OptimizationParam op in varListControl.Items) { List<string[]> paramList = new List<string[]>(); string testClass = (String)reslist.SelectedItem; string testName = op.name.ToString(); decimal val = decimal.MinValue; decimal max = decimal.MaxValue; while (val < max) { if (val == decimal.MinValue) { val = op.low; max = op.high; } else val += op.step; paramList.Add(new string[] { testClass, testName, val.ToString() }); } paramListList.Add(paramList); } //now we have all the possibilities in a list //we need to combine them into all possible combos //keep all possible combinations in a list //each string[] is a parameter value //each List<string[]> is a parameter set List<List<string[]>> comboList = new List<List<string[]>>(); foreach (List<string[]> paramList in paramListList) { comboList = appendList(comboList, paramList); }*/ debug("All combinations queued, Starting Gauntlet Threads"); var rh = RunHelper.run(runopt, null, debug, "runopt: " + this.ToString()); status("Optimizaton started with " + OptimizeCount + " combinations."); return rh.isStarted; }
public void BarPerformance() { HistSim h = new HistSim(Environment.CurrentDirectory + "\\"); h.GotTick += new TradeLink.API.TickDelegate(h_GotTick); h.Initialize(); tickcount = 0; lasttime = 0; Assert.AreEqual(0, lasttime); Assert.Greater(h.TicksPresent, 0); if (Environment.ProcessorCount == 1) EXPECTBARS *= 2.5; DateTime start = DateTime.Now; h.PlayTo(HistSim.ENDSIM); double time = DateTime.Now.Subtract(start).TotalSeconds; Assert.GreaterOrEqual(tickcount, 50000); Assert.AreEqual(3, bt.SymbolCount); Assert.LessOrEqual(time, EXPECTBARS); Console.WriteLine("BarList runtime: " + time.ToString("N2") + "sec, versus: " + EXPECTBARS + "sec expected."); Console.WriteLine("BarList " + ((double)tickcount / time).ToString("N0") + " ticks/sec"); }
public Optimize(string dll, string response, HistSim sim) : base(ResponseLoader.FromDLL(response,dll), sim) { Dll = dll; ResponseName = response; }
public gauntletArgs(string _dll, string _response, HistSim h) { dll = _dll; response = _response; hsim = h; }
void unbindsim(ref HistSim h) { if (h != null) { h.GotDebug -= new DebugDelegate(h_GotDebug); h.GotTick -= new TickDelegate(h_GotTick); } }
bool loadsim() { h = new MultiSimImpl(epffiles.ToArray()); SimBroker = new Broker(); SimBroker.GotOrder += new OrderDelegate(broker_GotOrder); SimBroker.GotFill += new FillDelegate(broker_GotFill); h.GotTick += new TickDelegate(h_GotTick); SimBroker.UseBidAskFills = Properties.Settings.Default.UseBidAskFills; SimBroker.GotOrderCancel += new OrderCancelDelegate(broker_GotOrderCancel); try { updatetitle(); status("Loaded tickdata: " + PrettyEPF()); return true; } catch (IOException ex) { if (ex.Message.Contains("used by another process")) { status("Simulation file still in use."); debug("Try again, one of following in use: " + string.Join(",",epffiles.ToArray())); } return false; } }
void unbindsim(ref HistSim h) { h.GotTick -= new TickDelegate(_h_GotTick); }
void bindsim(ref HistSim h) { h.GotDebug += new DebugDelegate(h_GotDebug); h.GotTick += new TickDelegate(h_GotTick); }
private void playbut_Click(object sender, EventArgs e) { status("preparing simulation"); if (_playback.IsBusy) { status("simulation already in progress"); return; } // setup simulation (portfolio realistic) h = new MultiSimImpl(tickfolder,FileFilter); // bind events h.GotTick += new TickDelegate(h_GotTick); h.GotDebug += new DebugDelegate(_dw.GotDebug); // setup playback _playback = new Playback(h); _playback.RunWorkerCompleted += new RunWorkerCompletedEventHandler(_playback_RunWorkerCompleted); _playback.ProgressChanged += new ProgressChangedEventHandler(_playback_ProgressChanged); // clear highs and lows highs = new Dictionary<string, decimal>(); lows = new Dictionary<string, decimal>(); // start playback var delayscale = (int)((double)trackBar1.Value / 5); _playback.RunWorkerAsync(new PlayBackArgs(delayscale)); // notify user status("Playback started..."); // update user interface options playbut.Enabled = false; stopbut.Enabled = true; trackBar1.Enabled = false; }
// 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; }
public Playback(HistSim simulator) { h = simulator; WorkerSupportsCancellation = true; WorkerReportsProgress = 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 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; }