Ejemplo n.º 1
0
        /// <summary>
        /// build index for an entire folder
        /// </summary>
        /// <param name="folder"></param>
        public HistSimIndexPlay(string folder, int interval)
        {
            _folder       = folder + "\\";
            string[,] tfi = Util.TickFileIndex(folder, TikConst.WILDCARD_EXT);
            // see if we have index
            string       fn;
            HistSimIndex hsi;

            _extdebug = tfi.GetLength(0) > 500;
            edebug("checking for index for: " + tfi.GetLength(0) + "-sized simulation.");
            if (HistSimIndex.HaveIndex(folder, tfi, interval, out fn))
            {
                edebug("index found.");
                hsi           = HistSimIndex.FromFile(fn);
                hsi.GotDebug += new DebugDelegate(debug);
            }
            else if (HistSimIndex.BuildIndex(folder, tfi, out hsi, true, true, interval, debug))
            {
                edebug("Index built successfully. ");
            }
            else
            {
                debug("Error building index.");
                return;
            }
            myhsi           = hsi;
            _reader.DoWork += new DoWorkEventHandler(_reader_DoWork);
            _reader.WorkerSupportsCancellation = true;

            hsip_avail = hsi.Playindex.Length;
            checkindex();
        }
Ejemplo n.º 2
0
        public HistSimIndexPlay(string folder, TickFileFilter tff, int interval, DebugDelegate deb)
        {
            if (deb != null)
            {
                GotDebug += deb;
            }
            _folder = folder + "\\";
            // see if we have index
            string       fn;
            HistSimIndex hsi;

            debug("getting tickfiles, please wait...");

            string[,] total = tff.bUseCSV ? ChimeraDataUtils.TickFileIndex(folder, "*_trades.csv", true)
                                : Util.TickFileIndex(folder, TikConst.WILDCARD_EXT, false);
            debug("found " + total.GetLength(0).ToString("N0") + " tickfiles");
            string[,] filtered = tff.AllowsIndexAndSize(total);
            debug("post-filter: " + filtered.GetLength(0).ToString("N0") + ", checking for index...");

            if (HistSimIndex.HaveIndex(folder, filtered, out fn, deb, tff.bUseCSV))
            {
                debug("index found, starting load: " + fn);
                hsi = HistSimIndex.FromFile(fn, debug);
                if (hsi == null)
                {
                    debug("unable to load index.");
                    return;
                }
                hsi.GotDebug += new DebugDelegate(debug);
            }
            else if (HistSimIndex.BuildIndex(folder, filtered, out hsi, true, true, interval, debug, tff.bUseCSV))
            {
                debug("Index built successfully, ready to play.");
            }
            else
            {
                debug("Error building index...");
                return;
            }
            _reader.DoWork += new DoWorkEventHandler(_reader_DoWork);
            _reader.WorkerSupportsCancellation = true;
            myhsi      = hsi;
            hsip_avail = hsi.Playindex.Length;
            checkindex();
        }
Ejemplo n.º 3
0
        public HistSimIndexPlay(string[] dataset, string folder, int interval, DebugDelegate deb)
        {
            if (deb != null)
            {
                GotDebug += deb;
            }
            if (dataset.Length < 1)
            {
                debug("Empty data set, quitting...");
                return;
            }
            _folder = folder;
            // get index of set
            string[,] tfi = GetTickIndex(dataset, false, folder);
            _extdebug     = tfi.GetLength(0) > 500;
            // see if we have index
            string       fn;
            HistSimIndex hsi;

            edebug("checking for index");
            if (HistSimIndex.HaveIndex(folder, tfi, interval, out fn))
            {
                edebug("index found.");
                hsi           = HistSimIndex.FromFile(fn);
                hsi.GotDebug += new DebugDelegate(debug);
            }
            else if (HistSimIndex.BuildIndex(folder, tfi, out hsi, true, true, interval, debug))
            {
                edebug("Index built successfully");
            }
            else
            {
                debug("Error building index...");
                return;
            }
            myhsi           = hsi;
            _reader.DoWork += new DoWorkEventHandler(_reader_DoWork);
            _reader.WorkerSupportsCancellation = true;

            hsip_avail = hsi.Playindex.Length;
            checkindex();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// checks whether we already have an index built for a given data set.
        /// if index is empty, deletes index.
        /// </summary>
        /// <param name="folder"></param>
        /// <param name="tff"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        public static bool HaveIndex(string folder, string[,] tickindex, int interval, out string file)
        {
            HistSimIndex hsi;

            if (BuildIndex(folder, tickindex, out hsi, false, false, interval, null))
            {
                string checksum = MD5(indextoc(hsi));
                string fn       = idxfold(folder) + checksum + ".txt";
                if (File.Exists(fn))
                {
                    file = fn;
                    hsi  = HistSimIndex.FromFile(fn);
                    bool complete = hsi.isComplete && (hsi.Playindex.Length > 0);
                    if (!complete)
                    {
                        File.Delete(fn);
                        return(false);
                    }
                    return(true);
                }
            }
            file = string.Empty;
            return(false);
        }