Exemple #1
0
        protected void debugMarketSimulationMaofSecsMaof(IWrite iWrite, string cmdName, object[] cmdArguments)
        {
            int[] ids = marketSimulationMaof.GetSecurities();               //get the list of securities

            System.Collections.ArrayList names = new System.Collections.ArrayList();
            names.Add("Id");
            names.Add("Name");
            names.Add("Bid:PriceVolume");
            names.Add("Ask:PriceVolume");

            int[] columns = JQuant.ArrayUtils.CreateInitializedArray(6, names.Count);
            columns[0] = 10;
            columns[1] = 16;
            columns[2] = 30;
            columns[3] = 30;

            CommandLineInterface.printTableHeader(iWrite, names, columns);

            System.Array.Sort(ids);

            foreach (int id in ids)
            {
                MarketSimulationMaof.Option  option = marketSimulationMaof.GetOption(id);
                System.Collections.ArrayList values = new System.Collections.ArrayList();

                values.Add(id);
                values.Add(option.GetName());
                values.Add(OrderBook2String(option.GetBookBid(), 9));
                values.Add(OrderBook2String(option.GetBookAsk(), 9));

                CommandLineInterface.printValues(iWrite, values, columns);
            }
        }
Exemple #2
0
 public void printList()
 {
     int[] list = marketSimulationMaof.WatchList();
     for (int i = 0; i < list.Length; i++)
     {
         int id = list[i];
         MarketSimulationMaof.Option option = marketSimulationMaof.GetOption(id);
         string optionName = option.GetName();
         System.Collections.ArrayList values = new System.Collections.ArrayList();
         values.Add(id);
         values.Add(optionName);
         CommandLineInterface.printValues(iWrite, values, this.columns);
     }
 }
Exemple #3
0
        protected void placeOrderCallback(MarketSimulation.ReturnCode errorCode, MarketSimulation.ISystemLimitOrder lo, int quantity)
        {
            MarketSimulationMaof.Option option = marketSimulationMaof.GetOption(lo.SecurityId);
            string optionName = option.GetName();

            if (errorCode == MarketSimulation.ReturnCode.Fill)
            {
                System.Console.WriteLine("Tick {6} Order {0} {5} id {1} quantity {3} price {4} got fill at price {2}",
                                         optionName, lo.Id, lo.FillPrice, quantity, lo.Price, lo.SecurityId, lo.FillTick);
            }
            else
            {
                System.Console.WriteLine("Tick {5} Order {0} id {1} price {2} quantity {3} failed on {4}",
                                         optionName, lo.Id, lo.Price, quantity, errorCode.ToString(), lo.FillTick);
            }
        }
Exemple #4
0
        /// <summary>
        /// This method do two things
        /// - get list of securities from the MarketSimulationMaof
        /// For every security ask MarketSimulation.Core what the Core thinks about it.
        /// </summary>
        protected void debugMarketSimulationMaofSecsCore(IWrite iWrite, string cmdName, object[] cmdArguments)
        {
            int[] ids = marketSimulationMaof.GetSecurities();               //get the list of securities

            System.Collections.ArrayList names = new System.Collections.ArrayList();
            names.Add("Id");
            names.Add("Name");
            names.Add("CoreId");
            names.Add("Bid:PriceVolume");
            names.Add("Ask:PriceVolume");
            names.Add("LastTrade");
            names.Add("LastTradeSize");
            names.Add("DayVolume");

            int[] columns = JQuant.ArrayUtils.CreateInitializedArray(6, names.Count);
            columns[0] = 9;
            columns[1] = 12;
            columns[2] = 9;
            columns[3] = 30;
            columns[4] = 30;

            CommandLineInterface.printTableHeader(iWrite, names, columns);

            System.Array.Sort(ids);

            foreach (int id in ids)
            {
                // i need MarketSimulationMaof.Option to show the name of the option
                // currently I take care only of options
                MarketSimulationMaof.Option option = marketSimulationMaof.GetOption(id);
                // get information kept in the MrketSimulation.Core
                MarketSimulation.MarketData  md     = marketSimulationMaof.GetSecurity(id);
                System.Collections.ArrayList values = new System.Collections.ArrayList();

                values.Add(id);
                values.Add(option.GetName());
                values.Add(md.id);
                values.Add(OrderBook2String(md.bid, 9));
                values.Add(OrderBook2String(md.ask, 9));
                values.Add(md.lastTrade);
                values.Add(md.lastTradeSize);
                values.Add(md.dayVolume);

                CommandLineInterface.printValues(iWrite, values, columns);
            }
        }
