public static List<MarketData> FillByPivotData(MarketData pivotData, List<MarketData> inputData) { // pivotData의 datetime에 맞추어서 나머지 데이터를 채운다. DateTime curDateTime = pivotData.StartDate; List<MarketData> outputData = new List<MarketData>(); Dictionary<String, MarketDataTrace> trace = new Dictionary<string, MarketDataTrace>(); // init variables foreach (MarketData md in inputData) { String ticker = md.Ticker; DOHLC firstData = md.GetByIndex(0); trace.Add(md.Ticker, new MarketDataTrace(ticker, firstData)); outputData.Add(new MarketData(md)); } while (curDateTime <= pivotData.EndDate) { if (pivotData.IsExistDate(curDateTime)) { // update trace foreach (MarketData md in inputData) { String ticker = md.Ticker; if (md.IsExistDate(curDateTime)) { trace[ticker].CurData = md.GetData(curDateTime); } } // set data foreach (MarketData md in outputData) { String ticker = md.Ticker; MarketDataTrace tr = trace[ticker]; // 기준 데이터보다 전 데이터이어야 한다. Trace.Assert(tr.CurData.CurDate <= curDateTime, String.Format("{0}, {1}, {2}", tr.Ticker, tr.CurData.CurDate, curDateTime)); md.AddDatum(curDateTime, tr.CurData.OHLC); if (tr.CurData.CurDate != curDateTime) { md.SetPrevDataUsedDate(curDateTime); } } } curDateTime = curDateTime.AddDays(1); } return outputData; }
MarketData GetNewMarketData(DateTime startDate, DateTime endDate, MarketData md) { MarketData newMD = new MarketData(startDate, endDate, md.Ticker); DateTime curDate = startDate; while (curDate <= endDate) { if (md.IsExistDate(curDate)) { DOHLC dohlc = md.GetData(curDate); newMD.AddDatum(dohlc); } curDate = curDate.AddDays(1); } return newMD; }
void UpdatePrevDataGridView_Raw(MarketData md) { DateTime curDate = md.StartDate; String ticker = md.Ticker; String desc = TickerNameMap.Ins().GetDesc(ticker); while (curDate <= md.EndDate) { if (md.IsExistDate(curDate)) { DOHLC datum = md.GetData(curDate); double value = datum.OHLC.Close; int index = dataGridView1.Rows.Add(); dataGridView1.Rows[index].Cells[0].Value = curDate.ToString("yyyy-MM-dd"); dataGridView1.Rows[index].Cells[1].Value = ticker; dataGridView1.Rows[index].Cells[2].Value = desc; dataGridView1.Rows[index].Cells[3].Value = value; } curDate = curDate.AddDays(1); } }
public static DateTime GetPivotTradingDate(int pivot, DateTime curDate, MarketData pivotData) { DateTime pivotDate = curDate; while (pivot > 0) { pivotDate = pivotDate.AddDays(1); if (pivotData.IsExistDate(pivotDate)) { pivot--; } } while (pivot < 0) { pivotDate = pivotDate.AddDays(-1); if (pivotData.IsExistDate(pivotDate)) { pivot++; } } return pivotDate; }
/** * Target Date가 비거래일이면, 직전 거래일을 반환한다. * */ public static DateTime GetLastTradingDay(MarketData mdPivot, DateTime targetDate) { if (mdPivot == null || mdPivot.GetByIndex(0).CurDate >= targetDate) { if (targetDate.DayOfWeek == DayOfWeek.Sunday) { return targetDate.AddDays(-2); } if (targetDate.DayOfWeek == DayOfWeek.Saturday) { return targetDate.AddDays(-1); } return targetDate; } DateTime tradingDate = targetDate; while (true) { if (mdPivot.IsExistDate(tradingDate)) { break; } tradingDate = tradingDate.AddDays(-1); } return tradingDate; }