Exemplo n.º 1
0
        public StockInfoHeader GetAll(string stSymbol, int date)
        {
            StockInfoHeader sth;
            StockInfoHeader[] headers;

            sth = new StockInfoHeader();

            ValidateStatus();

            if (dictStockPrices.ContainsKey(stSymbol) && !(date < 0 || date >= NUM_DAYS))
            {
                headers = dictStockPrices[stSymbol];
                sth = headers[date];
            }

            return sth;
        }
Exemplo n.º 2
0
        // Somewhat arbitrarily generates fake stock data.  Makes minor attempts to ensure "believability"
        // in that the stock will behave somehwat normally.  To generate a day of data it takes into account
        // the previous day and ensures there are no extrememe outliers.  It is still entirely possible to
        // have 50 days in a row of increases, but very unlikely

        private static void RefreshStockPrices(string stSymbol)
        {
            StockInfoHeader[] newPrices = new StockInfoHeader[NUM_DAYS];
            StockInfoHeader   stihlp;
            double            dlow, dhigh, dopen, dclose, dtc;

            if (dictStockPrices.ContainsKey(stSymbol))
            {
                dictStockPrices.Remove(stSymbol);
            }

            dlow   = r.NextDouble() * 50.0 + 25.0;
            dhigh  = dlow + r.NextDouble() * 10.0 + 2.5;
            dopen  = dlow + r.NextDouble() * (dhigh - dlow);
            dclose = dhigh - r.NextDouble() * (dhigh - dlow);
            dtc    = 0;

            for (int i = 0; i < NUM_DAYS; i++)
            {
                stihlp       = new StockInfoHeader(dopen, dclose, dlow, dhigh);
                newPrices[i] = stihlp;

                dopen  = stihlp.close + (stihlp.close - stihlp.open) * (0.5 + r.NextDouble()) * 0.25 + (r.NextDouble() - 0.5) * 10;
                dclose = dopen + (stihlp.close - stihlp.open) * (0.5 + r.NextDouble()) * 0.255 + (r.NextDouble() - 0.5) * 10;

                if (dopen < 10)
                {
                    dopen = r.NextDouble() * 5 + 10;
                }
                if (dclose < 10)
                {
                    dclose = r.NextDouble() * 5 + 10;
                }

                double dtlow, dthigh;
                dtlow  = dclose < dopen ? dclose : dopen;
                dthigh = dclose < dopen ? dopen : dclose;

                dlow  = dtlow - Math.Pow(r.NextDouble(), 2) * 10;
                dhigh = dthigh + Math.Pow(r.NextDouble(), 2) * 10;

                dtc += dclose - stihlp.close;
            }
            dictStockPrices[stSymbol] = newPrices;
        }
Exemplo n.º 3
0
        public StockInfoHeader GetAll(string stSymbol, int date)
        {
            StockInfoHeader sth;

            StockInfoHeader[] headers;

            sth = new StockInfoHeader();

            ValidateStatus();

            if (dictStockPrices.ContainsKey(stSymbol) && !(date < 0 || date >= NUM_DAYS))
            {
                headers = dictStockPrices[stSymbol];
                sth     = headers[date];
            }

            return(sth);
        }
Exemplo n.º 4
0
        // Somewhat arbitrarily generates fake stock data.  Makes minor attempts to ensure "believability"
        // in that the stock will behave somehwat normally.  To generate a day of data it takes into account
        // the previous day and ensures there are no extrememe outliers.  It is still entirely possible to
        // have 50 days in a row of increases, but very unlikely
        private static void RefreshStockPrices(string stSymbol)
        {
            StockInfoHeader[] newPrices = new StockInfoHeader[NUM_DAYS];
            StockInfoHeader stihlp;
            double dlow, dhigh, dopen, dclose, dtc;

            if (dictStockPrices.ContainsKey(stSymbol))
            {
                dictStockPrices.Remove(stSymbol);
            }

            dlow = r.NextDouble() * 50.0 + 25.0;
            dhigh = dlow + r.NextDouble() * 10.0 + 2.5;
            dopen = dlow + r.NextDouble() * (dhigh - dlow);
            dclose = dhigh - r.NextDouble() * (dhigh - dlow);
            dtc = 0;

            for (int i = 0; i < NUM_DAYS; i++)
            {
                stihlp = new StockInfoHeader(dopen, dclose, dlow, dhigh);
                newPrices[i] = stihlp;

                dopen = stihlp.close + (stihlp.close - stihlp.open) * (0.5 + r.NextDouble()) * 0.25 + (r.NextDouble() - 0.5) * 10;
                dclose = dopen + (stihlp.close - stihlp.open) * (0.5 + r.NextDouble()) * 0.255 + (r.NextDouble() - 0.5) * 10;

                if (dopen < 10)
                    dopen = r.NextDouble() * 5 + 10;
                if (dclose < 10)
                    dclose = r.NextDouble() * 5 + 10;

                double dtlow, dthigh;
                dtlow = dclose < dopen ? dclose : dopen;
                dthigh = dclose < dopen ? dopen : dclose;

                dlow = dtlow - Math.Pow(r.NextDouble(), 2) * 10;
                dhigh = dthigh + Math.Pow(r.NextDouble(), 2) * 10;

                dtc += dclose - stihlp.close;
            }
            dictStockPrices[stSymbol] = newPrices;
        }