public MarketDataSet GetMarketDataSet() { if (_marketData == null) { LoadPrevMarketData(); } if (_bMerged) { logger.Warn("Already merged..."); return _marketData; } if (_curData == null) { logger.Info("curData not set...."); return _marketData; } _bMerged = true; this.InputData.EndDate = DataUtil.GetDateWithDayPrecision(DateTime.Now); foreach (String ticker in Tickers) { MarketDataSetKey key = MarketDataSetKeyManager.Ins().GetKey(ticker); MarketData md = this._marketData.GetData(key); double value = _curData[ticker]; DateTime today = DataUtil.GetDateWithDayPrecision(DateTime.Now); DOHLC datum = new DOHLC(today, new OHLC(0, 0, 0, value)); md.AddDatum(datum); } return this._marketData; }
public AdjRateDatum CalculateAssetWeight_Raw(OperationSet opSet, DateTime targetDate, MarketDataSet data) { MarketData md = data.GetData(MarketDataSetKey.BokRate); DOHLC dohlc = md.GetData(targetDate); AdjRateDatum ret = null; if (_prevMarketData == null) { ret = new AdjRateDatum(1, 1, 1); } else { double prevValue = _prevMarketData.OHLC.Close; double curValue = dohlc.OHLC.Close; // changed more than 1 bp if (Math.Abs(prevValue - curValue) > 0.01) { double increment = curValue / prevValue - 1; // 금리 변동이 있다. BokRateEvent ev = new BokRateEvent(); ev.TargetIncrement = increment; ev.StartDate = targetDate; ev.EndDate = targetDate.AddYears(kEventDuration); ev.EventKey = _eventKeyGenerator++; ev.UpDown = increment > 0 ? UpDown.Up : UpDown.Down; _events.Add(ev); _lastEvent = ev; } ret = GetIncrement(targetDate); } _prevMarketData = dohlc; return ret; }
public MarketDataTrace(String ticker, DOHLC data) { this.Ticker = ticker; this.CurData = data; }
public void AddDatum(DateTime dt, OHLC ohlc) { DOHLC dohlc = new DOHLC(dt, ohlc); _data.Add(dohlc); _dateDict.Add(dohlc.CurDate, dohlc); }
public void AddDatum(DOHLC dohlc) { _data.Add(dohlc); _dateDict.Add(dohlc.CurDate, dohlc); }
public void LoadDataFromDB() { DBManager dbManager = new DBManager(); MySqlConnection con = null; try { String ip = Config.DB_SERVER_IP; con = dbManager.CreateConnection(ip, Config.DATABASE_CORREL); con.Open(); String query = String.Format( "select * from raw_price_data where Ticker = '{0}' and datetime >= '{1}' and datetime <= '{2}' order by DateTime", this.Ticker, this.StartDate.ToString("yyyy-MM-dd"), this.EndDate.ToString("yyyy-MM-dd")); MySqlCommand cmd = new MySqlCommand(query, con); MySqlDataAdapter dataAdapter = new MySqlDataAdapter(cmd); DataSet ds = new DataSet("raw_price_data"); dataAdapter.Fill(ds, "raw_price_data"); DataRowCollection drc = ds.Tables["raw_price_data"].Rows; double prevOpen = 0; double prevHigh = 0; double prevLow = 0; double prevClose = 0; for (int i = 0; i < drc.Count; ++i) { DataRow dr = drc[i]; String ticker = dr["Ticker"].ToString(); DateTime curDate = Convert.ToDateTime(dr["DateTime"]); double open = Convert.ToDouble(dr["Open"]); double high = Convert.ToDouble(dr["High"]); double low = Convert.ToDouble(dr["Low"]); double close = Convert.ToDouble(dr["LastPrice"]); // 주말 데이터가 들어오면 이상 데이터로 간주. 제외한다. if (curDate.DayOfWeek == DayOfWeek.Saturday || curDate.DayOfWeek == DayOfWeek.Sunday) { continue; } // 임시: 코스피 선물 데이터의 경우시고저종 값이 모두 같으면 이상 데이터로 간주. 제외한다. if ("KM1 R:00_0_R Index".CompareTo(ticker) == 0 && open == prevOpen && high == prevHigh && low == prevLow && close == prevClose) { continue; } OHLC ohlc = new OHLC(open, high, low, close); DOHLC dolhc = new DOHLC(curDate, ohlc); this._data.Add(dolhc); this._dateDict.Add(curDate, dolhc); prevOpen = open; prevHigh = high; prevLow = low; prevClose = close; } ds.Clear(); logger.Debug("{0} data load complete.", this.Ticker); } catch (System.Exception e) { logger.Error(e.ToString()); } finally { dbManager.Close(con); } }
// market data format // 2011-06-01 273.5 DOHLC ParseLine(String line, String ticker, DateTime startDateTime, DateTime endDateTime) { StringPacket data = new StringPacket(line); String dateString = data.Decode(); // 날짜 dateString.Replace("/", "-"); double value = Convert.ToDouble(data.Decode()); // 가격 DateTime date = DateTime.MaxValue; if (DateTime.TryParseExact( dateString, "yyyy-MM-dd", null, System.Globalization.DateTimeStyles.None, out date)) { } else if (DateTime.TryParseExact( dateString, "yyyy-MM-dd HH:mm", null, System.Globalization.DateTimeStyles.None, out date)) { } else if (DateTime.TryParseExact( dateString, "yyyy-MM", null, System.Globalization.DateTimeStyles.None, out date)) { //월데이터가 들어가면 해당 월 말일 오전 12:00로 세팅함. date = date.AddMonths(1).AddDays(-1); } if (!DeltaVolUtil.IsInValidDateTimeRange(date, startDateTime, endDateTime)) { return null; } OHLC ohlc = new OHLC(0, 0, 0, value); DOHLC datum = new DOHLC(date, ohlc); return datum; }