Ejemplo n.º 1
0
        public void Multiple()
        {
            // setup some symbols
            string[] ab = new string[] { "IBM", "LVS", "T", "GS", "MHS" };
            string[] bb = new string[] { "LVS", "MHS" };
            // create baskets from our symbols
            Basket mb = new BasketImpl( ab);
            Basket rem = new BasketImpl(bb);
            // verify symbol counts of our baskets
            Assert.That(mb.Count == ab.Length);
            Assert.That(rem.Count == bb.Length);
            // remove one basket from another
            mb.Remove(rem);
            // verify count matches
            Assert.That(mb.Count == 3,mb.Count.ToString());

            // add single symbol
            Basket cb = new BasketImpl("GM");
            // add another symbol
            cb.Add("GOOG");
            // verify we have two
            Assert.AreEqual(2, cb.Count);
            // attempt to add dupplicate
            cb.Add("GM");
            // verify we have two
            Assert.AreEqual(2, cb.Count);


        }
Ejemplo n.º 2
0
 public void BasketBasics()
 {
     BasketImpl mb = new BasketImpl();
     
     Assert.That(mb != null);
     SecurityImpl i = new SecurityImpl("IBM");
     mb = new BasketImpl(i);
     mb.SendDebugEvent += new DebugDelegate(rt.d);
     Assert.That(mb.isNotEmpty);
     Assert.That(mb.isSecurityPresent(i), "missing ibm security");
     Assert.That(mb.isSymbolPresent("IBM"), "missing ibm symbol");
     Assert.IsFalse(mb.isSymbolPresent("LVS"), "had lvs before added");
     mb.Remove(i);
     Assert.That(!mb.isNotEmpty);
     mb.Add(new SecurityImpl("LVS"));
     Assert.That(mb[0].symbol=="LVS",mb[0].ToString());
     mb.Add(new SecurityImpl("IBM"));
     Assert.That(mb[1].symbol=="IBM");
     mb.Add("CLV8 FUT NYMEX");
     Assert.AreEqual(3, mb.Count,"missing futures symbol");
     Assert.IsTrue(mb[1].Type == SecurityType.STK, "not a equities type:" + mb[1].Type);
     Assert.IsTrue(mb[2].Type == SecurityType.FUT, "not a futures type:"+mb[2].Type);
     Security ts;
     Assert.IsTrue(mb.TryGetSecurityAnySymbol("IBM", out ts), "ibm fetch failed");
     Assert.IsTrue(mb.TryGetSecurityAnySymbol("LVS", out ts), "lvs fetch failed");
     Assert.IsTrue(mb.TryGetSecurityAnySymbol("CLV8", out ts), "CLV8 short fetch failed");
     Assert.IsTrue(mb.TryGetSecurityAnySymbol("CLV8 NYMEX FUT", out ts), "CLV8 short fetch failed");
     BasketImpl newbasket = new BasketImpl(new SecurityImpl("FDX"));
     newbasket.Add(mb);
     var orgcount = mb.Count;
     mb.Clear();
     Assert.That(mb.Count==0,"basket clear did not work");
     Assert.AreEqual(orgcount+1,newbasket.Count,"new basket missing symbols");
 }
