예제 #1
0
        internal void GenerateOHLCData(NStockSeries s, double dPrevClose, int historicalDays)
        {
            DateTime  now = DateTime.Now;
            NTimeline timeline = m_Calendar.CreateTimeline(new NDateTimeRange(now, now + new TimeSpan(360, 0, 0, 0, 0)));
            double    open, high, low, close;

            s.ClearDataPoints();

            int numberOfWorkingDays = historicalDays;

            if (ZoomModeDropDownList.SelectedIndex == 0)
            {
                numberOfWorkingDays += 7;
            }
            else
            {
                numberOfWorkingDays += 31;
            }

            for (; numberOfWorkingDays > 0; numberOfWorkingDays--)
            {
                open = dPrevClose;

                if (dPrevClose < 25 || Random.NextDouble() > 0.5)
                {
                    // upward price change
                    close = open + (2 + (Random.NextDouble() * 20));
                    high  = close + (Random.NextDouble() * 10);
                    low   = open - (Random.NextDouble() * 10);
                }
                else
                {
                    // downward price change
                    close = open - (2 + (Random.NextDouble() * 20));
                    high  = open + (Random.NextDouble() * 10);
                    low   = close - (Random.NextDouble() * 10);
                }

                if (low < 1)
                {
                    low = 1;
                }

                dPrevClose = close;

                s.OpenValues.Add(open);
                s.HighValues.Add(high);
                s.LowValues.Add(low);
                s.CloseValues.Add(close);
                s.XValues.Add(now.ToOADate());

                // advance to next working day
                now = timeline.AddTimeSpan(now, new NDateTimeSpan(1, NDateTimeUnit.Day));
            }
        }
예제 #2
0
        private void GenerateData(NStockSeries s, NWorkCalendar calendar, double dPrevClose, int nCount)
        {
            DateTime  now = DateTime.Now;
            NTimeline timeline = calendar.CreateTimeline(new NDateTimeRange(now, now + new TimeSpan(730, 0, 0, 0, 0)));
            double    open, high, low, close;

            s.ClearDataPoints();

            Random random = new Random();

            for (int nIndex = 0; nIndex < nCount; nIndex++)
            {
                open = dPrevClose;

                if (dPrevClose < 25 || random.NextDouble() > 0.5)
                {
                    // upward price change
                    close = open + (2 + (random.NextDouble() * 20));
                    high  = close + (random.NextDouble() * 10);
                    low   = open - (random.NextDouble() * 10);
                }
                else
                {
                    // downward price change
                    close = open - (2 + (random.NextDouble() * 20));
                    high  = open + (random.NextDouble() * 10);
                    low   = close - (random.NextDouble() * 10);
                }

                if (low < 1)
                {
                    low = 1;
                }

                dPrevClose = close;

                s.OpenValues.Add(open);
                s.HighValues.Add(high);
                s.LowValues.Add(low);
                s.CloseValues.Add(close);
                s.XValues.Add(now.ToOADate());

                // advance to next working day
                now = timeline.AddTimeSpan(now, new NDateTimeSpan(1, NDateTimeUnit.Day));
            }
        }