public override void FillData(string data) { string[] tempContainer = data.Split('\n'); string[] tempSplit; string tempFinder = string.Empty; string tempSecurityName = string.Empty; string tempMaturityDate = string.Empty; double tempMultiplier = 0; int dateTimeIndex = 0; DateTime tempContentDate; Texts = tempContainer.ToList(); lookup.LoadLookUpTables(); aqrIDLookUp.LoadLookUpTables(); for (int i = 0; i < Texts.Count; i++) { if (DateTime.TryParse(Texts[i], out tempContentDate)) { dateTimeIndex = i > 0 ? i : 0; ContentDate = tempContentDate; break; } } // COUNTERPARTY - HARDCODED FOR NOW CounterParty = "JPM"; // FUND is the line after the letter date Fund = Texts[dateTimeIndex + 1]; Fund = lookup.GetFundShortName(Fund); try { // CP REF tempFinder = Texts.Where(x => x.Contains(JPM_CPREF_REFERENCE)).FirstOrDefault(); if (!string.IsNullOrEmpty(tempFinder)) { tempSplit = tempFinder.Split(':'); CPRef = tempSplit.Last().Trim(); } // FUND //tempFinder = Texts.Where(x => x.Contains(FUND_REFERENCE)).FirstOrDefault(); //if (!string.IsNullOrEmpty(tempFinder)) //{ // tempSplit = tempFinder.Split(':'); // Fund = tempSplit.Last(); //} // TRANSACTION TYPE TransactionType = "Open"; // always open // SECURITY NAME // Dropdown (Index: Swiss market Index) We determine the date based on the Valuation date which is also available in the General Terms under Valuation Date at the end of the paragraph, page 2. // TRADE DATE tempFinder = Texts.Where(x => x.Contains(JPM_TRADE_DATE_REFERENCE)).FirstOrDefault(); if (!string.IsNullOrEmpty(tempFinder)) { tempSplit = tempFinder.Split(':'); TradeDate = DateTime.Parse(tempSplit.Last()); } // SETTLEMENT DATE int daysToAdd = 0; SettlementDate = TradeDate; while (daysToAdd < 3) { SettlementDate = SettlementDate.AddDays(1); if (SettlementDate.DayOfWeek != DayOfWeek.Saturday && SettlementDate.DayOfWeek != DayOfWeek.Sunday) { daysToAdd++; } } //SettlementDate = TradeDate.AddDays(3); //if (SettlementDate.DayOfWeek == DayOfWeek.Sunday || SettlementDate.DayOfWeek == DayOfWeek.Saturday) //{ // while (SettlementDate.DayOfWeek == DayOfWeek.Saturday || SettlementDate.DayOfWeek == DayOfWeek.Sunday) // { // SettlementDate = SettlementDate.AddDays(1); // } //} // MATURITY DATE // Valuation date - at the end of the paragraph with this format : 19 December 2014 // TERMINATION DATE tempFinder = Texts.Where(x => x.Contains(TERMINATION_DATE_REFERENCE)).FirstOrDefault(); if (!string.IsNullOrEmpty(tempFinder)) { tempSplit = tempFinder.Split(':'); if (string.Compare(tempSplit.Last(), JPM_TERMINATION_DATE_CASH_SETTLEMENT_PAYMENT_DATE_REFERENCE) == 0) { MaturityDate = SettlementDate; } else { MaturityDate = DateTime.Parse(tempSplit.Last()); } } // MULTIPLIER tempFinder = Texts.Where(x => x.Contains(JPM_MULTIPLIER_REFERENCE)).FirstOrDefault(); if (!string.IsNullOrEmpty(tempFinder)) { if (tempFinder.ToLower().Contains("deal")) { tempFinder = tempFinder.ToLower().Split(new string[] { "deal" }, StringSplitOptions.RemoveEmptyEntries).First(); } tempSplit = tempFinder.Split(':'); double.TryParse(tempSplit.Last(), out tempMultiplier); Multiplier = tempMultiplier; } //lookup.GetMultiplier(tempFund); // PRICE try { tempFinder = Texts.Where(x => x.Contains(JPM_FORWARD_PRICE)).FirstOrDefault(); if (!string.IsNullOrEmpty(tempFinder)) { tempSplit = tempFinder.Split(':'); string[] priceSplit = tempSplit[1].Split(' '); string price = string.Empty; if (!string.IsNullOrEmpty(priceSplit.First())) { price = priceSplit.First().Split(new string[] { "Deal" }, StringSplitOptions.RemoveEmptyEntries).First(); } else { price = priceSplit[1].Split(new string[] { "Deal" }, StringSplitOptions.RemoveEmptyEntries).First(); } Price = Double.Parse(price); } else { // Initial price tempFinder = Texts.Where(x => x.Contains(JPM_HANGSENG_INITIAL_PRICE)).FirstOrDefault(); if (!string.IsNullOrEmpty(tempFinder)) { tempSplit = tempFinder.Split(':'); string[] priceSplit = tempSplit[1].Split(' '); //string price = string.Empty; //if (!string.IsNullOrEmpty(priceSplit.First())) //{ // price = priceSplit.First().Split(new string[] { "Deal" }, StringSplitOptions.RemoveEmptyEntries).First(); //} //else //{ // price = priceSplit[1].Split(new string[] { "Deal" }, StringSplitOptions.RemoveEmptyEntries).First(); //} double price_temp = 0; foreach (string tempPrice in priceSplit) { double.TryParse(tempPrice, out price_temp); if (price_temp > 0) { break; } } Price = price_temp; //Price = Double.Parse(price); } } } finally { } // LOCAL CURRENCY tempFinder = Texts.Where(x => x.Trim().Contains(JPM_SETTLEMENT_CURRENCY)).FirstOrDefault(); if (!string.IsNullOrEmpty(tempFinder)) { //tempSplit = tempFinder.Split(new string[] { ": " }, StringSplitOptions.None); //LocalCurrency = tempSplit.Last(); //if (LocalCurrency.Length > 3) //{ // tempSplit = LocalCurrency.Split(' '); // LocalCCY = tempSplit.First(); //} tempSplit = tempFinder.Split(':'); LocalCurrency = tempSplit.Last().Trim(); LocalCurrency = StripInvalidCharacters(LocalCurrency); tempFinder = GetTextBaseOnReference(JPM_EQUITY_NOTIONAL_AMOUNT); if (!string.IsNullOrEmpty(tempFinder)) { tempSplit = tempFinder.Split(':'); if (tempSplit != null && tempSplit.Count() > 0) { string tempCurrency = tempSplit.Last(); tempSplit = tempCurrency.Split(' '); if (tempSplit != null && tempSplit.Count() > 0) { tempCurrency = StripInvalidCharacters(tempSplit.First() != string.Empty ? tempSplit.First() : tempSplit[1]); if (string.Compare(tempCurrency.ToLower(), LocalCurrency.ToLower()) != 0) { LocalCurrency = tempCurrency; } } } } } // SELLER tempFinder = Texts.Where(x => x.Contains(JPM_SELLER)).FirstOrDefault(); if (!string.IsNullOrEmpty(tempFinder)) { tempSplit = tempFinder.Split(':'); Seller = tempSplit.Last().Trim(); // hard code for now if (string.Compare(StripInvalidCharacters(Seller), "JPMorgan") == 0) { Seller = "JPM"; } else if (string.Compare(StripInvalidCharacters(Seller), "Counterparty") == 0) { Seller = Fund; } } else { tempFinder = Texts.Where(x => x.Contains(JPM_EQUITY_AMOUNT_PAYER)).FirstOrDefault(); if (!string.IsNullOrEmpty(tempFinder)) { tempSplit = tempFinder.Split(':'); Seller = tempSplit.Last().Trim(); // hard code for now if (string.Compare(StripInvalidCharacters(Seller), "JPMorgan") == 0) { Seller = "JPM"; } else if (string.Compare(StripInvalidCharacters(Seller), "Counterparty") == 0) { Seller = Fund; } } } // BUYER // NOTE: Buyer is always the opposite of seller if (string.Compare(Seller, "JPM") == 0) { Buyer = Fund; } else { Buyer = "JPM"; } // MATURITY DATE tempFinder = Texts.Where(x => x.Contains(JPM_VALUATION_DATE_EXPECTED_TO_BE)).FirstOrDefault(); if (!string.IsNullOrEmpty(tempFinder)) { Regex regex = new Regex(@"\d{2}\s\w+\s\d{4}"); Match match = regex.Match(tempFinder); DateTime tempPlaceHolder = DateTime.MinValue; if (match.Success) { DateTime.TryParse(match.Value, out tempPlaceHolder); if (tempPlaceHolder != DateTime.MinValue) { MaturityDate = tempPlaceHolder; } } } // SECURITY NAME tempFinder = Texts.Where(x => x.Replace(" ", "").Contains(JPM_SECURITY_NAME_REFERENCE)).FirstOrDefault(); if (!string.IsNullOrEmpty(tempFinder)) { tempSplit = tempFinder.Split(':'); tempSecurityName = tempSplit.Last(); if (!string.IsNullOrEmpty(tempSecurityName)) { if (tempSecurityName.ToLower().Contains("hang seng")) { if (string.Compare(tempSecurityName.Trim(), "Hang Seng China Enterprises Index", true) == 0) { tempSecurityName = "HSCEI China Index"; } } else if (tempSecurityName.ToLower().Contains("taiex index")) { tempSecurityName = "TAIEX Futures Swap"; } SecurityName = aqrIDLookUp.GetSecurityNameByMatch(tempSecurityName, MaturityDate); } } // SECURITY TYPE SecurityType = aqrIDLookUp.GetSecurityType(SecurityName); // MULTIPLIER tempSecurityName = SecurityName.Split(' ').First(); tempMultiplier = lookup.GetMultiplier(tempSecurityName, SecurityType); if (tempMultiplier == 0) { } // QUANTIY tempFinder = Texts.Where(x => x.Contains(JPM_NUMBER_OF_UNITS)).FirstOrDefault(); if (!string.IsNullOrEmpty(tempFinder)) { tempSplit = tempFinder.Split(':'); NumberOfUnits = Double.Parse(tempSplit.Last()); } if (NumberOfUnits > 0) { Quantity = NumberOfUnits / tempMultiplier; } else { Quantity = Multiplier / tempMultiplier; } // Multiplier Multiplier = tempMultiplier; // NOTIONAL Notional = Quantity * Price * Multiplier; // AQR ID AQRID = aqrIDLookUp.GetAQRID(SecurityName, SecurityType); //Always zero unless otherwise stated in the contract FixedRate = 0; //Always zero unless otherwise stated in the contract FloatRate = 0; //Always zero unless otherwise stated in the contract SettledCash = 0; SettledCurrency = LocalCurrency; Spread = 0; Status = ConfirmsData.RunStatus.Success; } catch (Exception ex) { Status = ConfirmsData.RunStatus.Failed; } }
public override void FillData(string data) { lookup.LoadLookUpTables(); aqrIDLookUp.LoadLookUpTables(); string[] tempContainer = data.Split('\n'); string[] tempSplit; string tempFinder = string.Empty; string tempSecurityName = string.Empty; string tempMaturityDate = string.Empty; string tempFund = string.Empty; string tempFixedPrice = string.Empty; double tempMultiplier = 0; int dateTimeIndex = 0; DateTime tempContentDate; Texts = tempContainer.ToList(); try { // Get the date reference tempFinder = GetTextBaseOnReference(ML_DATE); if (!string.IsNullOrEmpty(tempFinder)) { dateTimeIndex = Texts.IndexOf(tempFinder); // FUND is the line after the letter date while (string.IsNullOrEmpty(tempFund.Trim())) { tempFund = Texts[dateTimeIndex + 1]; dateTimeIndex++; } Fund = lookup.GetFundShortName(tempFund); } // TRADE ID / CP REF tempFinder = GetTextBaseOnReference(ML_TRADE_ID); if (!string.IsNullOrEmpty(tempFinder)) { tempSplit = tempFinder.Split(':'); regex = new Regex(@"\d+"); Match match = regex.Match(tempSplit[1]); if (match.Success) { CPRef = match.Value; } } // TRANSACTION TYPE TransactionType = "Open"; // SECURITY TYPE tempFinder = GetTextBaseOnReference(ML_COMMODITY); if (!string.IsNullOrEmpty(tempFinder)) { tempSplit = tempFinder.Split(':'); tempSecurityName = tempSplit[1]; //if (string.Compare(tempSecurityName.Trim(), "SoyBean Meal", true) == 0) if (tempSecurityName.Trim().Contains("SoyBean Meal")) { tempSecurityName = "Soy Meal"; } else if (string.Compare(tempSecurityName.Trim(), ML_REFINED_PRODUCS) == 0) { tempFinder = GetTextBaseOnReference(ML_COMMODITY_REFERENCE_PRICE); if (!string.IsNullOrEmpty(tempFinder)) { tempSplit = tempFinder.Split(':'); tempSecurityName = tempSplit.LastOrDefault(); } } KeyValuePair <string, string> kvp = lookup.GetSecurityValues(tempSecurityName); tempSecurityName = kvp.Key; SecurityType = kvp.Value; } // MATURITY DATE tempFinder = GetTextBaseOnReference(ML_EXPIRY_DATE); if (string.IsNullOrEmpty(tempFinder)) { tempFinder = GetTextBaseOnReference(ML_TERMINIATION_DATE); } if (!string.IsNullOrEmpty(tempFinder)) { tempSplit = tempFinder.Split(':'); string dateToParse = tempSplit[1]; if (string.IsNullOrEmpty(dateToParse)) { int dateIndex = Texts.IndexOf(tempFinder) + 2; dateToParse = Texts[dateIndex]; } DateTime tempPlaceHolder = DateTime.MinValue; DateTime.TryParse(dateToParse, out tempPlaceHolder); MaturityDate = tempPlaceHolder; } // SECURITY NAME // Special condition for Natural Gas if (string.Compare(tempSecurityName, "Natural Gas", true) == 0) { //SecurityName = aqrIDLookUp.GetSecurityNameByMatch(tempSecurityName, MaturityDate); SecurityName = aqrIDLookUp.GetSecurityNameByMonth(tempSecurityName, MaturityDate); if (!string.IsNullOrEmpty(SecurityName)) { MaturityDate = aqrIDLookUp.GetMaturityDateBySecurityName(SecurityName); } } else { // search using alias first SecurityName = aqrIDLookUp.GetSecurityNameByAlias(SecurityType, tempSecurityName, MaturityDate); //SecurityName = aqrIDLookUp.GetSecurityName(SecurityType, MaturityDate); if (string.IsNullOrEmpty(SecurityName)) { SecurityName = aqrIDLookUp.GetSecurityNameByMatch(tempSecurityName, SecurityType, MaturityDate); } } // AQR ID AQRID = aqrIDLookUp.GetAQRID(SecurityName, SecurityType); // MULTIPLIER Multiplier = lookup.GetMultiplier(tempSecurityName); if (Multiplier == 0) { Multiplier = lookup.GetMultiplier(SecurityName); } // TRADE DATE tempFinder = GetTextBaseOnReference(ML_TRADE_DATE); if (!string.IsNullOrEmpty(tempFinder)) { tempSplit = tempFinder.Split(':'); DateTime tempPlaceHolder = DateTime.MinValue; DateTime.TryParse(tempSplit[1], out tempPlaceHolder); TradeDate = tempPlaceHolder; } // SETTLEMENT DATE int daysToAdd = 0; SettlementDate = TradeDate; while (daysToAdd < 3) { SettlementDate = SettlementDate.AddDays(1); if (SettlementDate.DayOfWeek != DayOfWeek.Saturday && SettlementDate.DayOfWeek != DayOfWeek.Sunday) { daysToAdd++; } } // QUANTITY tempFinder = GetTextBaseOnReference(ML_TOTAL_NOTIONAL_QTY); if (string.IsNullOrEmpty(tempFinder)) { tempFinder = GetTextBaseOnReference(ML_VOLUME); } if (!string.IsNullOrEmpty(tempFinder)) { tempSplit = tempFinder.Split(':'); regex = new Regex(@"\d+"); Match match = regex.Match(StripInvalidCharacters(tempSplit[1])); if (match.Success) { Quantity = Convert.ToDouble(match.Value); Quantity = Quantity / Multiplier; } } // PRICE tempFinder = GetTextBaseOnReference(ML_FIXED_PRICE); if (!string.IsNullOrEmpty(tempFinder)) { tempSplit = tempFinder.Split(':'); Char[] tempChar = tempSplit[1].ToCharArray().Where(c => Char.IsDigit(c) || Char.IsPunctuation(c)).ToArray(); // temporary hard code unwanted characters to be removed List <char> tempCharList = tempChar.ToList(); tempCharList.Remove('('); tempCharList.Remove(')'); Price = Convert.ToDouble(new string(tempCharList.ToArray())); if (lookup.SelectedIndex > -1) { string note = lookup.GetNote(lookup.SelectedIndex); if (!string.IsNullOrEmpty(note) && string.Compare(note, ML_MOVE_2_DECIMAL_RIGHT) == 0) { Price = Price * 100; } } // for local ccy tempFixedPrice = tempSplit[1]; } // LOCAL CCY tempFinder = GetTextBaseOnReference(ML_TRANSACTION_CURRENCY); if (!string.IsNullOrEmpty(tempFinder)) { tempSplit = tempFinder.Split(':'); LocalCurrency = tempSplit.LastOrDefault(); } else if (!string.IsNullOrEmpty(tempFixedPrice)) { tempSplit = tempFixedPrice.TrimStart(' ').Split(' '); LocalCurrency = tempSplit.FirstOrDefault(); } // NOTIONAL Notional = Quantity * Price * Multiplier; // BUYER tempFinder = GetTextBaseOnReference(ML_FIXED_PRICE_PAYOR); if (string.IsNullOrEmpty(tempFinder)) { tempFinder = GetTextBaseOnReference(ML_FIXED_PRICE_PAYER); } if (!string.IsNullOrEmpty(tempFinder)) { string tempBuyer = string.Empty; tempSplit = tempFinder.Split(':'); tempBuyer = tempSplit.LastOrDefault(); if (string.Compare(tempBuyer, tempFund, true) == 0 || StripInvalidCharacters(tempFund).Contains(StripInvalidCharacters(tempBuyer))) { Buyer = Fund; } else { Buyer = "ML"; } } // SELLER tempFinder = GetTextBaseOnReference(ML_FLOATNG_PRICE_PAYOR); if (string.IsNullOrEmpty(tempFinder)) { tempFinder = GetTextBaseOnReference(ML_FLOATNG_PRICE_PAYER); } if (!string.IsNullOrEmpty(tempFinder)) { tempSplit = tempFinder.Split(':'); Seller = tempSplit.LastOrDefault(); if (string.Compare(Seller.Trim(), ML_LONG_NAME, true) == 0) { Seller = "ML"; } else { Seller = Fund; } } FixedRate = 0; FloatRate = 0; SettledCash = 0; SettledCurrency = LocalCurrency; Spread = 0; CounterParty = "ML"; Status = RunStatus.Success; } catch (Exception ex) { Status = RunStatus.Failed; CoreLibrary.Logger.Instance.Error(this.GetType(), "Error in parsing document " + CPRef + Environment.NewLine + ex.Message); } }