Ejemplo n.º 3
0
        public static Basket parsedata(string data, bool onlylinked, bool verify, DebugDelegate d)
        {
            debs = d;
            Basket b = new BasketImpl();

            if (onlylinked)
            {
                Basket b2 = LinkedOnlyNASDAQ(data);
                if (b2.Count > 0)
                {
                    b.Add(b2);
                }
                Basket b3 = LinkedOnlyNYSE(data);
                if (b3.Count > 0)
                {
                    b.Add(b3);
                }
            }
            else
            {
                System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(@"[A-Z.]{1,6}");
                foreach (System.Text.RegularExpressions.Match m in r.Matches(data))
                {
                    b.Add(m.Value);
                }
            }
            return(verify_equitysymbol(b, verify, d));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// gets a basket from a url
 /// </summary>
 /// <returns></returns>
 public Basket FetchURL()
 {
     Basket mb = new BasketImpl();
     if (!Uri.IsWellFormedUriString(_url, UriKind.RelativeOrAbsolute)) return mb;
     if (_nyse && _linkedonly) mb.Add(Fetch.LinkedNYSEFromURL(_url));
     else if (_nyse) mb.Add(Fetch.NYSEFromURL(_url));
     if (_nasd && _linkedonly) mb.Add(Fetch.LinkedNASDAQFromURL(_url));
     else if (_nasd) mb.Add(Fetch.NASDAQFromURL(_url));
     if (_xdupe) mb = Fetch.RemoveDupe(mb);
     return mb;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// gets nyse symbols
 /// </summary>
 /// <param name="ParseStocks"></param>
 /// <returns></returns>
 public static BasketImpl NYSE(string ParseStocks)
 {
     BasketImpl mb = new BasketImpl();
     MatchCollection mc = Regex.Matches(ParseStocks, @"\b[A-Z]{1,3}\b");
     for (int i = 0; i < mc.Count; i++)
         mb.Add(new SecurityImpl(mc[i].Value.ToUpper()));
     return mb;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// remove unlisted symbols, leaving only verified symbols remaining.
 /// tradelink has a list of verified nasdaq and nyse symbols, but it is not guaranteed to be all inclusive.
 /// </summary>
 /// <param name="input"></param>
 /// <returns></returns>
 public static Basket RemoveUnlisted(Basket input)
 {
     Basket output = new BasketImpl();
     for (int i =0; i<input.Count; i++)
         if (NYSE.isListed(input[i].symbol) || NASDAQ.isListed(input[i].symbol))
             output.Add(input[i]);
     return output;
 }
Ejemplo n.º 7
0
 public void BasketBasics()
 {
     BasketImpl mb = new BasketImpl();
     Assert.That(mb != null);
     SecurityImpl i = new SecurityImpl("IBM");
     mb = new BasketImpl(i);
     Assert.That(mb.hasStock);
     mb.Remove(i);
     Assert.That(!mb.hasStock);
     mb.Add(new SecurityImpl("LVS"));
     Assert.That(mb[0].Symbol=="LVS",mb[0].ToString());
     mb.Add(new SecurityImpl("IBM"));
     Assert.That(mb[1].Symbol=="IBM");
     BasketImpl newbasket = new BasketImpl(new SecurityImpl("FDX"));
     newbasket.Add(mb);
     mb.Clear();
     Assert.That(mb.Count==0);
     Assert.That(newbasket.Count==3);
 }
Ejemplo n.º 8
0
        public void Serialization()
        {
            BasketImpl mb = new BasketImpl();
            mb.Add(new SecurityImpl("IBM"));
            BasketImpl compare = BasketImpl.Deserialize(mb.ToString());
            Assert.That(compare.Count == 1);
            mb.Clear();
            compare = BasketImpl.Deserialize(mb.ToString());
            Assert.That(compare.Count==0);

            mb.Clear();
            SecurityImpl longform = SecurityImpl.Parse("CLZ8 FUT NYMEX");
            mb.Add(longform);
            compare = BasketImpl.Deserialize(mb.ToString());
            Assert.AreEqual(longform.ToString(),compare[0].ToString());



        }
Ejemplo n.º 9
0
        /// <summary>
        /// gets nyse symbols
        /// </summary>
        /// <param name="ParseStocks"></param>
        /// <returns></returns>
        public static BasketImpl NYSE(string ParseStocks)
        {
            BasketImpl      mb = new BasketImpl();
            MatchCollection mc = Regex.Matches(ParseStocks, @"\b[A-Z]{1,3}\b");

            for (int i = 0; i < mc.Count; i++)
            {
                mb.Add(new SecurityImpl(mc[i].Value.ToUpper()));
            }
            return(mb);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// gets symbols removed from newbasket, given original basket
 /// </summary>
 /// <param name="old"></param>
 /// <param name="newb"></param>
 /// <returns></returns>
 public static Basket Subtract(Basket old, Basket newb)
 {
     if (old.Count == 0) return new BasketImpl();
     Basket rem = new BasketImpl();
     foreach (Security sec in old)
     {
         if (!newb.ToString().Contains(sec.Symbol))
             rem.Add(sec);
     }
     return rem;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// gets a basket from a file
 /// </summary>
 /// <returns></returns>
 public Basket FetchFILE()
 {
     Basket mb = new BasketImpl();
     if ((_file == "") || (_file == null)) return mb;
     System.IO.StreamReader sr = null;
     try
     {
         sr = new System.IO.StreamReader(_file);
     }
     catch (Exception) { return mb; }
     string file = sr.ReadToEnd();
     if (_nyse && _linkedonly) mb.Add(ParseStocks.LinkedOnlyNYSE(file));
     else if (_nyse) mb.Add(ParseStocks.NYSE(file));
     if (_nasd && _linkedonly) mb.Add(ParseStocks.LinkedOnlyNASDAQ(file));
     else if (_nasd) mb.Add(ParseStocks.NASDAQ(file));
     if (_xdupe) mb = Fetch.RemoveDupe(mb);
     return mb;
     
     
 }
Ejemplo n.º 12
0
 /// <summary>
 /// removes duplicate symbols
 /// </summary>
 /// <param name="input"></param>
 /// <returns></returns>
 public static Basket RemoveDupe(Basket input)
 {
     List<string> cache = new List<string>();
     Basket output = new BasketImpl();
     for (int i = 0; i < input.Count; i++)
         if (!cache.Contains(input[i].Symbol))
         {
             output.Add(input[i]);
             cache.Add(input[i].Symbol);
         }
     return output;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// gets clickable nasdaq symbols found in a string (eg html)
 /// </summary>
 /// <param name="parsestring"></param>
 /// <returns></returns>
 public static BasketImpl LinkedOnlyNASDAQ(string parsestring)
 {
     BasketImpl mb = new BasketImpl();
     string regexp = @">[A-Z]{4}</a>";
     MatchCollection mc = Regex.Matches(parsestring, regexp);
     for (int i = 0; i < mc.Count; i++)
     {
         string chunk = mc[i].Value;
         chunk = chunk.Replace("</a>", "");
         chunk = chunk.TrimStart('>');
         mb.Add(new SecurityImpl(chunk.ToUpper()));
     }
     return mb;
 }
Ejemplo n.º 14
0
        /// <summary>
        /// removes duplicate symbols
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static Basket RemoveDupe(Basket input)
        {
            List <string> cache  = new List <string>();
            Basket        output = new BasketImpl();

            for (int i = 0; i < input.Count; i++)
            {
                if (!cache.Contains(input[i].symbol))
                {
                    output.Add(input[i]);
                    cache.Add(input[i].symbol);
                }
            }
            return(output);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// gets clickable nasdaq symbols found in a string (eg html)
        /// </summary>
        /// <param name="parsestring"></param>
        /// <returns></returns>
        public static BasketImpl LinkedOnlyNASDAQ(string parsestring)
        {
            BasketImpl      mb     = new BasketImpl();
            string          regexp = @">[A-Z]{4}</a>";
            MatchCollection mc     = Regex.Matches(parsestring, regexp);

            for (int i = 0; i < mc.Count; i++)
            {
                string chunk = mc[i].Value;
                chunk = chunk.Replace("</a>", "");
                chunk = chunk.TrimStart('>');
                mb.Add(new SecurityImpl(chunk.ToUpper()));
            }
            return(mb);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// gets symbols removed from newbasket, given original basket
        /// </summary>
        /// <param name="old"></param>
        /// <param name="newb"></param>
        /// <returns></returns>
        public static Basket Subtract(Basket old, Basket newb)
        {
            if (old.Count == 0)
            {
                return(new BasketImpl());
            }
            Basket rem = new BasketImpl();

            foreach (Security sec in old)
            {
                if (!newb.ToString().Contains(sec.symbol))
                {
                    rem.Add(sec);
                }
            }
            return(rem);
        }
Ejemplo n.º 17
0
        public static BasketImpl Deserialize(string serialBasket)
        {
            BasketImpl mb = new BasketImpl();

            if ((serialBasket == null) || (serialBasket == ""))
            {
                return(mb);
            }
            string[] r = serialBasket.Split(',');
            for (int i = 0; i < r.Length; i++)
            {
                if (r[i] == "")
                {
                    continue;
                }
                SecurityImpl sec = SecurityImpl.Parse(r[i]);
                if (sec.isValid)
                {
                    mb.Add(sec);
                }
            }
            return(mb);
        }
Ejemplo n.º 18
0
 static Basket verify_equitysymbol(Basket b, bool googleyahoo, DebugDelegate d)
 {
     debs = d;
     b    = RemoveDupe(b);
     if (googleyahoo)
     {
         Basket v = new BasketImpl();
         foreach (Security s in b)
         {
             BarList bl = BarListImpl.DayFromAny(s.symbol, sdebug);
             if (bl.Count > 0)
             {
                 v.Add(s.symbol);
                 sdebug("verified google/yahoo: " + s.symbol + " bars: " + bl.Count);
             }
             else
             {
                 sdebug("ignoring, not verified google/yahoo: " + s.symbol + " bars: " + bl.Count);
             }
         }
         return(v);
     }
     return(b);
 }
Ejemplo n.º 19
0
 public static BasketImpl Deserialize(string serialBasket)
 {
     BasketImpl mb = new BasketImpl();
     if ((serialBasket == null) || (serialBasket == "")) return mb;
     string[] r = serialBasket.Split(',');
     for (int i = 0; i < r.Length; i++)
     {
         if (r[i] == "") continue;
         SecurityImpl sec = SecurityImpl.Parse(r[i]);
         if (sec.isValid)
             mb.Add(sec);
     }
     return mb;
 }
Ejemplo n.º 20
0
 public static Basket parsedata(string data, bool onlylinked, bool verify, DebugDelegate d)
 {
     debs = d;
     Basket b = new BasketImpl();
     if (onlylinked)
     {
         Basket b2 = LinkedOnlyNASDAQ(data);
         if (b2.Count > 0)
             b.Add(b2);
         Basket b3 = LinkedOnlyNYSE(data);
         if (b3.Count > 0)
             b.Add(b3);
     }
     else
     {
         System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(@"[A-Z.]{1,6}");
         foreach (System.Text.RegularExpressions.Match m in r.Matches(data))
             b.Add(m.Value);
     }
     return verify_equitysymbol(b, verify, d);
 }
Ejemplo n.º 21
0
 static Basket verify_equitysymbol(Basket b, bool googleyahoo, DebugDelegate d)
 {
     debs = d;
     b = RemoveDupe(b);
     if (googleyahoo)
     {
         Basket v = new BasketImpl();
         foreach (Security s in b)
         {
             BarList bl = BarListImpl.DayFromAny(s.symbol,sdebug);
             if (bl.Count > 0)
             {
                 v.Add(s.symbol);
                 sdebug("verified google/yahoo: " + s.symbol + " bars: " + bl.Count);
             }
             else
                 sdebug("ignoring, not verified google/yahoo: " + s.symbol + " bars: " + bl.Count);
         }
         return v;
     }
     return b;
 }