예제 #1
0
        public void BollingerBandsUpperUsingSmaAndStandardDeviation()
        {
            var bbmSma            = new BollingerBandsMiddleIndicator(_sma);
            var standardDeviation = new StandardDeviationIndicator(_closePrice, _timeFrame);
            var bbuSma            = new BollingerBandsUpperIndicator(bbmSma, standardDeviation);

            TaTestsUtils.AssertDecimalEquals(bbuSma.K, 2);

            TaTestsUtils.AssertDecimalEquals(bbuSma.GetValue(0), 1);
            TaTestsUtils.AssertDecimalEquals(bbuSma.GetValue(1), 2.5);
            TaTestsUtils.AssertDecimalEquals(bbuSma.GetValue(2), 3.633);
            TaTestsUtils.AssertDecimalEquals(bbuSma.GetValue(3), 4.633);
            TaTestsUtils.AssertDecimalEquals(bbuSma.GetValue(4), 4.2761);
            TaTestsUtils.AssertDecimalEquals(bbuSma.GetValue(5), 4.6094);
            TaTestsUtils.AssertDecimalEquals(bbuSma.GetValue(6), 5.633);
            TaTestsUtils.AssertDecimalEquals(bbuSma.GetValue(7), 5.2761);
            TaTestsUtils.AssertDecimalEquals(bbuSma.GetValue(8), 5.633);
            TaTestsUtils.AssertDecimalEquals(bbuSma.GetValue(9), 4.2761);

            var bbuSmAwithK = new BollingerBandsUpperIndicator(bbmSma, standardDeviation, Decimal.ValueOf("1.5"));

            TaTestsUtils.AssertDecimalEquals(bbuSmAwithK.K, 1.5);

            TaTestsUtils.AssertDecimalEquals(bbuSmAwithK.GetValue(0), 1);
            TaTestsUtils.AssertDecimalEquals(bbuSmAwithK.GetValue(1), 2.25);
            TaTestsUtils.AssertDecimalEquals(bbuSmAwithK.GetValue(2), 3.2247);
            TaTestsUtils.AssertDecimalEquals(bbuSmAwithK.GetValue(3), 4.2247);
            TaTestsUtils.AssertDecimalEquals(bbuSmAwithK.GetValue(4), 4.0404);
            TaTestsUtils.AssertDecimalEquals(bbuSmAwithK.GetValue(5), 4.3737);
            TaTestsUtils.AssertDecimalEquals(bbuSmAwithK.GetValue(6), 5.2247);
            TaTestsUtils.AssertDecimalEquals(bbuSmAwithK.GetValue(7), 5.0404);
            TaTestsUtils.AssertDecimalEquals(bbuSmAwithK.GetValue(8), 5.2247);
            TaTestsUtils.AssertDecimalEquals(bbuSmAwithK.GetValue(9), 4.0404);
        }
