Esempio n. 1
0
 public void RawSingle()
 {
     SingleSimImpl h = new SingleSimImpl(new string[] { "FTI20070926.TIK" });
     rawbase("rawsingle",1,h);
     // tick count is = 42610 (FTI) + 5001 (SPX) + 8041 (ABN)
     Assert.Greater(tickcount, 40000);
 }
Esempio n. 2
0
        public void RawPerformance() 
        { 
            SingleSimImpl h = new SingleSimImpl(Environment.CurrentDirectory);
            rawbase("raw performance multi",3,h);
            // tick count is = 42610 (FTI) + 5001 (SPX) + 8041 (ABN)
            Assert.AreEqual(42610 + 4991 + 8041, tickcount);
            // check running time
            Assert.LessOrEqual(h.RunTimeSec, EXPECTRAW, "may fail on slow machines");

            // last time is 1649 on SPX
            Assert.AreEqual(20080318155843, lasttime);
        }
Esempio n. 3
0
        public void RawPerformance() 
        {
            SingleSimImpl h = new SingleSimImpl(new string[] { "FTI20070926.TIK", "ABN20080318.TIK", "SPX20070926.TIK" });
            rawbase("raw performance multi",3,h);
            // tick count is = 42610 (FTI) + 5001 (SPX) + 8041 (ABN)
            Assert.AreEqual(42610 + 4991 + 8041, tickcount);
            // check running time
            Assert.LessOrEqual(h.RunTimeSec, EXPECTRAW, "may fail on slow machines");

            // last time is 1649 on SPX
            Assert.AreEqual(20080318155843, lasttime);
        }
Esempio n. 4
0
        public void rawbase(string name,int symcount, SingleSimImpl sim)
        {
            rt.d(name.ToUpper());
            SingleSimImpl h = sim;
            h.GotTick += new TradeLink.API.TickDelegate(raw_GotTick);
            h.GotDebug += new DebugDelegate(h_GotDebug);
            tickcount = 0;
            syms.Clear();
            lasttime = 0;
                Assert.AreEqual(0, tickcount);
                Assert.AreEqual(0, syms.Count);
                Assert.AreEqual(0, lasttime);


            if (Environment.ProcessorCount == 1) EXPECTRAW *= 2.5;

            DateTime start = DateTime.Now;

            h.PlayTo(SingleSimImpl.ENDSIM);



            // printout simulation runtime
            
            rt.d("Ticks received: " + tickcount + " sent: " + h.TicksProcessed + " estimate: " + h.TicksPresent);
            rt.d("Raw runtime: " + h.RunTimeSec.ToString("N2") + "sec, versus: " + EXPECTRAW + "sec expected.");
            rt.d("Raw speed: " + h.RunTimeTicksPerSec.ToString("N0") + " ticks/sec");


            // make sure ticks arrived in order
            Assert.IsTrue(h.isTickPlaybackOrdered, "Tick arrived out-of-order.");
            // ensure got expected number of symbols
            Assert.AreEqual(symcount, syms.Count);
            // 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);

            h.Stop();
            rt.d(name.ToUpper());
        }
