private bool IsDateRow(string line) { if (string.IsNullOrEmpty(line)) { return(false); } // ожидается строка вида //PG39 BULLETIN # 41@ EURO FX & CME$INDEX OPTIONS Wed, Mar 02, 2011 PG39 //PG38 AUSTRALIAN DOLLAR AND NEW ZEALAND DOLLAR OPTIONS Thu, Aug 26, 2010 PG38 line = line.Trim(' ', (char)9); var preffix = string.Format("PG{0}", SectionNum); if (!line.StartsWith(preffix)) { return(false); } if (!line.EndsWith(preffix)) { return(false); } var parts = line.Split(new[] { ' ', (char)9 }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length < 9) { return(false); } var month = ExpirationMonth.ParseMonth(parts[parts.Length - 4], true); // Mar if (month <= 0) { return(false); } var dayStr = parts[parts.Length - 3].TrimEnd(','); // Mar int day, year; if (!int.TryParse(dayStr, out day)) { return(false); } var yearStr = parts[parts.Length - 2]; if (!int.TryParse(yearStr, out year)) { return(false); } DocumentDate = new DateTime(year, month, day); return(true); }
private News MakeOptionLevelNews(DateTime curDate, string curSymbol, ExpirationMonth expMonth, OptionStyle optStyle, OptionType optType, decimal strike, int volume, int OI, decimal closeRange, decimal openRange, decimal high, decimal low, decimal delta, decimal settPrice) { //[#fmt]#&newstype=option#&type=Call#&style=American#&baseactive=EURUSD#& //publishdate=09.03.2011 02:34:00#&dateexpiration=11.06.2011#&strikeprice=1.4550#& //high=0.0140#&low=0.0090#&close=0.0110#&oi=948#&volume=0 var newsBody = string.Format(CultureProvider.Common, "[#fmt]#&newstype=option#&type={0}#&style={1}#&baseactive={2}#&" + "publishdate={3:dd.MM.yyyy HH:mm:ss}#&dateexpiration={4:dd.MM.yyyy}#&strikeprice={5}#&" + "high={6}#&low={7}#&close={8}#&oi={9}#&volume={10}", optType, optStyle, curSymbol, curDate, new DateTime(expMonth.Year, expMonth.Month, 11), strike, high, low, closeRange, OI, volume); return(new News(newsChannelId, curDate, titleNewsOption, newsBody)); }
private int MakeOptionLevels() { var tmpFolderPath = string.Format("{0}\\{1}", ExecutablePath.ExecPath, FolderTemp); var newsList = new List <News>(); foreach (var fileName in Directory.GetFiles(tmpFolderPath, "*.xls")) { // ожидаем записи вида // BULLETIN 29 17.08.2010 // LEGEND:strike volume OI ClosRange OpRange High Low Delta SettPrice // TABLE USDJPY SEP10 CALL American 100000 10000 1 // 920 8 3,81 0,971 4,85 DateTime? curDate = null; string curSymbol = null; var optType = OptionType.CALL; var optStyle = OptionStyle.American; ExpirationMonth month = null; decimal strikeToBase = 1, premiumToBase = 1; var invertRate = false; using (var sr = new StreamReader(fileName, Encoding.Unicode)) { while (!sr.EndOfStream) { var line = sr.ReadLine(); if (string.IsNullOrEmpty(line)) { continue; } if (line.StartsWith("LEGEND")) { continue; } var parts = line.Split(new[] { ' ', (char)9 }, StringSplitOptions.None); if (parts[0] == "TABLE") { // получить текущие актив, дату экспирации, тип и стиль опциона curSymbol = parts[1]; month = ExpirationMonth.Parse(parts[2]); optType = (OptionType)Enum.Parse(typeof(OptionType), parts[3]); optStyle = (OptionStyle)Enum.Parse(typeof(OptionStyle), parts[4]); strikeToBase = parts[5].Replace(',', '.').ToDecimalUniform(); premiumToBase = parts[6].Replace(',', '.').ToDecimalUniform(); invertRate = parts[7] == "1" ? true : false; continue; } if (parts[0] == "BULLETIN") { // получить дату бюллетеня curDate = DateTime.ParseExact(parts[2], "dd.MM.yyyy", CultureProvider.Common); continue; } // получить текущие данные: // strike volume OI ClosRange OpRange High Low Delta SettPrice var strike = parts[0].Replace(',', '.').ToDecimalUniformSafe(); var volume = string.IsNullOrEmpty(parts[1]) ? 0 : parts[1].ToInt(); var OI = string.IsNullOrEmpty(parts[2]) ? 0 : parts[2].ToInt(); var closeRange = parts[3].Replace(',', '.').ToDecimalUniformSafe(); var openRange = parts[4].Replace(',', '.').ToDecimalUniformSafe(); var high = parts[5].Replace(',', '.').ToDecimalUniformSafe(); var low = parts[6].Replace(',', '.').ToDecimalUniformSafe(); var delta = parts[7].Replace(',', '.').ToDecimalUniformSafe(); var settPrice = parts[8].Replace(',', '.').ToDecimalUniformSafe(); // привести все цены к ценам БА strike = strike / strikeToBase; closeRange = closeRange.HasValue ? closeRange / premiumToBase : 0; openRange = openRange.HasValue ? openRange / premiumToBase : 0; high = high.HasValue ? high / premiumToBase : 0; low = low.HasValue ? low / premiumToBase : 0; delta = delta.HasValue ? delta / premiumToBase : 0; settPrice = settPrice.HasValue ? settPrice / premiumToBase : 0; if (curDate.HasValue && (!string.IsNullOrEmpty(curSymbol)) && month != null) { if (OI >= minOi && volume >= minVolume) { if (invertRate) { if (optType == OptionType.CALL) { optType = OptionType.PUT; high = high.HasValue ? 1 / strike - 1 / (strike + high.Value) : 0; low = low.HasValue ? 1 / strike - 1 / (strike + low.Value) : 0; delta = delta.HasValue ? 1 / strike - 1 / (strike + delta.Value) : 0; closeRange = closeRange.HasValue ? 1 / strike - 1 / (strike + closeRange.Value) : 0; openRange = openRange.HasValue ? 1 / strike - 1 / (strike + openRange.Value) : 0; settPrice = settPrice.HasValue ? 1 / strike - 1 / (strike + settPrice.Value) : 0; } else { optType = OptionType.CALL; high = high.HasValue ? 1 / (strike - high.Value) - 1 / strike : 0; low = low.HasValue ? 1 / (strike - low.Value) - 1 / strike : 0; delta = delta.HasValue ? 1 / (strike - delta.Value) - 1 / strike : 0; closeRange = closeRange.HasValue ? 1 / (strike - closeRange.Value) - 1 / strike : 0; openRange = openRange.HasValue ? 1 / (strike - openRange.Value) - 1 / strike : 0; settPrice = settPrice.HasValue ? 1 / (strike - settPrice.Value) - 1 / strike : 0; } strike = 1 / strike; } var news = MakeOptionLevelNews(curDate.Value, curSymbol, month, optStyle, optType, strike.Value, volume, OI, closeRange.Value, openRange.Value, high.Value, low.Value, delta.Value, settPrice.Value); newsList.Add(news); } } } // while ! EOS } // using (var sr = } // foreach (var fileName // отправить каждую новость провайдеру return(SendNewsToProvider(newsList)); }
private News MakeOptionLevelNews(DateTime curDate, string curSymbol, ExpirationMonth expMonth, OptionStyle optStyle, OptionType optType, decimal strike, int volume, int OI, decimal closeRange, decimal openRange, decimal high, decimal low, decimal delta, decimal settPrice) { //[#fmt]#&newstype=option#&type=Call#&style=American#&baseactive=EURUSD#& //publishdate=09.03.2011 02:34:00#&dateexpiration=11.06.2011#&strikeprice=1.4550#& //high=0.0140#&low=0.0090#&close=0.0110#&oi=948#&volume=0 var newsBody = string.Format(CultureProvider.Common, "[#fmt]#&newstype=option#&type={0}#&style={1}#&baseactive={2}#&" + "publishdate={3:dd.MM.yyyy HH:mm:ss}#&dateexpiration={4:dd.MM.yyyy}#&strikeprice={5}#&" + "high={6}#&low={7}#&close={8}#&oi={9}#&volume={10}", optType, optStyle, curSymbol, curDate, new DateTime(expMonth.Year, expMonth.Month, 11), strike, high, low, closeRange, OI, volume); return new News(newsChannelId, curDate, titleNewsOption, newsBody); }
private bool ParseTxtDocument(string fileName, CMETickerInfoCollection bulletinInfo) { // получить секцию из имени файла int sectionNum; if (!GetSectionNumFromFileName(fileName, out sectionNum)) { return(false); } SectionNum = sectionNum.ToString(); // получить набор таблиц (экспирация - опцион - тип опциона) CMEBulletinTable curTable = null; bool docDateParsed = false; CMETickerInfo curTicker = null; CMEBulletinReference curTickerRef = null; using (var sr = new StreamReader(fileName, Encoding.Unicode)) { while (!sr.EndOfStream) { // парсинг даты var line = sr.ReadLine(); try { if (!docDateParsed) { docDateParsed = IsDateRow(line); continue; } // строка содержит месяц экспирации? line = line.Trim(' ', (char)9); var parts = line.Split(new[] { ' ', (char)9 }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 0) { continue; } var em = ExpirationMonth.Parse(parts[0]); if (em != null) { if (curTicker != null && curTickerRef != null) { // создать таблицу if (curTable != null) { tables.Add(curTable); } curTable = new CMEBulletinTable { ExpMonth = em, OptStyle = curTickerRef.OptionStyle, OptType = curTickerRef.OptionType, SpotSymbol = curTicker.SpotSymbol, StrikeToBaseRatio = curTicker.StrikeToBaseRatio, PremiumToBaseRatio = curTicker.PremiumToBaseRatio, InvertRate = curTicker.InvertRate }; } continue; } // строка содержит заголовок? // EURO FX C (EU) // BRIT PND-P EU CMETickerInfo tick; CMEBulletinReference tickRef; if (bulletinInfo.FindTicker(parts, out tick, out tickRef, SectionNum)) { if (futuresInfo != null) { if (futuresInfo.Ticker == null) { futuresInfo.Ticker = tick; } } curTicker = tick; curTickerRef = tickRef; continue; } var row = CMEBulletinTableRow.ParseLine(line); if (row != null && curTable != null) { curTable.rows.Add(row); } if (row == null) // строка содержит данные по фьючам? { var summ = CheckFutureInfoLine(parts); if (summ != null) { futuresInfo = summ; } } } catch (Exception ex) { Logger.ErrorFormat("CMEDocumentParser.ParseTxtDocument parse line: \"{0}\", line:[{1}]", ex.Message, line); } } } try { CMEBulletinTable.MergeSameTables(tables); } catch (Exception ex) { Logger.Error("CMEDocumentParser.ParseTxtDocument MergeSameTables", ex); } return(true); }