コード例 #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 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);
        }
コード例 #3
0
        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 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);
        }
コード例 #5
0
 public BollingerBandWidthIndicator(BollingerBandsUpperIndicator bbu, BollingerBandsMiddleIndicator bbm, BollingerBandsLowerIndicator bbl) : base(bbm.TimeSeries)
 {
     _bbu = bbu;
     _bbm = bbm;
     _bbl = bbl;
 }