Exemple #5
0
            /// <summary>
            /// called by MarketSimulation when a change is in the status of the security
            /// </summary>
            public void callback(MarketSimulation.MarketData md)
            {
                int id = md.id;

                MarketSimulationMaof.Option option = marketSimulationMaof.GetOption(id);
                string optionName = option.GetName();

                // print everything out - name, bids, asks
                MarketSimulation.OrderPair[] bids = md.bid;
                MarketSimulation.OrderPair[] asks = md.ask;

                System.Collections.ArrayList values = new System.Collections.ArrayList();

                values.Add(md.tick);
                values.Add(id);
                values.Add(optionName);
                values.Add(md.lastTrade);
                values.Add(md.dayVolume);
                values.Add(OrderBook2String(bids, 9));
                values.Add(OrderBook2String(asks, 9));

                CommandLineInterface.printValues(iWrite, values, this.columns);
            }
Exemple #6
0
        protected void debugMarketSimulationMaofStatBook(IWrite iWrite, string cmdName, object[] cmdArguments)
        {
            int[] ids       = marketSimulationMaof.GetSecurities();         //get the list of securities
            int[] columns   = new int[0];
            bool  firstLoop = true;

            System.Collections.ArrayList names = new System.Collections.ArrayList();
            names.Add("Name");

            System.Array.Sort(ids);

            foreach (int id in ids)
            {
                MarketSimulationMaof.Option  option = marketSimulationMaof.GetOption(id);
                System.Collections.ArrayList values = new System.Collections.ArrayList();


                JQuant.IResourceStatistics   bids = marketSimulationMaof.GetOrderBook(id, JQuant.TransactionType.BUY);
                System.Collections.ArrayList bidValues;
                System.Collections.ArrayList bidNames;
                bids.GetEventCounters(out bidNames, out bidValues);

                JQuant.IResourceStatistics   asks = marketSimulationMaof.GetOrderBook(id, JQuant.TransactionType.SELL);
                System.Collections.ArrayList askValues;
                System.Collections.ArrayList askNames;
                asks.GetEventCounters(out askNames, out askValues);

                // print table header if this is first loop
                if (firstLoop)
                {
                    firstLoop = false;
                    for (int i = 0; i < bidNames.Count; i++)
                    {
                        names.Add(bidNames[i]);
                    }
                    for (int i = 0; i < askNames.Count; i++)
                    {
                        names.Add(askNames[i]);
                    }
                    columns    = JQuant.ArrayUtils.CreateInitializedArray(6, names.Count);
                    columns[0] = 16;
                    columns[1] = 10;
                    columns[2] = 6;
                    columns[3] = 6;
                    columns[4] = 6;
                    columns[5] = 10;
                    columns[6] = 6;
                    columns[7] = 6;
                    columns[8] = 6;
                    CommandLineInterface.printTableHeader(iWrite, names, columns);
                }

                values.Add(option.GetName());
                for (int i = 0; i < bidValues.Count; i++)
                {
                    values.Add(bidValues[i]);
                }
                for (int i = 0; i < askValues.Count; i++)
                {
                    values.Add(askValues[i]);
                }

                CommandLineInterface.printValues(iWrite, values, columns);
            }
        }
