Пример #1
0
        public List <DailyPrice> GetHistoricalData()
        {
            List <DailyPrice> dailyPrices = new List <DailyPrice>();
            var endDate = DateTime.Now.ToShortDateString();
            var num     = (Convert.ToDateTime(endDate) - Convert.ToDateTime(StartDate)).ToString();

            num = num.Remove(num.IndexOf('.'));

            // Move to DataLocation
            string url  = @"https://www.wsj.com/market-data/quotes/AAPL/historical-prices/download?MOD_VIEW=page&num_rows=" + num + "&range_days=" + num + "&startDate=" + StartDate + "&endDate=" + endDate;
            var    days = web.DownloadString(url).Split('\n').Skip(1).ToArray();

            foreach (var day in days)
            {
                DailyPrice daily      = new DailyPrice();
                var        datapoints = day.Split(',').ToArray();
                daily.Symbol = Symbol;
                daily.Date   = Convert.ToDateTime(datapoints[0]);
                daily.Open   = Convert.ToDouble(datapoints[1]);
                daily.High   = Convert.ToDouble(datapoints[2]);
                daily.Low    = Convert.ToDouble(datapoints[3]);
                daily.Close  = Convert.ToDouble(datapoints[4]);
                dailyPrices.Add(daily);
            }

            return(dailyPrices);
        }
Пример #2
0
        public Rating GetRating()
        {
            Rating FinalRating = new Rating();

            // Get Dividend History
            var divHistory = new DividendHistory().GetHistory(web.DownloadString(data.GetDivHistory(Symbol)));

            // Check # Entries  i => 10 continue
            bool tenOrMore = divHistory.Count >= 10;

            if (tenOrMore)
            {
                var        topTen = divHistory.GetRange(0, 10);
                DailyPrice daily  = new DailyPrice(Symbol, topTen[9].ExDate.AddDays(-1).ToShortDateString());

                // Get Historical Data: Start date == index 9
                var dailyPrice = daily.GetHistoricalData();


                List <Rating> RatingList = new List <Rating>();
                //Iterate through Exdates
                for (int i = 0; i < dailyPrice.Count; i++)
                {
                    //Console.WriteLine($"{i}");
                    for (int L = 9; L > 0; L--)
                    {
                        try
                        {
                            if (dailyPrice[i].Date == topTen[L].ExDate.AddDays(-1))
                            {
                                //Console.WriteLine($"{dailyPrice[i].Date}");
                                Rating rating = new Rating();
                                var    range  = dailyPrice.GetRange(i - 6, 5);

                                for (int j = 4; j >= 0; j--)
                                {
                                    if (range[j].High >= dailyPrice[i].Close)
                                    {
                                        switch (j)
                                        {
                                        case 0:
                                            rating.Speed = 1;
                                            break;

                                        case 1:
                                            rating.Speed = 2;
                                            break;

                                        case 2:
                                            rating.Speed = 3;
                                            break;

                                        case 3:
                                            rating.Speed = 4;
                                            break;

                                        case 4:
                                            rating.Speed = 5;
                                            break;

                                        default:
                                            rating.Speed = 0;
                                            break;
                                        }
                                        break;
                                    }
                                }
                                RatingList.Add(rating);
                            }
                        }
                        catch (ArgumentOutOfRangeException)
                        {
                            Console.WriteLine("Out of Range");
                        }
                        //Console.WriteLine($"{topTen[L].ExDate}");
                    }
                }

                FinalRating.Reliability = 0;
                foreach (var ratingItem in RatingList)
                {
                    if (ratingItem.Speed > 0)
                    {
                        FinalRating.Reliability += 1;
                    }
                }
                FinalRating.Speed = SpeedAverage(RatingList);
                FinalRating.Grade = GetGrade(FinalRating.Reliability, FinalRating.Speed);

                // Stock recovery in 5 days
            }
            return(FinalRating);
        }