Ejemplo n.º 1
0
    // STARC BANDS
    /// <include file='./info.xml' path='indicator/*' />
    ///
    public static IEnumerable <StarcBandsResult> GetStarcBands <TQuote>(
        this IEnumerable <TQuote> quotes,
        int smaPeriods     = 20,
        decimal multiplier = 2,
        int atrPeriods     = 10)
        where TQuote : IQuote
    {
        // check parameter arguments
        ValidateStarcBands(smaPeriods, multiplier, atrPeriods);

        // initialize
        List <AtrResult>        atrResults = GetAtr(quotes, atrPeriods).ToList();
        List <StarcBandsResult> results    = GetSma(quotes, smaPeriods)
                                             .Select(x => new StarcBandsResult
        {
            Date       = x.Date,
            Centerline = x.Sma
        })
                                             .ToList();

        int lookbackPeriods = Math.Max(smaPeriods, atrPeriods);

        // roll through quotes
        for (int i = lookbackPeriods - 1; i < results.Count; i++)
        {
            StarcBandsResult r = results[i];

            AtrResult a = atrResults[i];

            r.UpperBand = r.Centerline + (multiplier * a.Atr);
            r.LowerBand = r.Centerline - (multiplier * a.Atr);
        }

        return(results);
    }
Ejemplo n.º 2
0
        public void Convergence()
        {
            foreach (int qty in convergeQuantities)
            {
                IEnumerable <Quote>            h = History.GetHistoryLong(200 + qty);
                IEnumerable <StarcBandsResult> r = Indicator.GetStarcBands(h, 100);

                StarcBandsResult l = r.LastOrDefault();
                Console.WriteLine("STARC UPPER on {0:d} with {1,4} periods: {2:N8}",
                                  l.Date, h.Count(), l.UpperBand);
            }
        }
Ejemplo n.º 3
0
    public void StarcBands()
    {
        foreach (int qty in QuotesQuantities)
        {
            IEnumerable <Quote>            quotes = TestData.GetLongish(10 + qty);
            IEnumerable <StarcBandsResult> r      = quotes.GetStarcBands(20);

            StarcBandsResult l = r.LastOrDefault();
            Console.WriteLine(
                "STARC UPPER on {0:d} with {1,4} periods: {2:N8}",
                l.Date, quotes.Count(), l.UpperBand);
        }
    }
Ejemplo n.º 4
0
    public void Standard()
    {
        int smaPeriods      = 20;
        int multiplier      = 2;
        int atrPeriods      = 14;
        int lookbackPeriods = Math.Max(smaPeriods, atrPeriods);

        List <StarcBandsResult> results =
            quotes.GetStarcBands(smaPeriods, multiplier, atrPeriods)
            .ToList();

        // assertions

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

        // sample value
        StarcBandsResult r1 = results[18];

        Assert.AreEqual(null, r1.Centerline);
        Assert.AreEqual(null, r1.UpperBand);
        Assert.AreEqual(null, r1.LowerBand);

        StarcBandsResult r2 = results[19];

        Assert.AreEqual(214.5250m, Math.Round((decimal)r2.Centerline, 4));
        Assert.AreEqual(217.2831m, Math.Round((decimal)r2.UpperBand, 4));
        Assert.AreEqual(211.7669m, Math.Round((decimal)r2.LowerBand, 4));

        StarcBandsResult r3 = results[249];

        Assert.AreEqual(255.5500m, Math.Round((decimal)r3.Centerline, 4));
        Assert.AreEqual(258.2261m, Math.Round((decimal)r3.UpperBand, 4));
        Assert.AreEqual(252.8739m, Math.Round((decimal)r3.LowerBand, 4));

        StarcBandsResult r4 = results[485];

        Assert.AreEqual(265.4855m, Math.Round((decimal)r4.Centerline, 4));
        Assert.AreEqual(275.1161m, Math.Round((decimal)r4.UpperBand, 4));
        Assert.AreEqual(255.8549m, Math.Round((decimal)r4.LowerBand, 4));

        StarcBandsResult r5 = results[501];

        Assert.AreEqual(251.8600m, Math.Round((decimal)r5.Centerline, 4));
        Assert.AreEqual(264.1595m, Math.Round((decimal)r5.UpperBand, 4));
        Assert.AreEqual(239.5605m, Math.Round((decimal)r5.LowerBand, 4));
    }
Ejemplo n.º 5
0
    public void Removed()
    {
        int smaPeriods      = 20;
        int multiplier      = 2;
        int atrPeriods      = 14;
        int lookbackPeriods = Math.Max(smaPeriods, atrPeriods);

        List <StarcBandsResult> results =
            quotes.GetStarcBands(smaPeriods, multiplier, atrPeriods)
            .RemoveWarmupPeriods()
            .ToList();

        // assertions
        Assert.AreEqual(502 - (lookbackPeriods + 150), results.Count);

        StarcBandsResult last = results.LastOrDefault();

        Assert.AreEqual(251.8600m, Math.Round((decimal)last.Centerline, 4));
        Assert.AreEqual(264.1595m, Math.Round((decimal)last.UpperBand, 4));
        Assert.AreEqual(239.5605m, Math.Round((decimal)last.LowerBand, 4));
    }