Exemple #7
0
        /// <summary>
        /// This is a magic (aka Trust the force) method which goes through the
        /// CLI command arguments and look for a ticker IDs. The emthod recognize
        /// different formats of tickers. For example
        /// - the unique integer 80613003
        /// - partial integer 13003 (if unique)
        /// - description 'Call 1800 Nov'
        /// - description 'C1800Nov'
        /// - description 'Put1800 Nov'
        /// - full name 'TA9Z00960C'
        /// </summary>
        protected bool FindSecurity(string text, out int id)
        {
            id = 0;
            bool res = false;

            // get the list of securities
            int[] ids = marketSimulationMaof.GetSecurities();
            // my key is name of the option and my value is unique option Id (integer)
            // On TASE ID is an integer
            System.Collections.Generic.Dictionary <string, int> names = new System.Collections.Generic.Dictionary <string, int>(ids.Length);
            // i need an array (string) of IDs to look for patial integer IDs
            System.Text.StringBuilder idNames = new System.Text.StringBuilder(ids.Length * 10);
            // fill the dictionary and string of all IDs
            foreach (int i in ids)
            {
                MarketSimulationMaof.Option option = marketSimulationMaof.GetOption(i);
                string name = convertBnoName(option.GetName());
                if (name != null)
                {
                    names.Add(name, i);
                }
                idNames.Append(i); idNames.Append(" ");
            }
            string idNamesStr = idNames.ToString();

            // look in the command for regexp jan|feb)($| +)' first
            // Other possibilities are: ' +([0-9]+) *([c,p]) *(jan|feb)($| +)'
            // the final case is any set of digits ' +([0-9]+)($| +)'
            const string monthPattern   = "JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC";
            const string putcallPattern = "c|p|C|P|call|put|CALL|PUT|Call|Put]";
            const string pattern1       = " +(" + putcallPattern + ") *([0-9]+) *(" + monthPattern + ")($| +)";
            const string pattern2       = " +([0-9]+) *(" + putcallPattern + ") *(" + monthPattern + ")($| +)";
            const string pattern3       = " +([0-9]+)($| +)";

            System.Text.RegularExpressions.GroupCollection groups;
            int matchesCount;

            do
            {
                GetMatchGroups(pattern1, text, out groups, out matchesCount);
                if (matchesCount > 1)
                {
                    System.Console.WriteLine("I expect one and only one match for '" + pattern1 + "' instead of " + matchesCount);
                    break;
                }

                if (matchesCount == 1)
                {
                    string putcall = groups[1].Captures[0].ToString();                     // group[0] is reserved for the whole match
                    string strike  = groups[2].Captures[0].ToString();
                    string month   = groups[3].Captures[0].ToString();
                    res = FindSecurity(names, putcall, strike, month, out id);
                    break;
                }

                GetMatchGroups(pattern2, text, out groups, out matchesCount);
                if (matchesCount > 1)
                {
                    System.Console.WriteLine("I expect one and only one match for '" + pattern2 + "' instead of " + matchesCount);
                    break;
                }
                if (matchesCount == 1)
                {
                    string strike  = groups[2].Captures[0].ToString();                     // group[0] is reserved for the whole match
                    string putcall = groups[1].Captures[0].ToString();
                    string month   = groups[3].Captures[0].ToString();
                    res = FindSecurity(names, putcall, strike, month, out id);
                    break;
                }

                // finally i look just for any sequence of digits
                GetMatchGroups(pattern3, text, out groups, out matchesCount);
                if (matchesCount > 0)
                {
                    string digits      = groups[0].Captures[0].ToString();                // group[0] is reserved for the whole match
                    int    idxFirst    = idNamesStr.IndexOf(digits);                      // idNamesStr is a string containing all existing Ids followed by blank
                    int    idxSecond   = idNamesStr.LastIndexOf(digits);
                    string firstMatch  = idNamesStr.Substring(idxFirst, idNamesStr.IndexOf(" ", idxFirst + 1) - idxFirst);
                    string secondMatch = idNamesStr.Substring(idxSecond, idNamesStr.IndexOf(" ", idxSecond + 1) - idxSecond);
                    if (idxFirst != idxSecond)
                    {
                        System.Console.WriteLine("I have at least two matches '" + firstMatch + "' and '" + secondMatch + "'");
                        break;
                    }
                    // System.Console.WriteLine("firstMatch={0},secondMatch={1},digits={2}",firstMatch,secondMatch,digits);
                    // i got a single match - convert to ID
                    id  = Int32.Parse(firstMatch);
                    res = true;
                    break;
                }

                res = false;
            }while (false);


            return(res);
        }