コード例 #1
0
        public void TestTryGetDayOfYearFiscalEnd()
        {
            int testResultOut;
            var testResult = Copula.TryGetDayOfYearFiscalEnd("--12-25", out testResultOut);

            System.Console.WriteLine(testResultOut);
            Assert.IsTrue(testResult);
        }
コード例 #2
0
        public override IEnumerable <dynamic> ParseContent(object content)
        {
            var xmlContent = content as string;

            if (string.IsNullOrWhiteSpace(xmlContent))
            {
                return(null);
            }
            var xmlNsMgr = GetXmlAndNsMgr(xmlContent);

            if (xmlNsMgr?.Item1 == null || xmlNsMgr.Item2 == null)
            {
                return(null);
            }

            _xml   = xmlNsMgr.Item1;
            _nsMgr = xmlNsMgr.Item2;

            bool.TryParse(_xml.SelectSingleNode($"//{XmlNs.DEI}:AmendmentFlag", _nsMgr)?.InnerText ?? bool.FalseString,
                          out var amendmentFlag);

            var endOfYearStr = _xml.SelectSingleNode($"//{XmlNs.DEI}:CurrentFiscalYearEndDate", _nsMgr)?.InnerText ??
                               string.Empty;

            Copula.TryGetDayOfYearFiscalEnd(endOfYearStr, out var endOfYear);

            var cik = _xml.SelectSingleNode($"//{XmlNs.DEI}:EntityCentralIndexKey", _nsMgr)?.InnerText;

            int.TryParse(
                _xml.SelectSingleNode($"//{XmlNs.DEI}:EntityCommonStockSharesOutstanding", _nsMgr)?.InnerText ?? String.Empty,
                out var numOfShares);
            var name   = _xml.SelectSingleNode($"//{XmlNs.DEI}:EntityRegistrantName", _nsMgr)?.InnerText;
            var ticker = _xml.SelectSingleNode($"//{XmlNs.DEI}:TradingSymbol", _nsMgr)?.InnerText;

            var assets      = GetNodeDollarYear(_xml, $"//{XmlNs.US_GAAP}:Assets", _nsMgr);
            var liabilities = GetNodeDollarYear(_xml, $"//{XmlNs.US_GAAP}:Liabilities", _nsMgr);

            var netIncome = GetNodeDollarYear(_xml, $"//{XmlNs.US_GAAP}:NetIncomeLoss", _nsMgr);

            List <Tuple <int, decimal> > operateIncome = new List <Tuple <int, decimal> >();

            foreach (var anotherName in new[] { "OperatingIncomeLoss", "BenefitsLossesAndExpenses" })
            {
                operateIncome = GetNodeDollarYear(_xml,
                                                  $"//{XmlNs.US_GAAP}:{anotherName}", _nsMgr);
                if (operateIncome.Any())
                {
                    break;
                }
            }

            List <Tuple <int, decimal> > salesRev = new List <Tuple <int, decimal> >();

            foreach (
                var anotherName in
                new[]
                { "Revenues", "RetailRevenue", "SalesRevenueNet", "SalesRevenueServicesNet", "SalesRevenueGoodsNet" })
            {
                salesRev = GetNodeDollarYear(_xml,
                                             $"//{XmlNs.US_GAAP}:{anotherName}", _nsMgr);
                if (salesRev.Any())
                {
                    break;
                }
            }

            var textBlocks = GetTextBlocks();

            return(new List <dynamic>
            {
                new
                {
                    IsAmended = amendmentFlag,
                    EndOfYear = endOfYear,
                    Cik = cik,
                    NumOfShares = numOfShares,
                    Name = name,
                    Ticker = ticker,
                    Assets = assets,
                    Liabilities = liabilities,
                    NetIncome = netIncome,
                    OperatingIncome = operateIncome,
                    Revenue = salesRev,
                    TextBlocks = textBlocks
                }
            });
        }