public static async Task <CompanyStatsYF> GetCompanyStatsAsync(string symbol) { CompanyStatsYF companyStat = new CompanyStatsYF(); try { //Yahoo Quote Security quote = GetQuoteAsync(symbol).Result; if (quote != null) { //parse quote data into company stat companyStat.Symbol = symbol; companyStat.Exchange = quote.FullExchangeName; companyStat.CompanyName = quote.LongName; companyStat.CompanyTrading = quote.Tradeable; //companyStat.CompanyQuoteType = quote.QuoteType; //companyStat.CompanyMarket = quote.Market; //companyStat.MarketCap = quote.MarketCap; //companyStat.SharesOutstanding = quote.SharesOutstanding; decimal peTrailing = 0.0M; try { peTrailing = decimal.Parse(quote.TrailingPE.ToString()); } catch (Exception e) { /*do nothing*/ } decimal peForward = 0.0M; try { peForward = decimal.Parse(quote.ForwardPE.ToString()); } catch (Exception e) { /*set to trailing*/ peForward = peTrailing; } decimal epsTrailing = 0.0M; try { epsTrailing = decimal.Parse(quote.EpsTrailingTwelveMonths.ToString()); } catch (Exception e) { /*do nothing*/ } decimal epsForward = 0.0M; try { epsForward = decimal.Parse(quote.EpsForward.ToString()); } catch (Exception e) { /*set to trailing*/ epsForward = epsTrailing; } //companyStat.BookValue = decimal.Parse(quote.BookValue.ToString()); companyStat.Price = decimal.Parse(quote.RegularMarketPrice.ToString()); companyStat.PriceAverage50DayUSD = decimal.Parse(quote.FiftyDayAverage.ToString()); companyStat.PriceAverage200DayUSD = decimal.Parse(quote.TwoHundredDayAverage.ToString()); companyStat.PriceHigh52w = decimal.Parse(quote.FiftyTwoWeekHigh.ToString()); companyStat.PriceLow52w = decimal.Parse(quote.FiftyTwoWeekLow.ToString()); companyStat.PriceAverageEstimate52w = (companyStat.PriceHigh52w + companyStat.PriceLow52w) / 2; //companyStat.PriceToBook = decimal.Parse(quote.PriceToBook.ToString()); companyStat.VolumeToday = decimal.Parse(quote.RegularMarketVolume.ToString()); companyStat.VolumeTodayUSD = (companyStat.VolumeToday * companyStat.Price); companyStat.VolumeAverage10d = decimal.Parse(quote.AverageDailyVolume10Day.ToString()); companyStat.VolumeAverage10dUSD = (companyStat.VolumeAverage10d * companyStat.Price); companyStat.VolumeAverage3m = decimal.Parse(quote.AverageDailyVolume3Month.ToString()); companyStat.VolumeAverage3mUSD = (companyStat.VolumeAverage3m * companyStat.Price); /*Could get more trade data from IEX possibly * companyStat.TradeData = new TradeDataYF * { * BidPrice = decimal.Parse(quote.Bid.ToString()), * BidSize = decimal.Parse(quote.BidSize.ToString()), * AskPrice = decimal.Parse(quote.Ask.ToString()), * AskSize = decimal.Parse(quote.AskSize.ToString()) * };*/ } //Yahoo Dividends for the last year //You should be able to query data from various markets including US, HK, TW var dividends = await Yahoo.GetDividendsAsync(symbol, DateTime.Now.AddYears(-1), DateTime.Now); foreach (DividendTick div in dividends) { companyStat.Dividends.Add(div); } //Yahoo historical trade data and splits data var splits = await Yahoo.GetSplitsAsync(symbol, DateTime.Now.AddYears(-1), DateTime.Now); foreach (var split in splits) { companyStat.Splits.Add(split); } //Composite Score, this gets the YF quote twice right now //TODO: Update this method to not get YF quote twice during cache loading var score = Controllers.SearchController.GetCompositeScoreInternal(symbol, quote); if (score.CompositeScoreValue > 0) { companyStat.CompositeScoreResult = score; } } catch (Exception e) { Debug.WriteLine("EXCEPTION CAUGHT: YF.cs YF.GetComanyStatsAsync for symbol " + symbol + ", message: " + e.Message + ", StackTrace: " + e.StackTrace); } return(await Task.FromResult(companyStat)); }