/// <summary> /// serialize a tradelink tick file filter /// </summary> /// <param name="tff"></param> /// <returns></returns> public static string Serialize(TickFileFilter tff) { // save everything as xml StringWriter fs; try { XmlSerializer xs = new XmlSerializer(typeof(TickFileFilter)); fs = new StringWriter(); xs.Serialize(fs, tff); fs.Close(); } catch (FileNotFoundException) { return(string.Empty); } catch (Exception) { return(string.Empty); } if (fs == null) { return(""); } return(fs.GetStringBuilder().ToString()); }
/// <summary> /// gets currently selected filter /// </summary> /// <returns></returns> public TickFileFilter GetFilter() { TickFileFilter tff = new TickFileFilter(); // prepare date filter List<TickFileFilter.TLDateFilter> datefilter = new List<TickFileFilter.TLDateFilter>(); if (usedates.Checked) { for (int j = 0; j < yearlist.SelectedIndices.Count; j++) datefilter.Add(new TickFileFilter.TLDateFilter(Convert.ToInt32(yearlist.Items[yearlist.SelectedIndices[j]]) * 10000, DateMatchType.Year)); for (int j = 0; j < monthlist.SelectedItems.Count; j++) datefilter.Add(new TickFileFilter.TLDateFilter(Convert.ToInt32(monthlist.Items[monthlist.SelectedIndices[j]]) * 100, DateMatchType.Month)); for (int j = 0; j < daylist.SelectedItems.Count; j++) datefilter.Add(new TickFileFilter.TLDateFilter(Convert.ToInt32(daylist.Items[daylist.SelectedIndices[j]]), DateMatchType.Day)); } // prepare symbol filter List<string> symfilter = new List<string>(); if (usestocks.Checked) for (int j = 0; j < stocklist.SelectedItems.Count; j++) symfilter.Add(stocklist.Items[stocklist.SelectedIndices[j]].ToString()); // build consolidated filter if (usestocks.Checked && usedates.Checked) tff = new TickFileFilter(symfilter, datefilter); else if (usestocks.Checked) tff = new TickFileFilter(symfilter); else if (usedates.Checked) tff = new TickFileFilter(datefilter); // set search options tff.isDateMatchUnion = _dateor.Checked; tff.isSymbolDateMatchUnion = !_symdateand.Checked; //return filter return tff; }
/// <summary> /// save tickfilefilter to a file /// </summary> /// <param name="filename"></param> /// <returns></returns> public static TickFileFilter FromFile(string filename) { StreamReader sr = new StreamReader(filename); string msg = sr.ReadToEnd(); TickFileFilter tff = TickFileFilter.Deserialize(msg); return(tff); }
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; }
/// <summary> /// Create a historical simulator /// </summary> /// <param name="TickFolder">tick folder to use</param> /// <param name="tff">filter to determine what tick files from folder to use</param> public MultiSimImpl(string TickFolder, TickFileFilter tff) { _folder = TickFolder; if (tff != null) _filter = tff; else { _filter.DefaultDeny = false; } }
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); }
/// <summary> /// restore a filter from a file /// </summary> /// <param name="tff"></param> /// <param name="filename"></param> /// <returns></returns> public static bool ToFile(TickFileFilter tff, string filename) { try { StreamWriter sw = new StreamWriter(filename, false); sw.AutoFlush = true; sw.WriteLine(TickFileFilter.Serialize(tff)); sw.Close(); } catch (Exception) { return(false); } return(true); }
public GauntletEngine(TradeLink.API.Response r, TickFileFilter tff) { _r = r; _r.SendOrderEvent += new OrderSourceDelegate(_r_SendOrder); _r.SendCancelEvent += new LongSourceDelegate(_r_SendCancel); _tff = tff; _h = new MultiSimImpl(_tff); _h.GotTick += new TickDelegate(_h_GotTick); SimBroker.GotOrderCancel += new OrderCancelDelegate(SimBroker_GotOrderCancel); SimBroker.GotOrder += new OrderDelegate(_r.GotOrder); SimBroker.GotFill += new FillDelegate(_r.GotFill); }
/// <summary> /// Create a historical simulator /// </summary> /// <param name="TickFolder">tick folder to use</param> /// <param name="tff">filter to determine what tick files from folder to use</param> public SingleSimImpl(string TickFolder, TickFileFilter tff) { _folder = TickFolder; if (tff != null) { _filter = tff; } else { _filter.DefaultDeny = false; } }
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 static bool BuildIndex(string folder, TickFileFilter tff, out HistSimIndex hsi, bool start, bool saveidx, int interval, DebugDelegate debug) { if (debug != null) { debug("getting tickfiles available, please wait..."); } string[,] allows = Util.TickFileIndex(folder, TikConst.WILDCARD_EXT); if (debug != null) { debug("found " + allows.Length + " tickfiles."); } return(BuildIndex(folder, allows, tff, out hsi, start, saveidx, interval, debug)); }
public static bool BuildIndex(string folder, string[,] tickfiles, TickFileFilter tff, out HistSimIndex hsi, bool start, bool saveidx, int interval, DebugDelegate debug) { if (debug != null) { debug("filtering tickfiles..."); } string[,] allows = tff.AllowsIndexAndSize(tickfiles); if (debug != null) { debug("using " + allows.Length + " tickfiles post-filter."); } return(BuildIndex(folder, allows, out hsi, start, saveidx, interval, debug)); }
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); }
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(); }
public static bool HaveIndex(string folder, TickFileFilter tff, out string file, DebugDelegate debug) { if (debug != null) { debug("getting tickfiles present: " + folder); } string[,] files = Util.TickFileIndex(folder, TikConst.WILDCARD_EXT); if (debug != null) { debug("got " + files.Length.ToString("N0") + " tickfiles"); } string[,] filtered = tff.AllowsIndexAndSize(files); if (debug != null) { debug("found " + filtered.GetLength(0).ToString("N0") + " files post-filter."); } return(HaveIndex(folder, filtered, out file, debug)); }
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); }
/// <summary> /// take a serialized tickfilefilter and convert back to an object /// </summary> /// <param name="msg"></param> /// <returns></returns> public static TickFileFilter Deserialize(string msg) { StringReader fs; TickFileFilter tf = null; try { // prepare serializer XmlSerializer xs = new XmlSerializer(typeof(TickFileFilter)); // read in message fs = new StringReader(msg); // deserialize message tf = (TickFileFilter)xs.Deserialize(fs); // close serializer fs.Close(); } catch (FileNotFoundException) { } catch (Exception) { } return(tf); }
/// <summary> /// gets currently selected filter /// </summary> /// <returns></returns> public TickFileFilter GetFilter() { // prepare date filter List <TickFileFilter.TLDateFilter> datefilter = new List <TickFileFilter.TLDateFilter>(); if (usedates.Checked) { for (int j = 0; j < yearlist.SelectedIndices.Count; j++) { datefilter.Add(new TickFileFilter.TLDateFilter(Convert.ToInt32(yearlist.Items[yearlist.SelectedIndices[j]]) * 10000, DateMatchType.Year)); } for (int j = 0; j < monthlist.SelectedItems.Count; j++) { datefilter.Add(new TickFileFilter.TLDateFilter(Convert.ToInt32(monthlist.Items[monthlist.SelectedIndices[j]]) * 100, DateMatchType.Month)); } for (int j = 0; j < daylist.SelectedItems.Count; j++) { datefilter.Add(new TickFileFilter.TLDateFilter(Convert.ToInt32(daylist.Items[daylist.SelectedIndices[j]]), DateMatchType.Day)); } } // prepare symbol filter List <string> symfilter = new List <string>(); if (usestocks.Checked) { for (int j = 0; j < stocklist.SelectedItems.Count; j++) { symfilter.Add(stocklist.Items[stocklist.SelectedIndices[j]].ToString()); } } // build consolidated filter TickFileFilter tff = new TickFileFilter(symfilter, datefilter); // set search options tff.isDateMatchUnion = _dateor.Checked; tff.isSymbolDateMatchUnion = !_symdateand.Checked; //return filter return(tff); }
public void Basics() { // build a one symbol filter TickFileFilter tff = new TickFileFilter(new string[] { "GM" }); // get results from above data files string[] result = tff.Allows(filenames); // make sure both files for this symbol match Assert.AreEqual(2,result.Length); // make sure the actual file names are the same Assert.AreEqual(result[0],filenames[0]); Assert.AreEqual(result[1], filenames[4]); // build a new filter tff = new TickFileFilter(); // request all matching files for a given year tff.DateFilter(20070000, DateMatchType.Year); // do the match result = tff.Allows(filenames); // make sure we found 3 files from this year Assert.AreEqual(3, result.Length); // make sure the filename is the same Assert.AreEqual(filenames[3], result[2]); }
/// <summary> /// Create a historical simulator /// </summary> /// <param name="tff"></param> public HistSim(TickFileFilter tff) : this(Util.TLTickDir, tff) { }
bool getsimhints(string folder, TickFileFilter tff, ref int date, ref string[] syms) { date = 0; syms = new string[0]; try { string[] files = Directory.GetFiles(folder, TikConst.WILDCARD_EXT); var simfiles = tff.Allows(files); List<string> simsyms = new List<string>(simfiles.Length); Array.Sort(simfiles); // get earliest date var min = int.MaxValue; foreach (var sf in simfiles) { var sec = SecurityImpl.SecurityFromFileName(sf); if (!string.IsNullOrWhiteSpace(sec.symbol) && !simsyms.Contains(sec.symbol)) simsyms.Add(sec.symbol); if ((sec.Date > 0) && (sec.Date < min)) min = sec.Date; } if (min != int.MaxValue) date = min; syms = simsyms.ToArray(); return true; } catch (Exception ex) { debug("error getting sim hints: " + ex.Message + ex.StackTrace); return false; } }
/// <summary> /// checks whether we already have an index built for a given pre-filtered data set /// </summary> /// <param name="folder"></param> /// <param name="tff"></param> /// <param name="file"></param> /// <returns></returns> public static bool HaveIndex(string folder, TickFileFilter tff, out string file) { return(HaveIndex(folder, tff, out file, null)); }
public static bool HaveIndex(string folder, TickFileFilter tff, out string file, DebugDelegate debug) { if (debug != null) debug("getting tickfiles present: " + folder); string[,] files = Util.TickFileIndex(folder, TikConst.WILDCARD_EXT); if (debug!=null) debug("got "+files.Length.ToString("N0")+" tickfiles"); string[,] filtered = tff.AllowsIndexAndSize(files); if (debug != null) debug("found " + filtered.GetLength(0).ToString("N0") + " files post-filter."); return HaveIndex(folder, filtered, out file, debug); }
private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e) { // set the filter on the simulator FileFilter = getfilterdate(Util.ToTLDate(monthCalendar1.SelectionEnd)); }
public HistSimMemory(string folder, TickFileFilter tff) : base(folder, tff,0, null) { }
/// <summary> /// get index from a set of tick files given a filter and starts indexing /// </summary> /// <param name="folder"></param> /// <param name="tff"></param> /// <param name="hsi"></param> /// <returns></returns> public static bool BuildIndex(string folder, TickFileFilter tff, out HistSimIndex hsi) { return BuildIndex(folder, tff, out hsi, true, true, 0,null); }
public static bool BuildIndex(string folder, TickFileFilter tff, out HistSimIndex hsi,int interval,DebugDelegate debug) { if (debug != null) debug("getting tickfiles available, please wait..."); string[,] allows = Util.TickFileIndex(folder, TikConst.WILDCARD_EXT); if (debug != null) debug("found " + allows.Length + " tickfiles."); return BuildIndex(folder,allows, tff,out hsi, true,true,interval,debug); }
/// <summary> /// gets index from set of tick files and starts indexing /// </summary> /// <param name="tickfiles"></param> /// <param name="tff"></param> /// <param name="hsi"></param> /// <param name="start"></param> /// <returns></returns> public static bool BuildIndex(string folder, string[,] tickfiles, TickFileFilter tff, out HistSimIndex hsi) { return BuildIndex(folder, tickfiles, tff,out hsi,0, null); }
/// <summary> /// Create a historical simulator /// </summary> /// <param name="tff"></param> public SingleSimImpl(TickFileFilter tff) : this(Util.TLTickDir, tff) { }
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; }
/// <summary> /// get index from a set of tick files given a filter /// </summary> /// <param name="folder"></param> /// <param name="tff"></param> /// <param name="hsi"></param> /// <returns></returns> public static bool BuildIndex(string folder, TickFileFilter tff, out HistSimIndex hsi, bool start) { return(BuildIndex(folder, tff, out hsi, start, true, 0, null)); }
/// <summary> /// create a player from some tickdata, attempt to create index if not present /// </summary> /// <param name="folder"></param> /// <param name="tff"></param> public HistSimIndexPlay(string folder, TickFileFilter tff) : this(folder, tff, 0, null) { }
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 = 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)) { 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)) { 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(); }
public HistSimMemory(string folder, TickFileFilter tff,DebugDelegate deb) : base(folder, tff,0,deb) { }
/// <summary> /// checks whether we already have an index built for a given pre-filtered data set /// </summary> /// <param name="folder"></param> /// <param name="tff"></param> /// <param name="file"></param> /// <returns></returns> public static bool HaveIndex(string folder, TickFileFilter tff, out string file) { return HaveIndex(folder, tff, out file, null); }
public HistSimMemory(string folder, TickFileFilter tff) : base(folder, tff, 0, null) { }
/// <summary> /// get index from set of tick files given a filter /// </summary> /// <param name="tickfiles"></param> /// <param name="tff"></param> /// <param name="hsi"></param> /// <returns></returns> public static bool BuildIndex(string folder, string[,] tickfiles, TickFileFilter tff, out HistSimIndex hsi, bool start, bool bUseCSV) { return(BuildIndex(folder, tickfiles, out hsi, start, true, 0, null, bUseCSV)); }
public HistSimMemory(string folder, TickFileFilter tff, DebugDelegate deb) : base(folder, tff, 0, deb) { }
/// <summary> /// create a player from some tickdata, attempt to create index if not present /// </summary> /// <param name="folder"></param> /// <param name="tff"></param> public HistSimIndexPlay(string folder, TickFileFilter tff) : this(folder, tff, 0,null) { }
/// <summary> /// gets index from set of tick files and starts indexing /// </summary> /// <param name="tickfiles"></param> /// <param name="tff"></param> /// <param name="hsi"></param> /// <param name="start"></param> /// <returns></returns> public static bool BuildIndex(string folder, string[,] tickfiles, TickFileFilter tff, out HistSimIndex hsi) { return(BuildIndex(folder, tickfiles, tff, out hsi, 0, null)); }
/// <summary> /// serialize a tradelink tick file filter /// </summary> /// <param name="tff"></param> /// <returns></returns> public static string Serialize(TickFileFilter tff) { // save everything as xml StringWriter fs; try { XmlSerializer xs = new XmlSerializer(typeof(TickFileFilter)); fs = new StringWriter(); xs.Serialize(fs, tff); fs.Close(); } catch (FileNotFoundException) { return string.Empty; } catch (Exception) { return string.Empty; } if (fs == null) return ""; return fs.GetStringBuilder().ToString(); }
public static bool BuildIndex(string folder, string[,] tickfiles, TickFileFilter tff, out HistSimIndex hsi, int interval, DebugDelegate debug) { if (debug != null) debug("filtering tickfiles..."); string[,] allows = tff.AllowsIndexAndSize(tickfiles); if (debug != null) debug("using " + allows.Length + " tickfiles post-filter."); return BuildIndex(folder,allows, out hsi, true,true,interval,debug); }
/// <summary> /// Create a historical simulator /// </summary> /// <param name="tff"></param> public MultiSimImpl(TickFileFilter tff) : this(Util.TLTickDir, tff) { }
/// <summary> /// restore a filter from a file /// </summary> /// <param name="tff"></param> /// <param name="filename"></param> /// <returns></returns> public static bool ToFile(TickFileFilter tff, string filename) { try { StreamWriter sw = new StreamWriter(filename, false); sw.AutoFlush = true; sw.WriteLine(TickFileFilter.Serialize(tff)); sw.Close(); } catch (Exception) { return false; } return true; }
bool SetFilter(string file) { if (File.Exists(file)) { _filterloc = file; _filter = TickFileFilter.FromFile(file); D("found filter: " + file); return true; } else D("no filter found: " + file); return false; }