Exemple #1
0
        static void Main(string[] args)
        {
            //HtmlWeb web = new HtmlWeb();
            WebClient       webClient = new WebClient();
            DividendHistory dividend  = new DividendHistory();
            DataURL         data      = new DataURL();


            List <string> Week = new List <string>()
            {
                "2020-01-21", "2020-01-22", "2020-01-23", "2020-01-24", "2020-01-27", "2020-01-28", "2020-01-29", "2020-01-30", "2020-01-31"
            };

            List <string> fileList = new List <string>();

            foreach (var day in Week)
            {
                Console.WriteLine(day);
                Calendar calendar = new Calendar(day);
                var      stocks   = calendar.GetCalendar();



                //DailyPrice daily = new DailyPrice("aapl", "01/01/2018");

                // daily.GetHistoricalData();

                fileList.Add("Ex-Date,Symbol, Speed, Reliability, Grade, Dividend, Yield");
                foreach (var stock in stocks)
                {
                    CurrentPrice currentPrice = new CurrentPrice(stock.Symbol);
                    Rating       rating       = new Rating(stock.Symbol);
                    var          url          = data.GetDivHistory(stock.Symbol);
                    var          history      = webClient.DownloadString(url);
                    var          records      = dividend.GetHistory(history);

                    var final = rating.GetRating();
                    fileList.Add($"{stock.ExDate},{stock.Symbol},{Math.Round(final.Speed, 1)},{Math.Round(final.Reliability, 1)},{final.Grade},{records[0].Amount:C},{records[0].Amount / currentPrice.GetInfo():P}");
                    Console.WriteLine(stock.Symbol);
                }

                //if (final.Reliability > 6 && records[0].Amount / currentPrice.GetInfo() > .02)
                //{

                //}
            }
            File.WriteAllLines("Dividend.csv", fileList);
            Console.ReadLine();
        }
Exemple #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);
        }