RandomDataManager.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. namespace Easychart.Finance.DataProvider
  2. {
  3. using Easychart.Finance;
  4. using System;
  5. public class RandomDataManager : CacheDataManagerBase
  6. {
  7. private int MaxCount;
  8. public RandomDataManager() : this(false)
  9. {
  10. }
  11. public RandomDataManager(ExchangeIntraday ei) : this(ei, 0x3e8)
  12. {
  13. }
  14. public RandomDataManager(bool Intraday) : this(Intraday, 0x3e8)
  15. {
  16. }
  17. public RandomDataManager(ExchangeIntraday ei, int MaxCount)
  18. {
  19. base.IntradayInfo = ei;
  20. this.MaxCount = MaxCount;
  21. }
  22. public RandomDataManager(bool Intraday, int MaxCount) : this((ExchangeIntraday) null, MaxCount)
  23. {
  24. if (Intraday)
  25. {
  26. base.IntradayInfo = ExchangeIntraday.US;
  27. }
  28. }
  29. public override IDataProvider GetData(string Code, int Count)
  30. {
  31. CommonDataProvider provider = new CommonDataProvider(this);
  32. if (Code == null)
  33. {
  34. Code = "MSFT";
  35. }
  36. Random random = new Random(Code.GetHashCode());
  37. double[][] ds = new double[6][];
  38. double[] minuteDate = null;
  39. if (base.IntradayInfo != null)
  40. {
  41. minuteDate = base.IntradayInfo.GetMinuteDate(DateTime.Today.AddDays(-7.0), DateTime.Today);
  42. this.MaxCount = minuteDate.Length;
  43. }
  44. for (int i = 0; i < ds.Length; i++)
  45. {
  46. ds[i] = new double[this.MaxCount];
  47. }
  48. for (int j = 0; j < this.MaxCount; j++)
  49. {
  50. if (j == 0)
  51. {
  52. ds[0][j] = 20.0;
  53. ds[3][j] = 21.0;
  54. ds[4][j] = 100000.0;
  55. }
  56. else
  57. {
  58. ds[0][j] = Math.Round((double) ((ds[0][j - 1] + random.NextDouble()) - 0.48), 2);
  59. ds[3][j] = Math.Round((double) ((ds[0][j - 1] + random.NextDouble()) - 0.48), 2);
  60. ds[4][j] = Math.Round(Math.Abs((double) ((ds[4][j - 1] + random.Next(0x186a0)) - 50000.0)), 2);
  61. }
  62. ds[1][j] = Math.Round((double) (Math.Max(ds[0][j], ds[3][j]) + random.NextDouble()), 2);
  63. ds[2][j] = Math.Round((double) (Math.Min(ds[0][j], ds[3][j]) - random.NextDouble()), 2);
  64. if (base.IntradayInfo != null)
  65. {
  66. ds[5][j] = minuteDate[j];
  67. }
  68. else
  69. {
  70. ds[5][j] = DateTime.Today.AddDays((double) (j - this.MaxCount)).ToOADate();
  71. }
  72. }
  73. provider.LoadBinary(ds);
  74. provider.SetStringData("Code", Code);
  75. return provider;
  76. }
  77. }
  78. }