Beispiel #1
0
    public void Standard()
    {
        List <RsiResult> results = quotes.GetRsi(14).ToList();

        // assertions

        // proper quantities
        // should always be the same number of results as there is quotes
        Assert.AreEqual(502, results.Count);
        Assert.AreEqual(488, results.Where(x => x.Rsi != null).Count());

        // sample values
        RsiResult r1 = results[13];

        Assert.AreEqual(null, r1.Rsi);

        RsiResult r2 = results[14];

        Assert.AreEqual(62.0541, Math.Round((double)r2.Rsi, 4));

        RsiResult r3 = results[249];

        Assert.AreEqual(70.9368, Math.Round((double)r3.Rsi, 4));

        RsiResult r4 = results[501];

        Assert.AreEqual(42.0773, Math.Round((double)r4.Rsi, 4));
    }
Beispiel #2
0
        public void GetRsi()
        {
            int lookbackPeriod       = 14;
            List <RsiResult> results = Indicator.GetRsi(history, lookbackPeriod).ToList();

            // assertions

            // proper quantities
            // should always be the same number of results as there is history
            Assert.AreEqual(502, results.Count);
            Assert.AreEqual(488, results.Where(x => x.Rsi != null).Count());

            // sample values
            RsiResult r1 = results[501];

            Assert.AreEqual(42.0773m, Math.Round((decimal)r1.Rsi, 4));

            RsiResult r2 = results[249];

            Assert.AreEqual(70.9368m, Math.Round((decimal)r2.Rsi, 4));

            RsiResult r3 = results[14];

            Assert.AreEqual(62.0541m, Math.Round((decimal)r3.Rsi, 4));

            RsiResult r4 = results[13];

            Assert.AreEqual(null, r4.Rsi);
        }
Beispiel #3
0
    // STOCHASTIC RSI
    /// <include file='./info.xml' path='indicator/*' />
    ///
    public static IEnumerable <StochRsiResult> GetStochRsi <TQuote>(
        this IEnumerable <TQuote> quotes,
        int rsiPeriods,
        int stochPeriods,
        int signalPeriods,
        int smoothPeriods = 1)
        where TQuote : IQuote
    {
        // check parameter arguments
        ValidateStochRsi(rsiPeriods, stochPeriods, signalPeriods, smoothPeriods);

        // initialize
        List <RsiResult>      rsiResults = GetRsi(quotes, rsiPeriods).ToList();
        List <StochRsiResult> results    = new(rsiResults.Count);

        // convert rsi to quote format
        List <Quote> rsiQuotes = rsiResults
                                 .Where(x => x.Rsi != null)
                                 .Select(x => new Quote
        {
            Date  = x.Date,
            High  = (decimal)x.Rsi,
            Low   = (decimal)x.Rsi,
            Close = (decimal)x.Rsi
        })
                                 .ToList();

        // get Stochastic of RSI
        List <StochResult> stoResults =
            GetStoch(rsiQuotes, stochPeriods, signalPeriods, smoothPeriods)
            .ToList();

        // compose
        for (int i = 0; i < rsiResults.Count; i++)
        {
            RsiResult r     = rsiResults[i];
            int       index = i + 1;

            StochRsiResult result = new()
            {
                Date = r.Date
            };

            if (index >= rsiPeriods + stochPeriods)
            {
                StochResult sto = stoResults[index - rsiPeriods - 1];

                result.StochRsi = sto.Oscillator;
                result.Signal   = sto.Signal;
            }

            results.Add(result);
        }

        return(results);
    }
    public void Rsi()
    {
        foreach (int qty in QuotesQuantities)
        {
            IEnumerable <Quote>     quotes = TestData.GetLongish(10 + qty);
            IEnumerable <RsiResult> r      = quotes.GetRsi(14);

            RsiResult l = r.LastOrDefault();
            Console.WriteLine(
                "RSI(14) on {0:d} with {1,4} periods: {2:N8}",
                l.Date, quotes.Count(), l.Rsi);
        }
    }
Beispiel #5
0
    public void Removed()
    {
        List <RsiResult> results = quotes.GetRsi(14)
                                   .RemoveWarmupPeriods()
                                   .ToList();

        // assertions
        Assert.AreEqual(502 - (10 * 14), results.Count);

        RsiResult last = results.LastOrDefault();

        Assert.AreEqual(42.0773, Math.Round((double)last.Rsi, 4));
    }
        public void Convergence()
        {
            int lookbackPeriod = 14;

            foreach (int qty in convergeQuantities.Where(q => q > 100 - lookbackPeriod))
            {
                IEnumerable <Quote>     h = HistoryTestData.GetLong(lookbackPeriod + qty);
                IEnumerable <RsiResult> r = Indicator.GetRsi(h, lookbackPeriod);

                RsiResult l = r.LastOrDefault();
                Console.WriteLine("RSI({0}) on {1:d} with {2,4} periods: {3:N8}",
                                  lookbackPeriod, l.Date, h.Count(), l.Rsi);
            }
        }
        public void GetRsiTest()
        {
            int lookbackPeriod = 14;
            IEnumerable <RsiResult> results = Indicator.GetRsi(history, lookbackPeriod);

            // assertions

            // proper quantities
            // should always be the same number of results as there is history
            Assert.AreEqual(502, results.Count());
            Assert.AreEqual(488, results.Where(x => x.Rsi != null).Count());

            // sample value
            RsiResult r = results.Where(x => x.Index == 502).FirstOrDefault();

            Assert.AreEqual(42.0773m, Math.Round((decimal)r.Rsi, 4));
        }
