public void Basics() { const string sym = "TST"; const int d = 20080509; const int t = 935; const string x = "NYSE"; Tick[] ticklist = new Tick[] { Tick.NewTrade(sym,d,t,0,10,100,x), Tick.NewTrade(sym,d,t+1,0,10,100,x), Tick.NewTrade(sym,d,t+2,0,10,100,x), Tick.NewTrade(sym,d,t+3,0,10,100,x), Tick.NewTrade(sym,d,t+4,0,15,100,x), // blade up Tick.NewTrade(sym,d,t+5,0,16,100,x), // new bar (blades reset) Tick.NewTrade(sym,d,t+6,0,16,100,x), Tick.NewTrade(sym,d,t+7,0,10,100,x), // blade down Tick.NewTrade(sym,d,t+7,10,10,100,x), // still a blade down (same bar) Tick.NewTrade(sym,d,t+8,0,15,100,x), Tick.NewTrade(sym,d,t+15,0,15,800,x), // volume spike Tick.NewTrade(sym,d,t+20,0,15,100,x), Tick.NewTrade(sym,d,t+25,0,15,100,x), }; BarList bl = new BarList(BarInterval.FiveMin,sym); Blade b = new Blade(); Assert.That(b.BladePercentage != 0); b = new Blade(.2m); // 20 percent move is a blade int up=0,down=0,newbar=0,bigvol=0; foreach (Tick k in ticklist) { bl.AddTick(k); b.newBar(bl); if (bl.NewBar) newbar++; if (b.isBladeUP) up++; if (b.isBladeDOWN) down++; if (b.isBigVolume) bigvol++; } Assert.That(up == 1,up.ToString()); Assert.That(down == 2,down.ToString()); Assert.That(newbar == 5,newbar.ToString()); Assert.That(bigvol == 1,bigvol.ToString()); }
public int Test(List<FileInfo> tf) { show("Starting run "+name+" containing "+ tf.Count + " symbols."+Environment.NewLine); int totfills = 0; int totalticks = approxticks(tf); for (int i = 1; i <= tf.Count; i++) // loop through the list { FileInfo f = tf[i-1]; Match m = Regex.Match(f.Name, "([0-9]+)", RegexOptions.IgnoreCase); int date = Convert.ToInt32(m.Result("$1")); LoadIndexFiles(date); TickFile(f.Name); // set current file if (f.Length == 0) continue; // ignore if tick file is empty show(Environment.NewLine); show("Symbol " + this.symbol + " (" + i + " of " + tf.Count + ") "); // reset per-symbol statistics if (mybox!=null) mybox.Reset(); bl = new BarList((BarInterval)bint, symbol); int fills = 0; tick = new eSigTick(); // reset our tick int itime = 0; BoxInfo bi = new BoxInfo(); while (this.getTick() && tick.hasTick) { // process the ticks line++; if ((line % 5000) == 0) show("."); if (((itime==0) || (itime!=tick.time))) { // load all the indicies for this time List<Index> itix = FetchIdx(tick.time); itime = tick.time; // send them to the box (before we send the tix) for (int id = 0; id < itix.Count; id++) mybox.NewIndex(itix[id]); } if ((this.exfilter != "") && ((!tick.isTrade && (!tick.be.Contains(exfilter) || !tick.oe.Contains(exfilter))) || (tick.isTrade && tick.ex.Contains(exfilter)))) continue; if ((bi.Open == 0) && tick.isTrade) bi.Open = tick.trade; if (tick.trade > bi.High) bi.High = tick.trade; if (tick.trade < bi.Low) bi.Low = tick.trade; bl.AddTick(tick); // save our tick to a bar if (bl.Has(2) && bl.Get(bl.Last-1).DayEnd) { // we hit a new day in the same file, reset day stuff and set our DayEndTime bl.Reset(); bl.AddTick(tick); // put our tick back if (mybox!=null) mybox.Reset(); SetDayClose(); // this has to be run after mybox.Reset!!! } // execute any pending orders on this tick if (mybroker.GetOrderList().Count>0) fills += mybroker.Execute(tick); // trade box on this tick, if he generates any orders then send them if (mybox != null) { mybroker.sendOrder( mybox.Trade(tick, bl, mybroker.GetOpenPosition(this.symbol), bi)); // quit early if box shuts itself off and no pending orders if (mybox.Off && (mybroker.GetOrderList().Count == 0)) break; } if (this.delay != 0) { System.Threading.Thread.Sleep(this.delay); System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.Lowest; } this.ReportProgress((int)((100*line) / totalticks)); } show(fills+" executions."); totfills += fills; this.cf.Close(); } show(Environment.NewLine); show(name+" complete: "+tf.Count+" symbols, "+ totfills + " executions."+Environment.NewLine); return totfills; }
/// <summary> /// Build a barlist using an IDX (index) file as a source. /// </summary> /// <param name="filename">The filename.</param> /// <returns></returns> public static BarList FromIDX(string filename) { System.IO.StreamReader sr = new System.IO.StreamReader(filename); Index i = Index.Deserialize(sr.ReadLine()); BarList b = new BarList(BarInterval.FiveMin, i.Name); b.AddTick(i.ToTick()); while (!sr.EndOfStream) b.AddTick(Index.Deserialize(sr.ReadLine()).ToTick()); return b; }
/// <summary> /// Build a barlist using an EPF file as the source /// </summary> /// <param name="filename">The filename.</param> /// <returns></returns> public static BarList FromEPF(string filename) { System.IO.StreamReader sr = new System.IO.StreamReader(filename); Stock s = eSigTick.InitEpf(sr); BarList b = new BarList(BarInterval.FiveMin, s.Symbol); while (!sr.EndOfStream) b.AddTick(eSigTick.FromStream(s.Symbol,sr)); return b; }
public void BollingerBarlisttest() { string symbol = "TST"; BarList bl = new BarList(BarInterval.Minute, symbol); Bollinger bbb = new Bollinger(2, BarInterval.Minute, 10); foreach (Tick t in ticklist) { bl.AddTick(t); bbb.newBar(bl); } Assert.That(bbb.Mean == 3, bbb.Mean.ToString()); Assert.That(bbb.Devavg == 2, bbb.Devavg.ToString()); Assert.That(bbb.Sd == 1.4142135623730950488016887242097, bbb.Sd.ToString()); Assert.That(bbb.Upperband == 5.8284271247462M, bbb.Upperband.ToString()); }
public void BollingerBarlisttestlookbacks() { string symbol = "TST"; BarList bl = new BarList(BarInterval.Minute, symbol); Bollinger bbb = new Bollinger(2, BarInterval.Minute, 4); foreach (Tick t in ticklist) { bl.AddTick(t); bbb.newBar(bl); } Assert.That(bbb.Mean == 3.5M, bbb.Mean.ToString()); Assert.That(bbb.Devavg == 1.25M, bbb.Devavg.ToString()); Assert.That(bbb.Sd == 1.1180339887498948482045868343656, bbb.Sd.ToString()); Assert.That(bbb.Upperband == 5.73606797749978M, bbb.Upperband.ToString()); Assert.That(bbb.Lowerband == 1.26393202250022M, bbb.Lowerband.ToString()); }