예제 #2
0
        public void bollingerBandsLowerUsingSMAAndStandardDeviation()
        {
            BollingerBandsMiddleIndicator bbmSMA            = new BollingerBandsMiddleIndicator(sma);
            StandardDeviationIndicator    standardDeviation = new StandardDeviationIndicator(closePrice, timeFrame);
            BollingerBandsLowerIndicator  bblSMA            = new BollingerBandsLowerIndicator(bbmSMA, standardDeviation);

            Assert.AreEqual(bblSMA.getK(), 2);

            Assert.AreEqual(bblSMA.GetValue(0), 1);
            Assert.AreEqual(bblSMA.GetValue(1), 0.5M);
            Assert.AreEqual(bblSMA.GetValue(2), 0.3670068381445479345351439502M);
            Assert.AreEqual(bblSMA.GetValue(3), 1.3670068381445479345351439502M);
            Assert.AreEqual(bblSMA.GetValue(4), 2.3905242917512699674655408505M);
            Assert.AreEqual(bblSMA.GetValue(5), 2.7238576250846033007988741839M);
            Assert.AreEqual(bblSMA.GetValue(6), 2.3670068381445479345351439502M);

            BollingerBandsLowerIndicator bblSMAwithK = new BollingerBandsLowerIndicator(bbmSMA, standardDeviation, 1.5M);

            Assert.AreEqual(bblSMAwithK.getK(), 1.5M);

            Assert.AreEqual(bblSMAwithK.GetValue(0), 1);
            Assert.AreEqual(bblSMAwithK.GetValue(1), 0.75M);
            Assert.AreEqual(bblSMAwithK.GetValue(2), 0.7752551286084109509013579626M);
            Assert.AreEqual(bblSMAwithK.GetValue(3), 1.7752551286084109509013579626M);
            Assert.AreEqual(bblSMAwithK.GetValue(4), 2.6262265521467858089324889712M);
            Assert.AreEqual(bblSMAwithK.GetValue(5), 2.9595598854801191422658223046M);
            Assert.AreEqual(bblSMAwithK.GetValue(6), 2.7752551286084109509013579626M);
        }
        public void BollingerBandWidthUsingSMAAndStandardDeviation()
        {
            SMAIndicator sma = new SMAIndicator(closePrice, 5);
            StandardDeviationIndicator standardDeviation = new StandardDeviationIndicator(closePrice, 5);

            BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma);
            BollingerBandsUpperIndicator  bbuSMA = new BollingerBandsUpperIndicator(bbmSMA, standardDeviation);
            BollingerBandsLowerIndicator  bblSMA = new BollingerBandsLowerIndicator(bbmSMA, standardDeviation);

            BollingerBandWidthIndicator bandwidth = new BollingerBandWidthIndicator(bbuSMA, bbmSMA, bblSMA);

            Assert.AreEqual(bandwidth.GetValue(0), 0.0M);
            Assert.AreEqual(bandwidth.GetValue(1), 36.363636363636363636363636360M);
            Assert.AreEqual(bandwidth.GetValue(2), 66.642313545610556218920998730M);
            Assert.AreEqual(bandwidth.GetValue(3), 60.244280375440064123683819780M);
            Assert.AreEqual(bandwidth.GetValue(4), 71.076741021144541578134348630M);
            Assert.AreEqual(bandwidth.GetValue(5), 69.939393317876184065428705400M);
            Assert.AreEqual(bandwidth.GetValue(6), 62.704283664302785713832632430M);
            Assert.AreEqual(bandwidth.GetValue(7), 56.017820550978806498453596730M);
            Assert.AreEqual(bandwidth.GetValue(8), 27.682979522960278118630842150M);
            Assert.AreEqual(bandwidth.GetValue(9), 12.649110640673517327995574180M);
            Assert.AreEqual(bandwidth.GetValue(10), 12.649110640673517327995574180M);
            Assert.AreEqual(bandwidth.GetValue(11), 24.295632895188751961975636990M);
            Assert.AreEqual(bandwidth.GetValue(12), 68.333165356240492140358775280M);
            Assert.AreEqual(bandwidth.GetValue(13), 85.14693182963200583066660912M);
            Assert.AreEqual(bandwidth.GetValue(14), 112.84810090360856581393406310M);
            Assert.AreEqual(bandwidth.GetValue(15), 108.16818718178015127023901017M);
            Assert.AreEqual(bandwidth.GetValue(16), 66.932802122726043838253762060M);
            Assert.AreEqual(bandwidth.GetValue(17), 56.519416526043901158871302720M);
            Assert.AreEqual(bandwidth.GetValue(18), 28.109134757052260728879053730M);
            Assert.AreEqual(bandwidth.GetValue(19), 32.536151189338620744206510720M);
        }
예제 #4
0
        public void BollingerBandsUpperUsingSMAAndStandardDeviation()
        {
            BollingerBandsMiddleIndicator bbmSMA            = new BollingerBandsMiddleIndicator(sma);
            StandardDeviationIndicator    standardDeviation = new StandardDeviationIndicator(closePrice, timeFrame);
            BollingerBandsUpperIndicator  bbuSMA            = new BollingerBandsUpperIndicator(bbmSMA, standardDeviation);

            Assert.AreEqual(bbuSMA.getK(), 2);

            Assert.AreEqual(bbuSMA.GetValue(0), 1);
            Assert.AreEqual(bbuSMA.GetValue(1), 2.5M);
            Assert.AreEqual(bbuSMA.GetValue(2), 3.6329931618554520654648560498M);
            Assert.AreEqual(bbuSMA.GetValue(3), 4.6329931618554520654648560498M);
            Assert.AreEqual(bbuSMA.GetValue(4), 4.2761423749153966992011258161M);
            Assert.AreEqual(bbuSMA.GetValue(5), 4.6094757082487300325344591495M);
            Assert.AreEqual(bbuSMA.GetValue(6), 5.6329931618554520654648560498M);
            Assert.AreEqual(bbuSMA.GetValue(7), 5.2761423749153966992011258161M);
            Assert.AreEqual(bbuSMA.GetValue(8), 5.6329931618554520654648560498M);
            Assert.AreEqual(bbuSMA.GetValue(9), 4.2761423749153966992011258161M);

            BollingerBandsUpperIndicator bbuSMAwithK = new BollingerBandsUpperIndicator(bbmSMA, standardDeviation, 1.5M);

            Assert.AreEqual(bbuSMAwithK.getK(), 1.5M);

            Assert.AreEqual(bbuSMAwithK.GetValue(0), 1);
            Assert.AreEqual(bbuSMAwithK.GetValue(1), 2.25M);
            Assert.AreEqual(bbuSMAwithK.GetValue(2), 3.2247448713915890490986420374M);
            Assert.AreEqual(bbuSMAwithK.GetValue(3), 4.2247448713915890490986420374M);
            Assert.AreEqual(bbuSMAwithK.GetValue(4), 4.0404401145198808577341776954M);
            Assert.AreEqual(bbuSMAwithK.GetValue(5), 4.3737734478532141910675110288M);
            Assert.AreEqual(bbuSMAwithK.GetValue(6), 5.2247448713915890490986420374M);
            Assert.AreEqual(bbuSMAwithK.GetValue(7), 5.0404401145198808577341776954M);
            Assert.AreEqual(bbuSMAwithK.GetValue(8), 5.2247448713915890490986420374M);
            Assert.AreEqual(bbuSMAwithK.GetValue(9), 4.0404401145198808577341776954M);
        }
        public void BollingerBandsLowerUsingSmaAndStandardDeviation()
        {
            var bbmSma            = new BollingerBandsMiddleIndicator(_sma);
            var standardDeviation = new StandardDeviationIndicator(_closePrice, _timeFrame);
            var bblSma            = new BollingerBandsLowerIndicator(bbmSma, standardDeviation);

            TaTestsUtils.AssertDecimalEquals(bblSma.K, 2);

            TaTestsUtils.AssertDecimalEquals(bblSma.GetValue(0), 1);
            TaTestsUtils.AssertDecimalEquals(bblSma.GetValue(1), 0.5);
            TaTestsUtils.AssertDecimalEquals(bblSma.GetValue(2), 0.367);
            TaTestsUtils.AssertDecimalEquals(bblSma.GetValue(3), 1.367);
            TaTestsUtils.AssertDecimalEquals(bblSma.GetValue(4), 2.3905);
            TaTestsUtils.AssertDecimalEquals(bblSma.GetValue(5), 2.7239);
            TaTestsUtils.AssertDecimalEquals(bblSma.GetValue(6), 2.367);

            var bblSmAwithK = new BollingerBandsLowerIndicator(bbmSma, standardDeviation, Decimal.ValueOf("1.5"));

            TaTestsUtils.AssertDecimalEquals(bblSmAwithK.K, 1.5);

            TaTestsUtils.AssertDecimalEquals(bblSmAwithK.GetValue(0), 1);
            TaTestsUtils.AssertDecimalEquals(bblSmAwithK.GetValue(1), 0.75);
            TaTestsUtils.AssertDecimalEquals(bblSmAwithK.GetValue(2), 0.7752);
            TaTestsUtils.AssertDecimalEquals(bblSmAwithK.GetValue(3), 1.7752);
            TaTestsUtils.AssertDecimalEquals(bblSmAwithK.GetValue(4), 2.6262);
            TaTestsUtils.AssertDecimalEquals(bblSmAwithK.GetValue(5), 2.9595);
            TaTestsUtils.AssertDecimalEquals(bblSmAwithK.GetValue(6), 2.7752);
        }
