public static void Tick(MarketVolatility mv, List <Stock> stocks)//Runs one iteration of the market simulator
        {
            Random rand      = new Random();
            Random operation = new Random();
            int    min       = 1;
            int    max       = 4;

            if (mv == MarketVolatility.High)
            {
                min = 3;
                max = 15;
            }
            else if (mv == MarketVolatility.Medium)
            {
                min = 2;
                max = 8;
            }
            foreach (Stock s in stocks)
            {
                int num = rand.Next(min, max);
                int op  = operation.Next(0, 2);//Determines if the stock is going up or down.
                if (op == 0)
                {
                    num = -num;
                }
                s.PreviousPrice = s.StockPrice;
                s.StockPrice    = (double)Math.Round(s.StockPrice * (num / 100.0f + 1.0f), 2);
            }
        }
Пример #2
0
        /// <summary>
        /// Runs a simulation of an active market based on user input
        /// </summary>
        private static void Simulator()
        {
            string input = "";

            while (input != "H" && input != "M" && input != "L" && input != "X")
            {
                Console.Write("Please enter a market volatility (H)igh, (M)edium, or (L)ow or press X to go back to the main menu: ");
                input = Console.ReadLine().ToUpper();
            }
            switch (input)
            {
            case "H":
                volatility = MarketVolatility.High;
                break;

            case "M":
                volatility = MarketVolatility.Medium;
                break;

            case "L":
                volatility = MarketVolatility.Low;
                break;

            case "X":
                return;
            }
            account.NextPeriod();
            MarketSimulator.Tick(volatility, stocks);
        }