Beispiel #8
0
    // CONNORS RSI
    /// <include file='./info.xml' path='indicator/*' />
    ///
    public static IEnumerable <ConnorsRsiResult> GetConnorsRsi <TQuote>(
        this IEnumerable <TQuote> quotes,
        int rsiPeriods    = 3,
        int streakPeriods = 2,
        int rankPeriods   = 100)
        where TQuote : IQuote
    {
        // convert quotes
        List <BasicD> bdList = quotes.ConvertToBasic(CandlePart.Close);

        // check parameter arguments
        ValidateConnorsRsi(rsiPeriods, streakPeriods, rankPeriods);

        // initialize
        List <ConnorsRsiResult> results = CalcConnorsRsiBaseline(bdList, rsiPeriods, rankPeriods);
        int startPeriod = Math.Max(rsiPeriods, Math.Max(streakPeriods, rankPeriods)) + 2;

        // RSI of streak
        List <BasicD> bdStreak = results
                                 .Where(x => x.Streak != null)
                                 .Select(x => new BasicD {
            Date = x.Date, Value = (double)x.Streak
        })
                                 .ToList();

        List <RsiResult> rsiStreakResults = CalcRsi(bdStreak, streakPeriods);

        // compose final results
        for (int p = streakPeriods + 2; p < results.Count; p++)
        {
            ConnorsRsiResult r = results[p];
            RsiResult        k = rsiStreakResults[p - 1];

            r.RsiStreak = k.Rsi;

            if (p + 1 >= startPeriod)
            {
                r.ConnorsRsi = (r.RsiClose + r.RsiStreak + r.PercentRank) / 3;
            }
        }

        return(results);
    }
Beispiel #9
0
        public void GetRsiTest()
        {
            int lookbackPeriod = 14;
            IEnumerable <RsiResult> results = Indicator.GetRsi(history, lookbackPeriod);

            // assertions

            // proper quantities
            // should always be the same number of results as there is history
            Assert.AreEqual(502, results.Count());
            Assert.AreEqual(488, results.Where(x => x.Rsi != null).Count());
            Assert.AreEqual(487, results.Where(x => x.IsIncreasing != null).Count());

            // sample value
            RsiResult r = results.Where(x => x.Date == DateTime.ParseExact("12/31/2018", "MM/dd/yyyy", null)).FirstOrDefault();

            Assert.AreEqual((decimal)42.0773, Math.Round((decimal)r.Rsi, 4));
            Assert.AreEqual(true, r.IsIncreasing);
        }
Beispiel #10
0
        public void GetRsiSmall()
        {
            int lookbackPeriod       = 1;
            List <RsiResult> results = Indicator.GetRsi(history, lookbackPeriod).ToList();

            // assertions

            // proper quantities
            // should always be the same number of results as there is history
            Assert.AreEqual(502, results.Count);
            Assert.AreEqual(501, results.Where(x => x.Rsi != null).Count());

            // sample values
            RsiResult r1 = results[28];

            Assert.AreEqual(100m, Math.Round((decimal)r1.Rsi, 4));

            RsiResult r2 = results[52];

            Assert.AreEqual(0m, Math.Round((decimal)r2.Rsi, 4));
        }
        public void GetRsiSmallPeriodTest()
        {
            int lookbackPeriod = 1;
            IEnumerable <RsiResult> results = Indicator.GetRsi(history, lookbackPeriod);

            // assertions

            // proper quantities
            // should always be the same number of results as there is history
            Assert.AreEqual(502, results.Count());
            Assert.AreEqual(501, results.Where(x => x.Rsi != null).Count());

            // sample values
            RsiResult r1 = results.Where(x => x.Index == 29).FirstOrDefault();

            Assert.AreEqual(100m, Math.Round((decimal)r1.Rsi, 4));

            RsiResult r2 = results.Where(x => x.Index == 53).FirstOrDefault();

            Assert.AreEqual(0m, Math.Round((decimal)r2.Rsi, 4));
        }
Beispiel #12
0
    public void SmallLookback()
    {
        int lookbackPeriods      = 1;
        List <RsiResult> results = quotes.GetRsi(lookbackPeriods)
                                   .ToList();

        // assertions

        // proper quantities
        // should always be the same number of results as there is quotes
        Assert.AreEqual(502, results.Count);
        Assert.AreEqual(501, results.Where(x => x.Rsi != null).Count());

        // sample values
        RsiResult r1 = results[28];

        Assert.AreEqual(100, r1.Rsi);

        RsiResult r2 = results[52];

        Assert.AreEqual(0, r2.Rsi);
    }