Пример #1
0
        public void PrepareHistoryTest()
        {
            IEnumerable <Quote> newHistory = History.GetHistory();

            // confirm no-Index before cleaning
            Assert.IsFalse(newHistory.Any(x => x.Index != null));

            // clean
            IEnumerable <Quote> h = Cleaners.PrepareHistory(newHistory);

            // assertions

            // should always be the same number of results as there is history
            Assert.AreEqual(502, h.Count());

            // should always have index
            Assert.IsFalse(h.Where(x => x.Index == null || x.Index <= 0).Any());

            // last index should be 502
            Quote r = newHistory
                      .Where(x => x.Date == DateTime.ParseExact("12/31/2018", "MM/dd/yyyy", englishCulture))
                      .FirstOrDefault();

            Assert.AreEqual(502, r.Index);

            // ensure expected List address
            List <Quote> historyList = h.ToList();

            Assert.AreEqual(502, historyList[501].Index);
        }
        public void CleanHistory()
        {
            IEnumerable <Quote> history = History.GetHistory();

            Cleaners.PrepareHistory(history);

            Indicator.GetSma(history, 5);
        }
        public void ReadQuoteClass()
        {
            IEnumerable <Quote> history = History.GetHistory();
            List <Quote>        h       = Cleaners.PrepareHistory(history);

            Quote f = h.FirstOrDefault();

            Console.WriteLine("Date:{0},Close:{1}", f.Date, f.Close);
        }
Пример #4
0
        public void CleanerTest()
        {
            List <Quote> h = Cleaners.PrepareHistory(history);

            // assertions

            // should always be the same number of results as there is history
            Assert.AreEqual(502, h.Count);
        }
Пример #5
0
        public void CleanerTest()
        {
            List <Quote> h = Cleaners.PrepareHistory(history);

            // assertions

            // should always be the same number of results as there is history
            Assert.AreEqual(502, h.Count);

            // should always have index
            Assert.IsFalse(h.Where(x => x.Index == null || x.Index <= 0).Any());
        }
Пример #6
0
        public void CutHistoryTest()
        {
            // if history post-cleaning, is cut down in size it should not corrupt the results

            int i = 0;
            IEnumerable <Quote> history = History.GetHistory(200);
            IEnumerable <Quote> h       = Cleaners.PrepareHistory(history);

            // assertions

            // should be 200 periods, initially
            Assert.AreEqual(200, h.Count());

            // should always have index
            Assert.IsFalse(h.Where(x => x.Index == null || x.Index <= 0).Any());


            // should be 20 results and no index corruption
            IEnumerable <RsiResult> r1 = Indicator.GetRsi(h.TakeLast(20), 14);

            Assert.AreEqual(20, r1.Count());

            i = 1;
            foreach (RsiResult x in r1)
            {
                Assert.AreEqual(i++, x.Index);
            }

            // should be 50 results and no index corruption
            IEnumerable <RsiResult> r2 = Indicator.GetRsi(h.TakeLast(50), 14);

            Assert.AreEqual(50, r2.Count());

            i = 1;
            foreach (RsiResult x in r2)
            {
                Assert.AreEqual(i++, x.Index);
            }

            // should be original 200 periods and no index corruption, after temp mods
            Assert.AreEqual(200, h.Count());

            i = 1;
            foreach (Quote x in h)
            {
                Assert.AreEqual(i++, x.Index);
            }
        }
Пример #7
0
        public void PrepareHistoryTest()
        {
            IEnumerable <Quote> h = Cleaners.PrepareHistory(history);

            // assertions

            // should always be the same number of results as there is history
            Assert.AreEqual(502, h.Count());

            // should always have index
            Assert.IsFalse(h.Where(x => x.Index == null || x.Index <= 0).Any());

            // last index should be 502
            Quote r = history.Where(x => x.Date == DateTime.ParseExact("12/31/2018", "MM/dd/yyyy", null)).FirstOrDefault();

            Assert.AreEqual(502, r.Index);
        }
        public void DerivedQuoteClassLinq()
        {
            IEnumerable <Quote> history = History.GetHistory();

            Cleaners.PrepareHistory(history);

            // can use a derive Quote class using Linq

            IEnumerable <MyQuote> myHistory = history
                                              .Select(x => new MyQuote
            {
                Date       = x.Date,
                MyClose    = x.Close,
                MyProperty = false
            });

            Assert.IsTrue(myHistory.Any());
        }