Esempio n. 5
0
        public static bool PlayHistoricalTicks(Response r, GenericTracker <string> symbols, DateTime start, DateTime endexclusive, int expecteddays, DebugDelegate deb)
        {
            bool skipexpected = expecteddays == 0;
            // prepare to track actual days for each symbol
            GenericTracker <int> actualdays = new GenericTracker <int>();

            foreach (string sym in symbols)
            {
                actualdays.addindex(sym, 0);
            }
            // prepare to track all tickfiles
            Dictionary <string, List <string> > files = new Dictionary <string, List <string> >();
            // get all required tickfiles for each symbol on each date
            DateTime now = new DateTime(start.Ticks);
            int      tfc = 0;

            while (now < endexclusive)
            {
                // get the tick files
                List <string> allfiles = TikUtil.GetFilesFromDate(Util.TLTickDir, Util.ToTLDate(now));
                // go through them all and see if we find expected number
                foreach (string fn in allfiles)
                {
                    // get security
                    SecurityImpl sec = SecurityImpl.FromTIK(fn);
                    // see if we want this symbol
                    int idx = symbols.getindex(sec.HistSource.RealSymbol);
                    if (idx < 0)
                    {
                        idx = symbols.getindex(sec.Symbol);
                    }
                    sec.HistSource.Close();
                    // skip if we don't
                    if (idx < 0)
                    {
                        continue;
                    }
                    string sym = symbols.getlabel(idx);
                    // if we have it, count actual day
                    actualdays[idx]++;
                    // save file and symbol
                    if (!files.ContainsKey(sym))
                    {
                        files.Add(sym, new List <string>());
                    }
                    files[sym].Add(fn);
                    // count files
                    tfc++;
                }
                // add one day
                now = now.AddDays(1);
            }
            // notify
            if (deb != null)
            {
                deb("found " + tfc + " tick files matching dates: " + Util.ToTLDate(start) + "->" + Util.ToTLDate(endexclusive) + " for: " + string.Join(",", symbols.ToArray()));
            }
            // playback when actual meets expected
            bool allok = true;

            foreach (string sym in symbols)
            {
                if (skipexpected || (actualdays[sym] >= expecteddays))
                {
                    // get tick files
                    string[] tf = files[sym].ToArray();
                    // notify
                    if (deb != null)
                    {
                        deb(sym + " playing back " + tf.Length + " tick files.");
                    }
                    // playback
                    HistSim h = new SingleSimImpl(tf);
                    h.GotTick += new TickDelegate(r.GotTick);
                    h.PlayTo(MultiSimImpl.ENDSIM);
                    h.Stop();
                    // notify
                    if (deb != null)
                    {
                        deb(sym + " completed playback. ");
                    }
                }
                else
                {
                    allok = false;
                }
            }


            return(allok);
        }
Esempio n. 6
0
        public static bool PlayHistoricalTicks(Response r, GenericTracker<string> symbols, DateTime start, DateTime endexclusive, int expecteddays, DebugDelegate deb)
        {
            bool skipexpected = expecteddays == 0;
            // prepare to track actual days for each symbol
            GenericTracker<int> actualdays = new GenericTracker<int>();
            foreach (string sym in symbols)
                actualdays.addindex(sym, 0);
            // prepare to track all tickfiles
            Dictionary<string, List<string>> files = new Dictionary<string, List<string>>();
            // get all required tickfiles for each symbol on each date
            DateTime now = new DateTime(start.Ticks);
            int tfc = 0;
            while (now < endexclusive)
            {
                // get the tick files
                List<string> allfiles = TikUtil.GetFilesFromDate(Util.TLTickDir, Util.ToTLDate(now));
                // go through them all and see if we find expected number
                foreach (string fn in allfiles)
                {
                    // get security
                    SecurityImpl sec = SecurityImpl.FromTIK(fn);
                    // see if we want this symbol
                    int idx = symbols.getindex(sec.HistSource.RealSymbol);
                    if (idx < 0)
                        idx = symbols.getindex(sec.Symbol);
                    sec.HistSource.Close();
                    // skip if we don't
                    if (idx < 0)
                        continue;
                    string sym = symbols.getlabel(idx);
                    // if we have it, count actual day
                    actualdays[idx]++;
                    // save file and symbol
                    if (!files.ContainsKey(sym))
                        files.Add(sym, new List<string>());
                    files[sym].Add(fn);
                    // count files
                    tfc++;
                }
                // add one day
                now = now.AddDays(1);
            }
            // notify
            if (deb != null)
            {
                deb("found " + tfc + " tick files matching dates: " + Util.ToTLDate(start) + "->" + Util.ToTLDate(endexclusive) + " for: " + string.Join(",", symbols.ToArray()));
            }
            // playback when actual meets expected
            bool allok = true;
            foreach (string sym in symbols)
            {
                if (skipexpected || (actualdays[sym] >= expecteddays))
                {
                    // get tick files
                    string[] tf = files[sym].ToArray();
                    // notify
                    if (deb != null)
                    {
                        deb(sym + " playing back " + tf.Length + " tick files.");
                    }
                    // playback
                    HistSim h = new SingleSimImpl(tf);
                    h.GotTick += new TickDelegate(r.GotTick);
                    h.PlayTo(MultiSimImpl.ENDSIM);
                    h.Stop();
                    // notify
                    if (deb != null)
                    {
                        deb(sym + " completed playback. ");
                    }
                }
                else
                    allok = false;
            }


            return allok;

        }
