Пример #1
0
        public void getValueOnDeepIndicesShouldNotCauseStackOverflow()
        {
            ITimeSeries series = new MockTimeSeries();

            series.SetMaximumBarCount(5000);
            Assert.AreEqual(5000, series.GetBarCount());

            KAMAIndicator kama = new KAMAIndicator(new ClosePriceIndicator(series), 10, 2, 30);

            Assert.AreEqual(kama.GetValue(3000), 2999.75M);
        }
Пример #2
0
        public void getValueWithOldResultsRemoval()
        {
            decimal[] data = new decimal[20];
            Arrays.fill(data, 1);
            ITimeSeries  timeSeries = new MockTimeSeries(data);
            SMAIndicator sma        = new SMAIndicator(new ClosePriceIndicator(timeSeries), 10);

            Assert.AreEqual(sma.GetValue(5), 1);
            Assert.AreEqual(sma.GetValue(10), 1);
            timeSeries.SetMaximumBarCount(12);
            Assert.AreEqual(sma.GetValue(19), 1);
        }
Пример #3
0
        public void getValueOnResultsCalculatedFromRemovedBarsShouldReturnFirstRemainingResult()
        {
            ITimeSeries timeSeries = new MockTimeSeries(1, 1, 1, 1, 1);

            timeSeries.SetMaximumBarCount(3);
            Assert.AreEqual(2, timeSeries.GetRemovedBarsCount());

            SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(timeSeries), 2);

            for (int i = 0; i < 5; i++)
            {
                Assert.AreEqual(1, sma.GetValue(i), $"failed for {i}");
            }
        }
Пример #4
0
        public void strategyExecutionOnCachedIndicatorAndLimitedTimeSeries()
        {
            ITimeSeries  timeSeries = new MockTimeSeries(0, 1, 2, 3, 4, 5, 6, 7);
            SMAIndicator sma        = new SMAIndicator(new ClosePriceIndicator(timeSeries), 2);

            // Theoretical values for SMA(2) cache: 0, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5
            timeSeries.SetMaximumBarCount(6);
            // Theoretical values for SMA(2) cache: null, null, 2, 2.5, 3.5, 4.5, 5.5, 6.5

            IStrategy strategy = new BaseStrategy(
                new OverIndicatorRule(sma, Decimals.THREE),
                new UnderIndicatorRule(sma, Decimals.THREE)
                );

            // Theoretical shouldEnter results: false, false, false, false, true, true, true, true
            // Theoretical shouldExit results: false, false, true, true, false, false, false, false

            // As we return the first bar/result found for the removed bars:
            // -> Approximated values for ClosePrice cache: 2, 2, 2, 3, 4, 5, 6, 7
            // -> Approximated values for SMA(2) cache: 2, 2, 2, 2.5, 3.5, 4.5, 5.5, 6.5

            // Then enters/exits are also approximated:
            // -> shouldEnter results: false, false, false, false, true, true, true, true
            // -> shouldExit results: true, true, true, true, false, false, false, false

            Assert.IsFalse(strategy.ShouldEnter(0));
            Assert.IsTrue(strategy.ShouldExit(0));
            Assert.IsFalse(strategy.ShouldEnter(1));
            Assert.IsTrue(strategy.ShouldExit(1));
            Assert.IsFalse(strategy.ShouldEnter(2));
            Assert.IsTrue(strategy.ShouldExit(2));
            Assert.IsFalse(strategy.ShouldEnter(3));
            Assert.IsTrue(strategy.ShouldExit(3));
            Assert.IsTrue(strategy.ShouldEnter(4));
            Assert.IsFalse(strategy.ShouldExit(4));
            Assert.IsTrue(strategy.ShouldEnter(5));
            Assert.IsFalse(strategy.ShouldExit(5));
            Assert.IsTrue(strategy.ShouldEnter(6));
            Assert.IsFalse(strategy.ShouldExit(6));
            Assert.IsTrue(strategy.ShouldEnter(7));
            Assert.IsFalse(strategy.ShouldExit(7));
        }