Beispiel #1
0
 /// <summary>
 /// Loads a tick straight from an EPF file in the form of a StreamReader
 /// </summary>
 /// <param name="symbol">The symbol.</param>
 /// <param name="sr">The sr.</param>
 /// <returns></returns>
 public static eSigTick FromStream(string symbol, System.IO.StreamReader sr)
 {
     eSigTick e = new eSigTick();
     e.Load(sr.ReadLine());
     e.sym = symbol;
     return e;
 }
Beispiel #2
0
        /// <summary>
        /// Loads a tick straight from an EPF file in the form of a StreamReader
        /// </summary>
        /// <param name="symbol">The symbol.</param>
        /// <param name="sr">The sr.</param>
        /// <returns></returns>
        public static eSigTick FromStream(string symbol, System.IO.StreamReader sr)
        {
            eSigTick e = new eSigTick();

            e.Load(sr.ReadLine());
            e.sym = symbol;
            return(e);
        }
Beispiel #3
0
 bool getTick()
 {
     string line = "";
     t = new eSigTick();
     try
     {
         line = this.inf.ReadLine();
     }
     catch (Exception ex) { show(ex.Message); }
     return t.Load(line);
 }
Beispiel #4
0
		void Convert(string file)
		{
			StreamReader epf = new StreamReader(file);
			Stock s = eSigTick.InitEpf(epf);
            string symbol = s.Symbol.Replace("//", "");
            if (symmap.ContainsKey(symbol))
                symbol = symbol.Replace(symbol, symmap[symbol]);
			string filename  =  symbol + s.Date + ".IDX";
			d("Attempting to convert: "+file + " -> " + filename);
			StreamWriter idx;
			try 
			{
				idx = new StreamWriter(filename,false);
			}
			catch (Exception ex) { d(ex.Message); return; }

			decimal o = 0;
			decimal h = 0;
			decimal l = 100000000000;
			while (!epf.EndOfStream)
			{
                eSigTick et = new eSigTick();
                et.sym = prefix + symbol;
				try
				{
					string line = epf.ReadLine();  // get our tick from EPF
                    et.Load(line);
                    if (et.FullQuote) continue;
				}
				catch (Exception ex) { d(ex.Message); continue; }
				
				// set o/h/l/c
				decimal v = et.trade;
				if (o==0) o = v; 
				if (v>h) h = v;
				if (v<l) l = v;
				Index i = new Index(et.sym,v,o,h,l,v,et.date,et.time); // map to our index
				idx.WriteLine(i.Serialize()); // write our index
			}
			idx.Close();
			epf.Close();
			d("Finished converting "+filename);
		}
Beispiel #5
0
 public bool getTick()
 {
     string line = "";
     try
     {
         line = this.cf.ReadLine();
     }
     catch (Exception ex) { show(ex.Message+Environment.NewLine); }
     tick = new eSigTick();
     tick.factor = factorsize;
     bool good = false;
     try
     {
         good = tick.Load(line);
     }
     catch (AlreadySmallSizeException)
     {
         factorsize = 1; // fix it for this file
         tick.factor = factorsize;
         good = tick.Load(line);
     }
     tick.sym = symbol;
     return good;
 }
Beispiel #6
0
        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;
        }