/// <summary> /// Parses the web response html content from <see cref="SecForm.HtmlFormLink"/> /// locating the .xml Uri therein. /// </summary> /// <param name="webResponseBody"></param> /// <param name="srcUri"></param> /// <param name="pc"></param> /// <returns></returns> public static bool TryGetXmlLink(object webResponseBody, Uri srcUri, ref PublicCorporation pc) { var pcAnnualRpt = pc.SecReports?.FirstOrDefault(x => x.HtmlFormLink == srcUri); if (pcAnnualRpt == null) return false; var myDynData = Etx.DynamicDataFactory(srcUri); var myDynDataRslt = myDynData.ParseContent(webResponseBody); if (myDynDataRslt == null || !myDynDataRslt.Any()) return false; var xrblUriStr = myDynDataRslt.First().XrblUri; pcAnnualRpt.XmlLink = new Uri(xrblUriStr); var irsId = myDynDataRslt.First().IrsId as string; if(!string.IsNullOrWhiteSpace(irsId)) pc.EIN = new EmployerIdentificationNumber {Value = irsId}; return true; }
/// <summary> /// Merges the XBRL xml from the SEC filing for the given <see cref="pc"/> /// </summary> /// <param name="webResponseBody">The raw XML content from the SEC</param> /// <param name="srcUri"></param> /// <param name="pc"></param> /// <returns></returns> public static bool TryMergeXbrlInto10K(object webResponseBody, Uri srcUri, ref PublicCorporation pc) { var rptTenK = pc?.SecReports.FirstOrDefault(x => x is Form10K && ((Form10K)x).XmlLink == srcUri) as Form10K; if (rptTenK == null) return false; var myDynData = Etx.DynamicDataFactory(srcUri); var myDynDataRslt = myDynData.ParseContent(webResponseBody); if (myDynDataRslt == null || !myDynDataRslt.Any()) return false; if (rptTenK.FinancialData == null) rptTenK.FinancialData = new ComFinancialData { Assets = new NetConAssets(), Income = new NetConIncome() }; var xbrlDyn = myDynDataRslt.First(); var cik = xbrlDyn.Cik; if (pc.CIK.Value != cik) return false; if (rptTenK.CIK == null) rptTenK.CIK = new CentralIndexKey {Value = cik}; var ticker = xbrlDyn.Ticker ?? srcUri?.LocalPath.Split('/').LastOrDefault()?.Split('-').FirstOrDefault()?.ToUpper(); if (ticker != null && pc.TickerSymbols.All(x => !string.Equals(x.Symbol, ticker, StringComparison.OrdinalIgnoreCase))) { ticker = ticker.ToUpper(); pc.TickerSymbols.Add(new Ticker {Symbol = ticker, Country = "USA"}); } var legalName = xbrlDyn.Name; pc.UpsertName(KindsOfNames.Legal, legalName); rptTenK.FinancialData.NumOfShares = xbrlDyn.NumOfShares; if (xbrlDyn.EndOfYear > 0) pc.FiscalYearEndDay = xbrlDyn.EndOfYear; var assets = xbrlDyn.Assets as List<Tuple<int, decimal>>; var rptVal = assets?.OrderByDescending(x => x.Item1).FirstOrDefault(); if (rptVal != null) { rptTenK.FinancialData.Assets.TotalAssets = new Pecuniam(rptVal.Item2); rptTenK.FinancialData.FiscalYear = rptTenK.FinancialData.FiscalYear < rptVal.Item1 ? rptVal.Item1 : rptTenK.FinancialData.FiscalYear; } var lias = xbrlDyn.Liabilities as List<Tuple<int, decimal>>; rptVal = lias?.OrderByDescending(x => x.Item1).FirstOrDefault(); if (rptVal != null) { rptTenK.FinancialData.Assets.TotalLiabilities = new Pecuniam(rptVal.Item2); rptTenK.FinancialData.FiscalYear = rptTenK.FinancialData.FiscalYear < rptVal.Item1 ? rptVal.Item1 : rptTenK.FinancialData.FiscalYear; } var nis = xbrlDyn.NetIncome as List<Tuple<int, decimal>>; rptVal = nis?.OrderByDescending(x => x.Item1).FirstOrDefault(); if (rptVal != null) { rptTenK.FinancialData.Income.NetIncome = new Pecuniam(rptVal.Item2); rptTenK.FinancialData.FiscalYear = rptTenK.FinancialData.FiscalYear < rptVal.Item1 ? rptVal.Item1 : rptTenK.FinancialData.FiscalYear; } var ois = xbrlDyn.OperatingIncome as List<Tuple<int, decimal>>; rptVal = ois?.OrderByDescending(x => x.Item1).FirstOrDefault(); if (rptVal != null) { rptTenK.FinancialData.Income.OperatingIncome = new Pecuniam(rptVal.Item2); rptTenK.FinancialData.FiscalYear = rptTenK.FinancialData.FiscalYear < rptVal.Item1 ? rptVal.Item1 : rptTenK.FinancialData.FiscalYear; } var revs = xbrlDyn.Revenue as List<Tuple<int, decimal>>; rptVal = revs?.OrderByDescending(x => x.Item1).FirstOrDefault(); if (rptVal != null) { rptTenK.FinancialData.Income.Revenue = new Pecuniam(rptVal.Item2); rptTenK.FinancialData.FiscalYear = rptTenK.FinancialData.FiscalYear < rptVal.Item1 ? rptVal.Item1 : rptTenK.FinancialData.FiscalYear; } rptTenK.FinancialData.Income.Src = srcUri.ToString(); rptTenK.FinancialData.Assets.Src = srcUri.ToString(); return true; }
public void TestTryGetCorpData() { var xmlContent = System.IO.File.ReadAllText(SEC_BY_CIK_XML_PATH); var testResultOut = new PublicCorporation(); var testResult = NoFuture.Rand.Gov.Sec.Edgar.TryParseCorpData(xmlContent, new Uri( "http://www.sec.gov/cgi-bin/browse-edgar?action=getcompany&CIK=041215216456&type=10-K&dateb=&owner=exclude&count=100&output=atom"), ref testResultOut); Assert.IsTrue(testResult); Assert.IsNotNull(testResultOut); Assert.AreEqual("0000717538", testResultOut.CIK.Value); Assert.AreEqual("6021", testResultOut.SIC.Value); Assert.AreEqual("ARROW FINANCIAL CORP", testResultOut.Name); Assert.IsNotNull(testResultOut.MailingAddress); Assert.IsNotNull(testResultOut.BusinessAddress); Assert.AreEqual("250", testResultOut.BusinessAddress.Item1.PostBox); Assert.AreEqual("GLEN", testResultOut.BusinessAddress.Item1.StreetName); Assert.AreEqual("ST", testResultOut.BusinessAddress.Item1.StreetKind); Assert.AreEqual("250", testResultOut.MailingAddress.Item1.PostBox); //Assert.AreEqual("GLEN STREET", testResultOut.MailingAddress.Item1.StreetName); Assert.AreEqual("GLENS FALLS", testResultOut.BusinessAddress.Item2.City); Assert.AreEqual("NY", testResultOut.BusinessAddress.Item2.PostalState); Assert.AreEqual("12801", testResultOut.BusinessAddress.Item2.ZipCode); Assert.AreEqual("GLENS FALLS", testResultOut.MailingAddress.Item2.City); Assert.AreEqual("NY", testResultOut.MailingAddress.Item2.PostalState); Assert.AreEqual("12801", testResultOut.MailingAddress.Item2.ZipCode); Assert.IsNotNull(testResultOut.Phone); Assert.IsNotNull(testResultOut.Phone[0]); Assert.AreEqual("518", testResultOut.Phone[0].AreaCode); Assert.AreEqual("415", testResultOut.Phone[0].CentralOfficeCode); Assert.AreEqual("4299", testResultOut.Phone[0].SubscriberNumber); }
/// <summary> /// Merges the ticker symbol data contained in <see cref="webResponseBody"/> into the instance of <see cref="PublicCorporation"/> /// </summary> /// <param name="webResponseBody"></param> /// <param name="srcUri"></param> /// <param name="pc"></param> /// <returns></returns> public static bool TryMergeTickerLookup(object webResponseBody, Uri srcUri, ref PublicCorporation pc) { try { var myDynData = Etx.DynamicDataFactory(srcUri); var myDynDataRslt = myDynData.ParseContent(webResponseBody); if (myDynDataRslt == null) return false; foreach (var dd in myDynDataRslt) { var existing = pc.TickerSymbols.FirstOrDefault(x => x.Symbol == dd.Symbol && x.Country == dd.Country); if (existing != null) { existing.Src = myDynData.SourceUri.ToString(); existing.InstrumentType = dd.InstrumentType; continue; } pc.TickerSymbols.Add(new Ticker { Symbol = dd.Symbol, InstrumentType = dd.InstrumentType, Country = dd.Country, Src = myDynData.SourceUri.ToString() }); } return pc.TickerSymbols.Count > 0; } catch { return false; } }
public static Uri GetUri(PublicCorporation com) { return new Uri("http://www.bloomberg.com/markets/symbolsearch?query=" + com.UrlEncodedName + "&commit=Find+Symbols"); }