Beispiel #1
0
        public void Basics()
        {
            // build a one symbol filter
            TickFileFilter tff = new TickFileFilter(new[] { "GM" });

            // get results from above data files
            string[] result = tff.Allows(_filenames);
            // make sure both files for this symbol match
            Assert.Equal(2, result.Length);
            // make sure the actual file names are the same
            Assert.Equal(result[0], _filenames[0]);
            Assert.Equal(result[1], _filenames[4]);
            // build a new filter
            tff = new TickFileFilter();
            // request all matching files for a given year
            tff.DateFilter(20070000, DateMatchType.Year);
            tff.IsDateMatchUnion       = true;
            tff.IsSymbolDateMatchUnion = true;
            // do the match
            result = tff.Allows(_filenames);
            // make sure we found 3 files from this year
            Assert.Equal(3, result.Length);
            // make sure the filename is the same
            Assert.Equal(_filenames[3], result[2]);
        }
Beispiel #2
0
        private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
        {
            // create a new filter
            TickFileFilter tff = new TickFileFilter();

            // populate the filter from user's calendar
            tff.DateFilter(Util.ToTLDate(monthCalendar1.SelectionEnd), DateMatchType.Day | DateMatchType.Month | DateMatchType.Year);
            // set the filter on the simulator
            h.FileFilter = tff;
        }
Beispiel #3
0
        static TickFileFilter getfilterdate(int date)
        {
            // create a new filter
            TickFileFilter tff = new TickFileFilter();

            // we dont' select any symbols, so just playback whatever we find on this day
            tff.isSymbolDateMatchUnion = true;
            // populate the filter from user's calendar
            tff.DateFilter(date, DateMatchType.Day | DateMatchType.Month | DateMatchType.Year);
            return(tff);
        }
Beispiel #4
0
        public void AndTest()
        {
            // build a filter with two stocks
            TickFileFilter tff = new TickFileFilter(new string[] { "GM", "SPX" });

            // add date file for year
            tff.DateFilter(20070000, DateMatchType.Year);
            // add another date filter for month
            tff.DateFilter(600, DateMatchType.Month);
            // set DateFilter to AND/intersection
            tff.isDateMatchUnion = false;
            // make sure three stocks match
            string[] result = tff.Allows(filenames);
            Assert.AreEqual(3, result.Length);
            // set more exclusive filter
            tff.isSymbolDateMatchUnion = false;
            // make sure two stocks match
            result = tff.Allows(filenames);
            Assert.AreEqual(2, result.Length);
        }
Beispiel #5
0
        /// <summary>
        /// Returns the TIK file filter based on the samples used in this backtest
        /// </summary>
        /// <param name="baseFolder"></param>
        /// <param name="symbol"></param>
        /// <param name="filter"></param>
        /// <param name="startdate"></param>
        /// <param name="enddate"></param>
        /// <returns></returns>
        private static string[] GetTIKFiles(string baseFolder, ISecurityTracker securities, out TickFileFilter filter, int startdate, int enddate)
        {
            List <string> files = new List <string>();

            //Create filter with the symbols as requested
            List <string> symbols = new List <string>();

            foreach (var sec in securities.ToArray())
            {
                symbols.Add(sec.Name);
            }
            filter = new TickFileFilter(symbols);

            //Add the initial timeperiod
            DateTime ct           = Util.Qld2Dt(startdate);
            TimeSpan periodlenght = Util.Qld2Dt(enddate) - Util.Qld2Dt(startdate);

            //Filter the period
            for (int i = 0; i < periodlenght.TotalDays; i++)
            {
                filter.DateFilter(int.Parse(ct.AddDays(i).ToString("yyyyMMdd")), DateMatchType.Day);
            }

            //settings
            filter.IsDateMatchUnion = true;
            filter.DefaultDeny      = true;

            //Select tickfiles
            foreach (var xdate in filter.DateList)
            {
                foreach (var symbol in filter.SymbolList)
                {
                    //Check if file exists in the zip file
                    FileInfo fi = new FileInfo(baseFolder + string.Format("\\{0}.zip", symbol));

                    if (!fi.Exists)
                    {
                        throw new FileNotFoundException("Could not find tik archive");
                    }

                    using (ZipFile zip = ZipFile.Read(fi.FullName))
                    {
                        if (!zip.ContainsEntry(symbol.ToUpper() + xdate.Date + ".TIK"))
                        {
                            continue;
                        }
                    }
                    string file = fi.FullName + @"\" + symbol.ToUpper() + xdate.Date + ".TIK";
                    files.Add(file);
                }
            }
            return(files.ToArray());
        }
Beispiel #6
0
        public void Basics()
        {
            TickFileFilter tff = new TickFileFilter(new string[] { "GM" });

            string[] result = tff.Allows(filenames);
            Assert.That(result.Length == 1);
            Assert.That(result[0] == filenames[0]);
            tff = new TickFileFilter();
            tff.DateFilter(20070000, DateMatchType.Year);
            result = tff.Allows(filenames);
            Assert.That(result.Length == 3);
            Assert.That(result[2] == filenames[3]);
        }
Beispiel #7
0
        public void SerializeDeserialize()
        {
            TickFileFilter tff = new TickFileFilter(new string[] { "IBM", "MHS", "T" });

            tff.DateFilter(20070000, DateMatchType.Year);
            tff.isDateMatchUnion       = false;
            tff.isSymbolDateMatchUnion = false;
            string msg = TickFileFilter.Serialize(tff);

            TickFileFilter f2 = TickFileFilter.Deserialize(msg);

            string msg2 = TickFileFilter.Serialize(f2);

            Assert.AreEqual(msg, msg2);
            Assert.AreEqual(tff.isDateMatchUnion, f2.isDateMatchUnion);
            Assert.AreEqual(tff.isSymbolDateMatchUnion, f2.isDateMatchUnion);
        }
Beispiel #8
0
        private void playbut_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(tickfolder))
            {
                status("Tick folder " + tickfolder + " doesn't exist,  stopping.");
                return;
            }
            highs = new Dictionary <string, decimal>();
            lows  = new Dictionary <string, decimal>();
            TickFileFilter tff = new TickFileFilter();

            tff.DateFilter(Util.ToTLDate(monthCalendar1.SelectionEnd), DateMatchType.Day | DateMatchType.Month | DateMatchType.Year);
            h.FileFilter = tff;
            _playback    = new Playback(h);
            _playback.RunWorkerCompleted += new RunWorkerCompletedEventHandler(_playback_RunWorkerCompleted);
            _playback.ProgressChanged    += new ProgressChangedEventHandler(_playback_ProgressChanged);
            _playback.RunWorkerAsync(new PlayBackArgs((int)trackBar1.Value / 5, daystartpicker.Value));
            status("Playback started...");
            playbut.Enabled   = false;
            stopbut.Enabled   = true;
            trackBar1.Enabled = false;
        }