Esempio n. 7
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;
        }
Esempio n. 8
0
        public void RawPerformanceWithLoad()
        {
            System.ComponentModel.BackgroundWorker bw = new System.ComponentModel.BackgroundWorker();
            bw.DoWork += new System.ComponentModel.DoWorkEventHandler(bw_DoWork);
            bw.WorkerSupportsCancellation = true;
            SingleSimImpl h = new SingleSimImpl(Environment.CurrentDirectory);
            rawbase("raw performance multi w/load", 3, h);
            // tick count is = 42610 (FTI) + 5001 (SPX) + 8041 (ABN)
            Assert.AreEqual(42610 + 4991 + 8041, tickcount);
            // check running time
            Assert.LessOrEqual(h.RunTimeSec, EXPECTRAW, "may fail on slow machines");

            // last time is 1649 on SPX
            Assert.AreEqual(20080318155843, lasttime);
            RawPerformance();
            bw.CancelAsync();
            run = false;
            // tick count is = 42610 (FTI) + 5001 (SPX) + 8041 (ABN)
            Assert.AreEqual(42610 + 4991 + 8041, tickcount);
            // check running time
            Assert.LessOrEqual(h.RunTimeSec, EXPECTRAW, "may fail on slow machines");

            // last time is 1649 on SPX
            Assert.AreEqual(20080318155843, lasttime);
        }
Esempio n. 9
0
        //[Test]
        public void BarPerformance()
        {
            SingleSimImpl h = new SingleSimImpl(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(SingleSimImpl.ENDSIM);

            double time = DateTime.Now.Subtract(start).TotalSeconds;
            h.Stop();
            Assert.GreaterOrEqual(tickcount, 50000);
            Assert.AreEqual(3, bt.SymbolCount);
            Assert.LessOrEqual(time, EXPECTBARS);
            rt.d("BarList runtime: " + time.ToString("N2") + "sec, versus: " + EXPECTBARS + "sec expected.");
            rt.d("BarList " + ((double)tickcount / time).ToString("N0") + " ticks/sec");
        }
Esempio n. 10
0
        //[Test]
        public void ExecutionPerformance()
        {
            System.Threading.Thread.Sleep(100);
            h = new SingleSimImpl(Environment.CurrentDirectory);
            h.Initialize();
            h.GotTick += new TradeLink.API.TickDelegate(execute_GotTick);
            h.SimBroker.GotFill += new TradeLink.API.FillDelegate(SimBroker_GotFill);

            tickcount = 0;
            lasttime = 0;

            Assert.AreEqual(0, tickcount);
            Assert.AreEqual(0, syms.Count);
            Assert.AreEqual(0, lasttime);
            Assert.Greater(h.TicksPresent, 0);
            if (Environment.ProcessorCount == 1) EXPECTEX *= 2.5;

            DateTime start = DateTime.Now;

            h.PlayTo(SingleSimImpl.ENDSIM);

            double time = DateTime.Now.Subtract(start).TotalSeconds;

            rt.d("Execution runtime: " + time.ToString("N2") + "sec, versus: " + EXPECTEX + "sec expected.");
            rt.d("Execution " + ((double)tickcount / time).ToString("N0") + " ticks/sec.  " + ((double)fillcount / time).ToString("N0") + " fills/sec");

            Assert.AreEqual(desiredfills, fillcount);
            Assert.LessOrEqual(time, EXPECTEX);
            h.Stop();
        }