public MarketData(commonClass.BaseAnalysisData data) { DateTime startDate = DateTime.Today, endDate = DateTime.Today; AppTypes.GetDate(data.DataTimeRange, out startDate, out endDate); this.Init(startDate, endDate, data.DataTimeScale, null); }
/// <summary> /// Constructors to create a market indicator's data for specific stock list /// </summary> /// <param name="timeRange"></param> /// <param name="timeScale"></param> /// <param name="stockCodes"></param> public MarketData(AppTypes.TimeRanges timeRange, AppTypes.TimeScale timeScale, StringCollection stockCodes) { DateTime startDate = DateTime.Today, endDate = DateTime.Today; AppTypes.GetDate(timeRange, out startDate, out endDate); this.Init(startDate, endDate, timeScale, stockCodes); }
public MarketData(commonClass.BaseAnalysisData data, StringCollection stockCodes) { DateTime startDate = DateTime.Today, endDate = DateTime.Today; AppTypes.GetDate(data.DataTimeRange, out startDate, out endDate); this.Init(startDate, endDate, data.DataTimeScale, stockCodes); }
/// <summary> /// Constructors to create a market indicator's data for all enable stock /// </summary> /// <param name="timeRange"></param> /// <param name="timeScale"></param> public MarketData(AppTypes.TimeRanges timeRange, AppTypes.TimeScale timeScale) { DateTime startDate = DateTime.Today, endDate = DateTime.Today; AppTypes.GetDate(timeRange, out startDate, out endDate); this.Init(startDate, endDate, timeScale, null); }
/// <summary> /// Load stock price data withd some point ahead of the specified date range /// </summary> /// <param name="stockCode"></param> /// <param name="frDate">Start date </param> /// <param name="toDate">End date</param> /// <param name="timeScale">Time scale</param> /// <param name="noUnitAhead">the number of units(minute,day,hour,week...) to read beyond the start time[frDate].</param> /// <param name="toTbl">Table keeps loaded data</param> /// <param name="startIdx">specify the row where the data in [frDate,toDate] range starts</param> public static void LoadAnalysisData(AnalysisData dataObj) { int startIdx = dataObj.priceDataTbl.Count; if (dataObj.DataTimeRange == AppTypes.TimeRanges.None) { dataObj.priceDataTbl.Clear(); databases.DbAccess.LoadData(dataObj.priceDataTbl, dataObj.DataTimeScale.Code, dataObj.DataStockCode, dataObj.DataMaxCount + constNumberOfReadAheadUnit); dataObj.FirstDataStartAt = 0; return; } int noUnitAhead = constNumberOfReadAheadUnit; DateTime toDate = common.Consts.constNullDate; DateTime frDate = common.Consts.constNullDate; if (!AppTypes.GetDate(dataObj.DataTimeRange, out frDate, out toDate)) { return; } databases.baseDS.priceDataStatDataTable priceStatTbl = databases.DbAccess.GetPriceDataStat(dataObj.DataTimeScale, dataObj.DataStockCode); if (priceStatTbl.Count == 0) { return; } DateTime dataMaxDateTime = priceStatTbl[0].maxDate; DateTime dataMinDateTime = priceStatTbl[0].minDate; int dataTotalCount = priceStatTbl[0].totalCount; if (toDate > dataMaxDateTime) { toDate = dataMaxDateTime; } if (frDate < dataMinDateTime) { frDate = dataMinDateTime; } dataObj.priceDataTbl.Clear(); if (noUnitAhead != 0) { // Find start date that return sufficient rows as required by [noBarAhead] DateTime checkFrDate = common.Consts.constNullDate; DateTime checkToDate = frDate.AddSeconds(-1); int totalGotRowCount = 0, gotRowCount; decimal rangeScale = 1; //int loopPass = 0; while (true) { //loopPass++; switch (dataObj.DataTimeScale.Type) { case AppTypes.TimeScaleTypes.Minnute: checkFrDate = checkToDate.AddMinutes(-(int)(noUnitAhead * rangeScale)); break; case AppTypes.TimeScaleTypes.Hour: checkFrDate = checkToDate.AddHours(-(int)(noUnitAhead * rangeScale)); break; case AppTypes.TimeScaleTypes.Day: checkFrDate = checkToDate.AddDays(-(int)(noUnitAhead * rangeScale)); break; case AppTypes.TimeScaleTypes.Week: checkFrDate = checkToDate.AddDays(-(int)(7 * noUnitAhead * rangeScale)); break; case AppTypes.TimeScaleTypes.Month: checkFrDate = checkToDate.AddMonths(-(int)(noUnitAhead * rangeScale)); break; case AppTypes.TimeScaleTypes.Year: checkFrDate = checkToDate.AddYears(-(int)(noUnitAhead * rangeScale)); break; case AppTypes.TimeScaleTypes.RealTime: //checkFrDate = checkToDate.AddMinutes(-(int)(commonClass.Settings.sysAutoRefreshInSeconds * noUnitAhead * rangeScale) / 60); checkFrDate = checkToDate.AddMinutes(-(int)(noUnitAhead * rangeScale)); break; default: common.system.ThrowException("Invalid parametter in calling to LoadStockPrice()"); break; } gotRowCount = databases.DbAccess.GetTotalPriceRow(dataObj.DataTimeScale, checkFrDate, checkToDate, dataObj.DataStockCode); //No more data ?? if (checkFrDate < dataMinDateTime) { break; } //Sufficient data ?? totalGotRowCount += gotRowCount; if (totalGotRowCount >= noUnitAhead) { break; } //No data load means the check range not big enough, increse rangeScale by 5 to make it larger scale if (gotRowCount == 0) { rangeScale += 5; } else { //Estimate the best range scale // Increase total left sligtly by 3% with the hope that it can take all need. // 5 and 3% had been tested indifferent cases and see that they are the best value. decimal tmpRangeScale = rangeScale * (decimal)(noUnitAhead - totalGotRowCount + noUnitAhead * 0.03) / gotRowCount; rangeScale = (tmpRangeScale > 0 ? tmpRangeScale : rangeScale + 5); } checkToDate = checkFrDate.AddSeconds(-1); } databases.DbAccess.LoadData(dataObj.priceDataTbl, dataObj.DataTimeScale.Code, checkFrDate, frDate.AddSeconds(-1), dataObj.DataStockCode); startIdx = dataObj.priceDataTbl.Count - startIdx; } databases.DbAccess.LoadData(dataObj.priceDataTbl, dataObj.DataTimeScale.Code, frDate, toDate, dataObj.DataStockCode); dataObj.FirstDataStartAt = startIdx; }