namespace IndexFormula.Finance.DataProvider { using IndexFormula.Finance; using System; public class RandomDataManager : CacheDataManagerBase { private int MaxCount; public RandomDataManager() : this(false) { } public RandomDataManager(ExchangeIntraday ei) : this(ei, 0x3e8) { } public RandomDataManager(bool Intraday) : this(Intraday, 0x3e8) { } public RandomDataManager(ExchangeIntraday ei, int MaxCount) { base.IntradayInfo = ei; this.MaxCount = MaxCount; } public RandomDataManager(bool Intraday, int MaxCount) : this((ExchangeIntraday) null, MaxCount) { if (Intraday) { base.IntradayInfo = ExchangeIntraday.US; } } public override IDataProvider GetData(string Code, int Count) { CommonDataProvider provider = new CommonDataProvider(this); if (Code == null) { Code = "MSFT"; } Random random = new Random(Code.GetHashCode()); double[][] ds = new double[6][]; double[] minuteDate = null; if (base.IntradayInfo != null) { minuteDate = base.IntradayInfo.GetMinuteDate(DateTime.Today.AddDays(-7.0), DateTime.Today); this.MaxCount = minuteDate.Length; } for (int i = 0; i < ds.Length; i++) { ds[i] = new double[this.MaxCount]; } for (int j = 0; j < this.MaxCount; j++) { if (j == 0) { ds[0][j] = 20.0; ds[3][j] = 21.0; ds[4][j] = 100000.0; } else { ds[0][j] = Math.Round((double) ((ds[0][j - 1] + random.NextDouble()) - 0.48), 2); ds[3][j] = Math.Round((double) ((ds[0][j - 1] + random.NextDouble()) - 0.48), 2); ds[4][j] = Math.Round(Math.Abs((double) ((ds[4][j - 1] + random.Next(0x186a0)) - 50000.0)), 2); } ds[1][j] = Math.Round((double) (Math.Max(ds[0][j], ds[3][j]) + random.NextDouble()), 2); ds[2][j] = Math.Round((double) (Math.Min(ds[0][j], ds[3][j]) - random.NextDouble()), 2); if (base.IntradayInfo != null) { ds[5][j] = minuteDate[j]; } else { ds[5][j] = DateTime.Today.AddDays((double) (j - this.MaxCount)).ToOADate(); } } provider.LoadBinary(ds); provider.SetStringData("Code", Code); return provider; } } }