예제 #6
0
        public void BollingerBandWidthUsingSmaAndStandardDeviation()
        {
            var sma = new SmaIndicator(_closePrice, 5);
            var standardDeviation = new StandardDeviationIndicator(_closePrice, 5);

            var bbmSma = new BollingerBandsMiddleIndicator(sma);
            var bbuSma = new BollingerBandsUpperIndicator(bbmSma, standardDeviation);
            var bblSma = new BollingerBandsLowerIndicator(bbmSma, standardDeviation);

            var bandwidth = new BollingerBandWidthIndicator(bbuSma, bbmSma, bblSma);

            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(0), 0.0);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(1), 36.3636);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(2), 66.6423);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(3), 60.2443);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(4), 71.0767);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(5), 69.9394);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(6), 62.7043);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(7), 56.0178);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(8), 27.683);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(9), 12.6491);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(10), 12.6491);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(11), 24.2956);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(12), 68.3332);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(13), 85.1469);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(14), 112.8481);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(15), 108.1682);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(16), 66.9328);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(17), 56.5194);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(18), 28.1091);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(19), 32.5362);
        }
        public void bollingerBandsMiddleUsingSMA()
        {
            SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(data), 3);
            BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma);

            for (int i = 0; i < data.GetBarCount(); i++)
            {
                Assert.AreEqual(sma.GetValue(i), bbmSMA.GetValue(i));
            }
        }
        public void BollingerBandsMiddleUsingSma()
        {
            var sma    = new SmaIndicator(new ClosePriceIndicator(_data), 3);
            var bbmSma = new BollingerBandsMiddleIndicator(sma);

            for (var i = 0; i < _data.TickCount; i++)
            {
                Assert.AreEqual(sma.GetValue(i), bbmSma.GetValue(i));
            }
        }
예제 #9
0
 public BollingerBandWidthIndicator(BollingerBandsUpperIndicator bbu, BollingerBandsMiddleIndicator bbm, BollingerBandsLowerIndicator bbl) : base(bbm.TimeSeries)
 {
     _bbu = bbu;
     _bbm = bbm;
     _bbl = bbl;
 }
 public BollingerBandsUpperIndicator(BollingerBandsMiddleIndicator bbm, IIndicator <Decimal> indicator, Decimal k) : base(indicator)
 {
     _bbm       = bbm;
     _indicator = indicator;
     _k         = k;
 }
 public BollingerBandsUpperIndicator(BollingerBandsMiddleIndicator bbm, IIndicator <Decimal> indicator) : this(bbm, indicator, Decimal.Two)
 {
 }