Пример #9
0
        public void ResetHistoryTest()
        {
            // if history post-cleaning, is cut down in size it should not corrupt the results

            IEnumerable <Quote> history = History.GetHistory(200);
            IEnumerable <Quote> h       = Cleaners.PrepareHistory(history);

            // assertions

            // should be 200 periods, initially
            Assert.AreEqual(200, h.Count());

            // should always have index
            Assert.IsFalse(h.Where(x => x.Index == null || x.Index <= 0).Any());

            h.RemoveIndex();

            // should not have index after reset
            Assert.IsFalse(h.Where(x => x.Index != null).Any());
        }
Пример #10
0
        public void PrepareLongHistoryTest()
        {
            IEnumerable <Quote> historyLong = History.GetHistoryLong();

            IEnumerable <Quote> h = Cleaners.PrepareHistory(historyLong);

            // assertions

            // should always be the same number of results as there is history
            Assert.AreEqual(5285, h.Count());

            // should always have index
            Assert.IsFalse(h.Where(x => x.Index == null || x.Index <= 0).Any());

            // last index should be 502
            Quote r = historyLong
                      .Where(x => x.Date == DateTime.ParseExact("09/04/2020", "MM/dd/yyyy", cultureProvider))
                      .FirstOrDefault();

            Assert.AreEqual(5285, r.Index);
        }
Пример #11
0
        public void DuplicateHistory()
        {
            List <Quote> badHistory = new List <Quote>
            {
                new Quote {
                    Date = DateTime.ParseExact("2017-01-03", "yyyy-MM-dd", cultureProvider), Open = 214.86m, High = 220.33m, Low = 210.96m, Close = 216.99m, Volume = 5923254
                },
                new Quote {
                    Date = DateTime.ParseExact("2017-01-04", "yyyy-MM-dd", cultureProvider), Open = 214.75m, High = 228.00m, Low = 214.31m, Close = 226.99m, Volume = 11213471
                },
                new Quote {
                    Date = DateTime.ParseExact("2017-01-05", "yyyy-MM-dd", cultureProvider), Open = 226.42m, High = 227.48m, Low = 221.95m, Close = 226.75m, Volume = 5911695
                },
                new Quote {
                    Date = DateTime.ParseExact("2017-01-06", "yyyy-MM-dd", cultureProvider), Open = 226.93m, High = 230.31m, Low = 225.45m, Close = 229.01m, Volume = 5527893
                },
                new Quote {
                    Date = DateTime.ParseExact("2017-01-06", "yyyy-MM-dd", cultureProvider), Open = 228.97m, High = 231.92m, Low = 228.00m, Close = 231.28m, Volume = 3979484
                }
            };

            Cleaners.PrepareHistory(badHistory);
        }
Пример #12
0
        public void DuplicateHistory()
        {
            List <Quote> badHistory = new List <Quote>
            {
                new Quote {
                    Date = DateTime.Parse("2017-01-03"), Open = (decimal)214.86, High = (decimal)220.33, Low = (decimal)210.96, Close = (decimal)216.99, Volume = 5923254
                },
                new Quote {
                    Date = DateTime.Parse("2017-01-04"), Open = (decimal)214.75, High = 228, Low = (decimal)214.31, Close = (decimal)226.99, Volume = 11213471
                },
                new Quote {
                    Date = DateTime.Parse("2017-01-05"), Open = (decimal)226.42, High = (decimal)227.48, Low = (decimal)221.95, Close = (decimal)226.75, Volume = 5911695
                },
                new Quote {
                    Date = DateTime.Parse("2017-01-06"), Open = (decimal)226.93, High = (decimal)230.31, Low = (decimal)225.45, Close = (decimal)229.01, Volume = 5527893
                },
                new Quote {
                    Date = DateTime.Parse("2017-01-06"), Open = (decimal)228.97, High = (decimal)231.92, Low = 228, Close = (decimal)231.28, Volume = 3979484
                },
            };

            Cleaners.PrepareHistory(badHistory);
        }
Пример #13
0
        public void NoHistory()
        {
            List <Quote> badHistory = new List <Quote>();

            Cleaners.PrepareHistory(badHistory);
        }
Пример #14
0
 public object PrepareHistory()
 {
     return(Cleaners.PrepareHistory(h));
 }
Пример #15
0
        public void BadHistoryEmptyTest()
        {
            List <Quote> badHistory = new List <Quote>();

            Cleaners.PrepareHistory(badHistory);
        }