コード例 #1
0
        protected override CompanyStatisticsResult ConvertResult(YahooManaged.Base.ConnectionInfo connInfo, System.IO.Stream stream, YahooManaged.Base.SettingsBase settings)
        {
            CompanyStatisticsData result = null;
            if (stream != null)
            {
                System.Globalization.CultureInfo convCulture = new System.Globalization.CultureInfo("en-US");
                XDocument doc = MyHelper.ParseXmlDocument(stream);
                XElement resultNode = XPath.GetElement("//table[@id=\"yfncsumtab\"]/tr[2]",doc);

                if (resultNode != null)
                {

                    XElement tempNode = null;
                    XElement vmNode = XPath.GetElement("/td[1]/table[2]/tr/td/table", resultNode);
                    double[] vmValues = new double[9];
                    if (vmNode != null)
                    {
                        tempNode = XPath.GetElement("/tr[1]/td[2]/span", vmNode);
                        if (tempNode != null) vmValues[0] = FinanceHelper.GetMillionValue(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[2]/td[2]", vmNode);
                        if (tempNode != null) vmValues[1] = FinanceHelper.GetMillionValue(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[3]/td[2]", vmNode);
                        if (tempNode != null) vmValues[2] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[4]/td[2]", vmNode);
                        if (tempNode != null) vmValues[3] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[5]/td[2]", vmNode);
                        if (tempNode != null) vmValues[4] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[6]/td[2]", vmNode);
                        if (tempNode != null) vmValues[5] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[7]/td[2]", vmNode);
                        if (tempNode != null) vmValues[6] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[8]/td[2]", vmNode);
                        if (tempNode != null) vmValues[7] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[9]/td[2]", vmNode);
                        if (tempNode != null) vmValues[8] = FinanceHelper.ParseToDouble(tempNode.Value);

                    }

                    CompanyValuationMeasures vm = new CompanyValuationMeasures(vmValues);


                    XElement fyNode = XPath.GetElement("/td[1]/table[4]/tr/td/table",resultNode);
                    XElement profitNode = XPath.GetElement("/td[1]/table[5]/tr/td/table", resultNode);
                    XElement meNode = XPath.GetElement("/td[1]/table[6]/tr/td/table", resultNode);
                    XElement isNode = XPath.GetElement("/td[1]/table[7]/tr/td/table", resultNode);
                    XElement bsNode = XPath.GetElement("/td[1]/table[8]/tr/td/table", resultNode);
                    XElement cfsNode = XPath.GetElement("/td[1]/table[9]/tr/td/table", resultNode);

                    DateTime fiscalYEnds = new DateTime();
                    DateTime mostRecQutr = new DateTime();
                    double[] fhValues = new double[20];

                    if (fyNode != null)
                    {
                        tempNode = XPath.GetElement("/tr[2]/td[2]", fyNode);
                        if (tempNode != null) fiscalYEnds = FinanceHelper.ParseToDateTime(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[3]/td[2]",fyNode);
                        if (tempNode != null) mostRecQutr = FinanceHelper.ParseToDateTime(tempNode.Value);
                    }

                    if (profitNode != null)
                    {
                        tempNode = XPath.GetElement("/tr[2]/td[2]",profitNode);
                        if (tempNode != null) fhValues[0] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[3]/td[2]",profitNode);
                        if (tempNode != null) fhValues[1] = FinanceHelper.ParseToDouble(tempNode.Value);
                    }

                    if (meNode != null)
                    {
                        tempNode = XPath.GetElement("/tr[2]/td[2]",meNode);
                        if (tempNode != null) fhValues[2] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[3]/td[2]",meNode);
                        if (tempNode != null) fhValues[3] = FinanceHelper.ParseToDouble(tempNode.Value);
                    }

                    if (isNode != null)
                    {
                        tempNode = XPath.GetElement("/tr[2]/td[2]", isNode);
                        if (tempNode != null) fhValues[4] = FinanceHelper.GetMillionValue(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[3]/td[2]", isNode);
                        if (tempNode != null) fhValues[5] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[4]/td[2]", isNode);
                        if (tempNode != null) fhValues[6] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[5]/td[2]", isNode);
                        if (tempNode != null) fhValues[7] = FinanceHelper.GetMillionValue(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[6]/td[2]", isNode);
                        if (tempNode != null) fhValues[8] = FinanceHelper.GetMillionValue(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[7]/td[2]", isNode);
                        if (tempNode != null) fhValues[9] = FinanceHelper.GetMillionValue(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[8]/td[2]", isNode);
                        if (tempNode != null) fhValues[10] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[9]/td[2]", isNode);
                        if (tempNode != null) fhValues[11] = FinanceHelper.ParseToDouble(tempNode.Value);
                    }

                    if (bsNode != null)
                    {
                        tempNode = XPath.GetElement("/tr[2]/td[2]",bsNode);
                        if (tempNode != null) fhValues[12] = FinanceHelper.GetMillionValue(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[3]/td[2]",bsNode);
                        if (tempNode != null) fhValues[13] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[4]/td[2]",bsNode);
                        if (tempNode != null) fhValues[14] = FinanceHelper.GetMillionValue(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[5]/td[2]",bsNode);
                        if (tempNode != null) fhValues[15] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[6]/td[2]",bsNode);
                        if (tempNode != null) fhValues[16] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[7]/td[2]",bsNode);
                        if (tempNode != null) fhValues[17] = FinanceHelper.ParseToDouble(tempNode.Value);

                    }

                    if (cfsNode != null)
                    {
                        tempNode = XPath.GetElement("/tr[2]/td[2]", cfsNode);
                        if (tempNode != null) fhValues[18] = FinanceHelper.GetMillionValue(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[3]/td[2]",cfsNode);
                        if (tempNode != null) fhValues[19] = FinanceHelper.GetMillionValue(tempNode.Value);
                    }

                    CompanyFinancialHighlights fh = new CompanyFinancialHighlights(fiscalYEnds, mostRecQutr, fhValues);


                    XElement sphNode = XPath.GetElement("/td[3]/table[2]/tr/td/table", resultNode);
                    XElement stNode = XPath.GetElement("/td[3]/table[3]/tr/td/table", resultNode);
                    XElement dsNode = XPath.GetElement("/td[3]/table[4]/tr/td/table", resultNode);

                    double[] ctiValues = new double[23];
                    DateTime exDivDate = new DateTime();
                    DateTime divDate = new DateTime();
                    DateTime splitDate = new DateTime();
                    SharesSplitFactor sf = null;

                    if (sphNode != null)
                    {

                        tempNode = XPath.GetElement("/tr[2]/td[2]",sphNode);
                        if (tempNode != null) ctiValues[0] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[3]/td[2]",sphNode);
                        if (tempNode != null) ctiValues[1] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[4]/td[2]",sphNode);
                        if (tempNode != null) ctiValues[2] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[5]/td[2]",sphNode);
                        if (tempNode != null) ctiValues[3] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[6]/td[2]",sphNode);
                        if (tempNode != null) ctiValues[4] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[7]/td[2]",sphNode);
                        if (tempNode != null) ctiValues[5] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[8]/td[2]",sphNode);
                        if (tempNode != null) ctiValues[6] = FinanceHelper.ParseToDouble(tempNode.Value);

                    }


                    if (stNode != null)
                    {

                        tempNode = XPath.GetElement("/tr[2]/td[2]",stNode);
                        if (tempNode != null) ctiValues[7] = FinanceHelper.ParseToDouble(tempNode.Value) / 1000;

                        tempNode = XPath.GetElement("/tr[3]/td[2]",stNode);
                        if (tempNode != null) ctiValues[8] = FinanceHelper.ParseToDouble(tempNode.Value) / 1000;

                        tempNode = XPath.GetElement("/tr[4]/td[2]",stNode);
                        if (tempNode != null) ctiValues[9] = FinanceHelper.GetMillionValue(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[5]/td[2]",stNode);
                        if (tempNode != null) ctiValues[10] = FinanceHelper.GetMillionValue(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[6]/td[2]",stNode);
                        if (tempNode != null) ctiValues[11] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[7]/td[2]",stNode);
                        if (tempNode != null) ctiValues[12] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[8]/td[2]",stNode);
                        if (tempNode != null) ctiValues[13] = FinanceHelper.GetMillionValue(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[9]/td[2]",stNode);
                        if (tempNode != null) ctiValues[14] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[10]/td[2]",stNode);
                        if (tempNode != null) ctiValues[15] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[11]/td[2]",stNode);
                        if (tempNode != null) ctiValues[16] = FinanceHelper.GetMillionValue(tempNode.Value);

                    }

                    if (dsNode != null)
                    {

                        tempNode = XPath.GetElement("/tr[2]/td[2]",dsNode);
                        if (tempNode != null) ctiValues[17] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[3]/td[2]",dsNode);
                        if (tempNode != null) ctiValues[18] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[4]/td[2]",dsNode);
                        if (tempNode != null) ctiValues[19] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[5]/td[2]",dsNode);
                        if (tempNode != null) ctiValues[20] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[6]/td[2]",dsNode);
                        if (tempNode != null) ctiValues[21] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[7]/td[2]",dsNode);
                        if (tempNode != null) ctiValues[22] = FinanceHelper.ParseToDouble(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[8]/td[2]",dsNode);
                        if (tempNode != null) divDate = FinanceHelper.ParseToDateTime(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[9]/td[2]",dsNode);
                        if (tempNode != null) exDivDate = FinanceHelper.ParseToDateTime(tempNode.Value);

                        tempNode = XPath.GetElement("/tr[10]/td[2]",dsNode);
                        if (tempNode != null)
                        {
                            string[] txt = tempNode.Value.Split(':');
                            int from, to;
                            if (int.TryParse(txt[0], out to) && int.TryParse(txt[1], out from))
                            {
                                sf = new SharesSplitFactor(to, from);
                            }
                        }

                        tempNode = XPath.GetElement("/tr[11]/td[2]",dsNode);
                        if (tempNode != null) splitDate = FinanceHelper.ParseToDateTime(tempNode.Value);

                    }
                    CompanyTradingInfo cti = new CompanyTradingInfo(ctiValues, divDate, exDivDate, splitDate, sf);

                    result = new CompanyStatisticsData(((CompanyStatisticsDownloadSettings)settings).ID, vm, fh, cti);
                }
            }

            return new CompanyStatisticsResult(result);
        }
コード例 #2
0
        protected override CompanyProfileResult ConvertResult(YahooManaged.Base.ConnectionInfo connInfo, System.IO.Stream stream, YahooManaged.Base.SettingsBase settings)
        {
            CompanyProfileData res = null;

            System.Globalization.CultureInfo convCulture = new System.Globalization.CultureInfo("en-US");
            if (stream != null)
            {
                XDocument doc        = MyHelper.ParseXmlDocument(stream);
                XElement  resultNode = XPath.GetElement("//table[@id=\"yfncsumtab\"]/tr[2]", doc);

                if (resultNode != null)
                {
                    res = new CompanyProfileData();
                    res.SetID(FinanceHelper.CleanIndexID(((CompanyProfileDownloadSettings)settings).ID.ToUpper()));

                    XElement nameNode = XPath.GetElement("td[1]/b[1]", resultNode);
                    if (nameNode != null)
                    {
                        res.CompanyName = nameNode.Value;
                    }

                    XElement addressNode = XPath.GetElement("td[1]", resultNode);
                    if (addressNode != null)
                    {
                        System.Text.StringBuilder formattedAddress = new System.Text.StringBuilder();
                        try
                        {
                            string addNodeStr = addressNode.ToString();
                            if (addNodeStr != string.Empty)
                            {
                                addNodeStr = addNodeStr.Substring(addNodeStr.IndexOf("/>") + 2);
                                string[] rawAddress = addNodeStr.Substring(0, addNodeStr.IndexOf("Website")).Split(new string[] { "<b>", "<br />", "</b>", "\r", "\n", " - ", "</a>" }, StringSplitOptions.RemoveEmptyEntries);
                                if (rawAddress.Length >= 7)
                                {
                                    foreach (string line in rawAddress)
                                    {
                                        string l = line.Trim();
                                        if (l != string.Empty && !l.StartsWith("<a") && l != "Map")
                                        {
                                            formattedAddress.AppendLine(l);
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        res.Address = formattedAddress.ToString().TrimEnd();
                    }

                    XElement indicesNode = XPath.GetElement("td[1]/table[2]/tr/td/table/tr/td[2]", resultNode);
                    if (indicesNode != null)
                    {
                        List <KeyValuePair <string, string> > lstIndices = new List <KeyValuePair <string, string> >();
                        foreach (XElement indexLink in indicesNode.Elements())
                        {
                            if (indexLink.Name.LocalName == "a")
                            {
                                string indexID = Uri.UnescapeDataString(MyHelper.GetXmlAttributeValue(indexLink, "href").ToUpper().Replace("HTTP://FINANCE.YAHOO.COM/Q?S=", "").Replace("&D=T", ""));
                                string name    = string.Empty;
                                foreach (string p in indexLink.Value.Split(new string[] { "\r\n" }, StringSplitOptions.None))
                                {
                                    name += p.Trim() + " ";
                                }
                                lstIndices.Add(new KeyValuePair <string, string>(indexID, name.TrimEnd()));
                            }
                        }
                        res.Details.IndexMembership = lstIndices.ToArray();
                    }

                    XElement sectorsNode = XPath.GetElement("td[1]/table[2]/tr/td/table/tr[2]/td[2]", resultNode);
                    if (sectorsNode != null)
                    {
                        foreach (XElement sectorLink in sectorsNode.Elements())
                        {
                            if (sectorLink.Name.LocalName == "a")
                            {
                                foreach (Sector sect in Enum.GetValues(typeof(Sector)))
                                {
                                    string name = string.Empty;
                                    foreach (string p in sectorLink.Value.Split(new string[] { "\r\n" }, StringSplitOptions.None))
                                    {
                                        name += p.Trim() + " ";
                                    }
                                    name = name.TrimEnd();
                                    if (sect.ToString().Replace("_", " ") == name)
                                    {
                                        res.Details.Sector = sect;
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    XElement industryNode = XPath.GetElement("td[1]/table[2]/tr/td/table/tr[3]/td[2]", resultNode);
                    if (industryNode != null)
                    {
                        foreach (XElement industryLink in industryNode.Elements())
                        {
                            if (industryLink.Name.LocalName == "a")
                            {
                                int indIndex = 0;
                                if (int.TryParse(MyHelper.GetXmlAttributeValue(industryLink, "href").Replace("http://biz.yahoo.com/ic/", "").Replace(".html", ""), out indIndex))
                                {
                                    res.Details.Industry = (Industry)indIndex;
                                }
                            }
                        }
                    }

                    XElement employeesNode = XPath.GetElement("td[1]/table[2]/tr/td/table/tr[4]/td[2]", resultNode);
                    if (employeesNode != null)
                    {
                        int fte;
                        if (int.TryParse(employeesNode.Value.Trim(), System.Globalization.NumberStyles.Any, convCulture, out fte))
                        {
                            res.Details.FullTimeEmployees = fte;
                        }
                    }

                    XElement summaryNode = XPath.GetElement("td[1]/p[1]", resultNode);
                    if (summaryNode != null)
                    {
                        System.Text.StringBuilder summaryText = new System.Text.StringBuilder();
                        foreach (string line in summaryNode.Value.Split(new string[] { "\r\n" }, StringSplitOptions.None))
                        {
                            summaryText.Append(line.Trim() + " ");
                        }
                        res.BusinessSummary = summaryText.ToString().TrimEnd();
                    }

                    XElement websitesNodes = XPath.GetElement("td[1]/table[5]/tr/td", resultNode);
                    if (websitesNodes != null)
                    {
                        List <Uri> lstWebsites = new List <Uri>();
                        foreach (XElement linkNode in websitesNodes.Elements())
                        {
                            if (linkNode.Name.LocalName == "a")
                            {
                                lstWebsites.Add(new Uri(MyHelper.GetXmlAttributeValue(linkNode, "href")));
                            }
                        }
                        res.CompanyWebsites = lstWebsites.ToArray();
                    }



                    XElement governanceNode   = null;
                    XElement governanceHeader = XPath.GetElement("td[3]/table[1]/tr/th/span", resultNode);
                    if (governanceHeader != null && governanceHeader.Value.Contains("Governance"))
                    {
                        governanceNode = XPath.GetElement("td[3]/table[2]/tr/td", resultNode);
                    }
                    if (governanceNode != null)
                    {
                        System.Text.StringBuilder governanceText = new System.Text.StringBuilder();
                        foreach (string line in governanceNode.Value.Split(new string[] { "\r\n" }, StringSplitOptions.None))
                        {
                            governanceText.Append(line.Trim() + " ");
                        }
                        res.CorporateGovernance = governanceText.ToString().TrimEnd();
                    }



                    XElement executivesNode   = null;
                    XElement executivesHeader = XPath.GetElement("td[3]/table[3]/tr/th/span", resultNode);
                    if (executivesHeader != null && executivesHeader.Value.Contains("Executives"))
                    {
                        executivesNode = XPath.GetElement("td[3]/table[4]/tr/td/table", resultNode);
                    }
                    else
                    {
                        executivesNode = XPath.GetElement("td[3]/table[2]/tr/td/table", resultNode);
                    }

                    if (executivesNode != null)
                    {
                        List <ExecutivePersonInfo> lst = new List <ExecutivePersonInfo>();
                        bool isFirst = true;
                        foreach (XElement row in executivesNode.Elements())
                        {
                            if (!isFirst)
                            {
                                if (row.Name.LocalName == "tr")
                                {
                                    XElement[] enm = MyHelper.EnumToArray(row.Elements());
                                    if (enm.Length >= 3)
                                    {
                                        ExecutivePersonInfo exec = new ExecutivePersonInfo();

                                        string name = string.Empty;

                                        foreach (string l in MyHelper.EnumToArray(enm[0].Elements())[0].Value.Split(new string[] { "\r\n" }, StringSplitOptions.None))
                                        {
                                            name += l.Trim() + " ";
                                        }

                                        exec.Name = name.TrimEnd();

                                        string position = string.Empty;

                                        var enm2 = MyHelper.EnumToArray(enm[0].Elements());
                                        foreach (string l in enm2[enm2.Length - 1].Value.Split(new string[] { "\r\n" }, StringSplitOptions.None))
                                        {
                                            position += l.Trim() + " ";
                                        }

                                        exec.Position = position.Trim();


                                        string payStr = enm[1].Value.Replace("\r\n", "").Trim();
                                        if (!payStr.Contains("N/A"))
                                        {
                                            exec.Pay = FinanceHelper.GetMillionValue(payStr) * 1000000;
                                        }

                                        string exercisedStr = enm[2].Value.Replace("\r\n", "").Trim();
                                        if (!exercisedStr.Contains("N/A"))
                                        {
                                            double d = FinanceHelper.GetMillionValue(exercisedStr);
                                            exec.Exercised = (int)(d * 1000000);
                                        }

                                        lst.Add(exec);
                                    }
                                }
                            }
                            else
                            {
                                isFirst = false;
                            }
                        }
                        res.KeyExecutives = lst.ToArray();
                    }
                    if (res.BusinessSummary.StartsWith("There is no "))
                    {
                        res = null;
                    }
                }
            }

            return(new CompanyProfileResult(res));
        }