コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
0
 protected override Decimal Calculate(int index)
 {
     return(_bbu.GetValue(index).Minus(_bbl.GetValue(index)).DividedBy(_bbm.GetValue(index)).MultipliedBy(Decimal.Hundred));
 }