Exemplo n.º 1
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 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);
        }
        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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
 public BollingerBandWidthIndicator(BollingerBandsUpperIndicator bbu, BollingerBandsMiddleIndicator bbm, BollingerBandsLowerIndicator bbl) : base(bbm.TimeSeries)
 {
     _bbu = bbu;
     _bbm = bbm;
     _bbl = bbl;
 }