示例#1
0
 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);
 }
示例#2
0
        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);
        }
示例#3
0
        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);

        }
示例#4
0
 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);
 }
示例#5
0
        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);
        }
示例#6
0
        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");
        }
示例#7
0
         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;

        }
示例#8
0
        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;
        }
示例#9
0
        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");
        }
示例#10
0
 public Optimize(string dll, string response, HistSim sim) : base(ResponseLoader.FromDLL(response,dll), sim) 
 {
     Dll = dll;
     ResponseName = response;
 }
示例#11
0
 public gauntletArgs(string _dll, string _response, HistSim h)
 {
     dll = _dll;
     response = _response;
     hsim = h;
 }
示例#12
0
 void unbindsim(ref HistSim h)
 {
     if (h != null)
     {
         h.GotDebug -= new DebugDelegate(h_GotDebug);
         h.GotTick -= new TickDelegate(h_GotTick);
     }
 }
示例#13
0
         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;
             }

         }
示例#14
0
 void unbindsim(ref HistSim h)
 {
     h.GotTick -= new TickDelegate(_h_GotTick);
 }
示例#15
0
 void bindsim(ref HistSim h)
 {
     h.GotDebug += new DebugDelegate(h_GotDebug);
     h.GotTick += new TickDelegate(h_GotTick);
 }
示例#16
0
        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;
        }
示例#17
0
        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);

        }
示例#18
0
 void unbindsim(ref HistSim h)
 {
     h.GotTick -= new TickDelegate(_h_GotTick);
 }
示例#19
0
 // 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;
 }
示例#20
0
 public Playback(HistSim simulator) 
 { 
     h = simulator;
     WorkerSupportsCancellation = true;
     WorkerReportsProgress = true;
 }
示例#21
0
 // 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;
 }
示例#22
0
        /// <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;
        }