public void SetUp()
        {
            IList <Tick> ticks = new List <Tick>
            {
                // open, close, high, low
                GenerateTick.From(44.98, 45.05, 45.17, 44.96),
                GenerateTick.From(45.05, 45.10, 45.15, 44.99),
                GenerateTick.From(45.11, 45.19, 45.32, 45.11),
                GenerateTick.From(45.19, 45.14, 45.25, 45.04),
                GenerateTick.From(45.12, 45.15, 45.20, 45.10),
                GenerateTick.From(45.15, 45.14, 45.20, 45.10),
                GenerateTick.From(45.13, 45.10, 45.16, 45.07),
                GenerateTick.From(45.12, 45.15, 45.22, 45.10),
                GenerateTick.From(45.15, 45.22, 45.27, 45.14),
                GenerateTick.From(45.24, 45.43, 45.45, 45.20),
                GenerateTick.From(45.43, 45.44, 45.50, 45.39),
                GenerateTick.From(45.43, 45.55, 45.60, 45.35),
                GenerateTick.From(45.58, 45.55, 45.61, 45.39),
                GenerateTick.From(45.45, 45.01, 45.55, 44.80),
                GenerateTick.From(45.03, 44.23, 45.04, 44.17),
                GenerateTick.From(44.23, 43.95, 44.29, 43.81),
                GenerateTick.From(43.91, 43.08, 43.99, 43.08),
                GenerateTick.From(43.07, 43.55, 43.65, 43.06),
                GenerateTick.From(43.56, 43.95, 43.99, 43.53),
                GenerateTick.From(43.93, 44.47, 44.58, 43.93)
            };

            _data = new TimeSeries(ticks);
        }
        public void SetUp()
        {
            IList <Tick> ticks = new List <Tick>();

            // close, volume
            ticks.Add(GenerateTick.From(6, 100));
            ticks.Add(GenerateTick.From(7, 105));
            ticks.Add(GenerateTick.From(9, 130));
            ticks.Add(GenerateTick.From(12, 160));
            ticks.Add(GenerateTick.From(11, 150));
            ticks.Add(GenerateTick.From(10, 130));
            ticks.Add(GenerateTick.From(11, 95));
            ticks.Add(GenerateTick.From(13, 120));
            ticks.Add(GenerateTick.From(15, 180));
            ticks.Add(GenerateTick.From(12, 160));
            ticks.Add(GenerateTick.From(8, 150));
            ticks.Add(GenerateTick.From(4, 200));
            ticks.Add(GenerateTick.From(3, 150));
            ticks.Add(GenerateTick.From(4, 85));
            ticks.Add(GenerateTick.From(3, 70));
            ticks.Add(GenerateTick.From(5, 90));
            ticks.Add(GenerateTick.From(8, 100));
            ticks.Add(GenerateTick.From(9, 95));
            ticks.Add(GenerateTick.From(11, 110));
            ticks.Add(GenerateTick.From(10, 95));

            _data   = new TimeSeries(ticks);
            _close  = new ClosePriceIndicator(_data);
            _volume = new VolumeIndicator(_data, 2);
        }
Beispiel #3
0
        public void AverageDirectionalMovement()
        {
            var tick1 = GenerateTick.From(0, 0, 13, 7);
            var tick2 = GenerateTick.From(0, 0, 11, 5);
            var tick3 = GenerateTick.From(0, 0, 15, 3);
            var tick4 = GenerateTick.From(0, 0, 14, 2);
            var tick5 = GenerateTick.From(0, 0, 13, 0.2);

            IList <Tick> ticks = new List <Tick>();

            ticks.Add(tick1);
            ticks.Add(tick2);
            ticks.Add(tick3);
            ticks.Add(tick4);
            ticks.Add(tick5);

            var series  = GenerateTimeSeries.From(ticks);
            var admdown = new AverageDirectionalMovementDownIndicator(series, 3);

            TaTestsUtils.AssertDecimalEquals(admdown.GetValue(0), 1);
            TaTestsUtils.AssertDecimalEquals(admdown.GetValue(1), 4d / 3);
            TaTestsUtils.AssertDecimalEquals(admdown.GetValue(2), 4d / 3 * 2d / 3);
            TaTestsUtils.AssertDecimalEquals(admdown.GetValue(3), (4d / 3 * 2d / 3) * 2d / 3 + 1d / 3);
            TaTestsUtils.AssertDecimalEquals(admdown.GetValue(4), ((4d / 3 * 2d / 3) * 2d / 3 + 1d / 3) * 2d / 3 + 1.8 * 1d / 3);
        }
Beispiel #4
0
        public void GetValue()
        {
            IList <Tick> ticks = new List <Tick>();

            ticks.Add(GenerateTick.From(1355.69, 2739.55));
            ticks.Add(GenerateTick.From(1325.51, 3119.46));
            ticks.Add(GenerateTick.From(1335.02, 3466.88));
            ticks.Add(GenerateTick.From(1313.72, 2577.12));
            ticks.Add(GenerateTick.From(1319.99, 2480.45));
            ticks.Add(GenerateTick.From(1331.85, 2329.79));
            ticks.Add(GenerateTick.From(1329.04, 2793.07));
            ticks.Add(GenerateTick.From(1362.16, 3378.78));
            ticks.Add(GenerateTick.From(1365.51, 2417.59));
            ticks.Add(GenerateTick.From(1374.02, 1442.81));
            TimeSeries series = GenerateTimeSeries.From(ticks);

            var nvi = new NviIndicator(series);

            TaTestsUtils.AssertDecimalEquals(nvi.GetValue(0), 1000);
            TaTestsUtils.AssertDecimalEquals(nvi.GetValue(1), 1000);
            TaTestsUtils.AssertDecimalEquals(nvi.GetValue(2), 1000);
            TaTestsUtils.AssertDecimalEquals(nvi.GetValue(3), 984.0452);
            TaTestsUtils.AssertDecimalEquals(nvi.GetValue(4), 988.7417);
            TaTestsUtils.AssertDecimalEquals(nvi.GetValue(5), 997.6255);
            TaTestsUtils.AssertDecimalEquals(nvi.GetValue(6), 997.6255);
            TaTestsUtils.AssertDecimalEquals(nvi.GetValue(7), 997.6255);
            TaTestsUtils.AssertDecimalEquals(nvi.GetValue(8), 1000.079);
            TaTestsUtils.AssertDecimalEquals(nvi.GetValue(9), 1006.3116);
        }
Beispiel #5
0
        public void AddTick()
        {
            _defaultSeries = new TimeSeries();
            Tick firstTick  = GenerateTick.From(_date.WithDate(2014, 6, 13), 1d);
            Tick secondTick = GenerateTick.From(_date.WithDate(2014, 6, 14), 2d);

            Assert.Multiple(() =>
            {
                Assert.AreEqual(0, _defaultSeries.TickCount);
                Assert.AreEqual(-1, _defaultSeries.Begin);
                Assert.AreEqual(-1, _defaultSeries.End);
            });

            _defaultSeries.AddTick(firstTick);
            Assert.Multiple(() =>
            {
                Assert.AreEqual(1, _defaultSeries.TickCount);
                Assert.AreEqual(0, _defaultSeries.Begin);
                Assert.AreEqual(0, _defaultSeries.End);
            });

            _defaultSeries.AddTick(secondTick);
            Assert.Multiple(() =>
            {
                Assert.AreEqual(2, _defaultSeries.TickCount);
                Assert.AreEqual(0, _defaultSeries.Begin);
                Assert.AreEqual(1, _defaultSeries.End);
            });
        }
Beispiel #6
0
        public void SetUp()
        {
            // @TODO add volumes
            IList <Tick> ticks = new List <Tick>();

            ticks.Add(GenerateTick.From(44.98, 45.05, 45.17, 44.96));
            ticks.Add(GenerateTick.From(45.05, 45.10, 45.15, 44.99));
            ticks.Add(GenerateTick.From(45.11, 45.19, 45.32, 45.11));
            ticks.Add(GenerateTick.From(45.19, 45.14, 45.25, 45.04));
            ticks.Add(GenerateTick.From(45.12, 45.15, 45.20, 45.10));
            ticks.Add(GenerateTick.From(45.15, 45.14, 45.20, 45.10));
            ticks.Add(GenerateTick.From(45.13, 45.10, 45.16, 45.07));
            ticks.Add(GenerateTick.From(45.12, 45.15, 45.22, 45.10));
            ticks.Add(GenerateTick.From(45.15, 45.22, 45.27, 45.14));
            ticks.Add(GenerateTick.From(45.24, 45.43, 45.45, 45.20));
            ticks.Add(GenerateTick.From(45.43, 45.44, 45.50, 45.39));
            ticks.Add(GenerateTick.From(45.43, 45.55, 45.60, 45.35));
            ticks.Add(GenerateTick.From(45.58, 45.55, 45.61, 45.39));
            ticks.Add(GenerateTick.From(45.45, 45.01, 45.55, 44.80));
            ticks.Add(GenerateTick.From(45.03, 44.23, 45.04, 44.17));
            ticks.Add(GenerateTick.From(44.23, 43.95, 44.29, 43.81));
            ticks.Add(GenerateTick.From(43.91, 43.08, 43.99, 43.08));
            ticks.Add(GenerateTick.From(43.07, 43.55, 43.65, 43.06));
            ticks.Add(GenerateTick.From(43.56, 43.95, 43.99, 43.53));
            ticks.Add(GenerateTick.From(43.93, 44.47, 44.58, 43.93));
            _data = GenerateTimeSeries.From(ticks);
        }
Beispiel #7
0
        public void SetUp()
        {
            IList <Tick> ticks = new List <Tick>();

            ticks.Add(GenerateTick.From(44.98, 45.05, 45.17, 44.96, 1));
            ticks.Add(GenerateTick.From(45.05, 45.10, 45.15, 44.99, 2));
            ticks.Add(GenerateTick.From(45.11, 45.19, 45.32, 45.11, 1));
            ticks.Add(GenerateTick.From(45.19, 45.14, 45.25, 45.04, 3));
            ticks.Add(GenerateTick.From(45.12, 45.15, 45.20, 45.10, 1));
            ticks.Add(GenerateTick.From(45.15, 45.14, 45.20, 45.10, 2));
            ticks.Add(GenerateTick.From(45.13, 45.10, 45.16, 45.07, 1));
            ticks.Add(GenerateTick.From(45.12, 45.15, 45.22, 45.10, 5));
            ticks.Add(GenerateTick.From(45.15, 45.22, 45.27, 45.14, 1));
            ticks.Add(GenerateTick.From(45.24, 45.43, 45.45, 45.20, 1));
            ticks.Add(GenerateTick.From(45.43, 45.44, 45.50, 45.39, 1));
            ticks.Add(GenerateTick.From(45.43, 45.55, 45.60, 45.35, 5));
            ticks.Add(GenerateTick.From(45.58, 45.55, 45.61, 45.39, 7));
            ticks.Add(GenerateTick.From(45.45, 45.01, 45.55, 44.80, 6));
            ticks.Add(GenerateTick.From(45.03, 44.23, 45.04, 44.17, 1));
            ticks.Add(GenerateTick.From(44.23, 43.95, 44.29, 43.81, 2));
            ticks.Add(GenerateTick.From(43.91, 43.08, 43.99, 43.08, 1));
            ticks.Add(GenerateTick.From(43.07, 43.55, 43.65, 43.06, 7));
            ticks.Add(GenerateTick.From(43.56, 43.95, 43.99, 43.53, 6));
            ticks.Add(GenerateTick.From(43.93, 44.47, 44.58, 43.93, 1));
            _data = GenerateTimeSeries.From(ticks);
        }
Beispiel #8
0
        public void SetUp()
        {
            var ticks = new List <Tick>();

            foreach (var price in _typicalPrices)
            {
                ticks.Add(GenerateTick.From(price, price, price, price));
            }
            _series = GenerateTimeSeries.From(ticks);
        }
        public void SetUp()
        {
            IList <Tick> ticks = new List <Tick>();

            // open, close, high, low
            ticks.Add(GenerateTick.From(10, 18, 20, 10));
            ticks.Add(GenerateTick.From(15, 18, 19, 14));
            ticks.Add(GenerateTick.From(17, 16, 19, 15));
            ticks.Add(GenerateTick.From(15, 11, 15, 8));
            ticks.Add(GenerateTick.From(11, 12, 12, 10));
            _series = GenerateTimeSeries.From(ticks);
        }
        public void SetUp()
        {
            IList <Tick> ticks = new List <Tick>();

            ticks.Add(GenerateTick.From(0, 0, 16, 8));
            ticks.Add(GenerateTick.From(0, 0, 12, 6));
            ticks.Add(GenerateTick.From(0, 0, 18, 14));
            ticks.Add(GenerateTick.From(0, 0, 10, 6));
            ticks.Add(GenerateTick.From(0, 0, 8, 4));

            _series = GenerateTimeSeries.From(ticks);
        }
Beispiel #11
0
        public void PositiveDirectionalMovement()
        {
            var          yesterdayTick = GenerateTick.From(0, 0, 6, 6);
            var          todayTick     = GenerateTick.From(0, 0, 12, 4);
            IList <Tick> ticks         = new List <Tick>();

            ticks.Add(yesterdayTick);
            ticks.Add(todayTick);
            var series = GenerateTimeSeries.From(ticks);
            var dup    = new DirectionalMovementUpIndicator(series);

            TaTestsUtils.AssertDecimalEquals(dup.GetValue(1), 6);
        }
        public void ZeroDirectionalMovement3()
        {
            var          yesterdayTick = GenerateTick.From(0, 0, 6, 6);
            var          todayTick     = GenerateTick.From(0, 0, 12, 4);
            IList <Tick> ticks         = new List <Tick>();

            ticks.Add(yesterdayTick);
            ticks.Add(todayTick);
            var series = GenerateTimeSeries.From(ticks);
            var down   = new DirectionalMovementDownIndicator(series);

            TaTestsUtils.AssertDecimalEquals(down.GetValue(1), 0);
        }
Beispiel #13
0
        public void DynamicAddTrade()
        {
            var data = new double[] { 2, 1, 3, 5, 6, 3, 20, 20, 3 };

            // We will rely on this being correct as it duplicates tests above...
            TimeSeries confirmedSeries        = GenerateTimeSeries.From(data);
            var        confirmedTradingRecord = new TradingRecord(Order.BuyAt(0), Order.SellAt(2), Order.BuyAt(3), Order.SellAt(4), Order.BuyAt(5), Order.SellAt(6), Order.BuyAt(7), Order.SellAt(8));
            // use these results to check against the dynamically added Trades
            var confirmedCashFlow = new CashFlow(confirmedSeries, confirmedTradingRecord);

            TimeSeries sampleTimeSeries = new TimeSeries();
            var        tradingRecord    = new TradingRecord();
            var        cashFlow         = new CashFlow(sampleTimeSeries, tradingRecord);

            for (var i = 0; i < data.Length; i++)
            {
                sampleTimeSeries.AddTick(GenerateTick.From((new LocalDateTime()).WithMillisOfSecond(i), data[i]));
                switch (i)
                {
                case 0:     // buy
                case 3:     // buy
                case 5:     // buy
                case 7:     // buy
                    tradingRecord.Enter(i);
                    break;

                case 2:     // sell
                case 4:     // sell
                case 6:     // sell
                case 8:     // sell
                    tradingRecord.Exit(i);
                    cashFlow.AddTrade(tradingRecord.LastTrade);
                    break;

                default:
                    // don't do anything
                    break;
                }
            }

            // Check all the data off...
            Assert.Multiple(() =>
            {
                for (var i = 0; i < data.Length; i++)
                {
                    TaTestsUtils.AssertDecimalEquals(cashFlow.GetValue(i), confirmedCashFlow.GetValue(i).ToDouble());
                }
            });
        }
Beispiel #14
0
        public void SetUp()
        {
            IList <Tick> ticks = new List <Tick>();

            // open, close, high, low
            ticks.Add(GenerateTick.From(19, 19, 22, 15));
            ticks.Add(GenerateTick.From(10, 18, 20, 8));
            ticks.Add(GenerateTick.From(17, 16, 21, 15));
            ticks.Add(GenerateTick.From(15.6, 18, 18.1, 14));
            ticks.Add(GenerateTick.From(16, 19.9, 20, 15));
            ticks.Add(GenerateTick.From(16.8, 23, 23, 16.7));
            ticks.Add(GenerateTick.From(17, 25, 25, 17));
            ticks.Add(GenerateTick.From(23, 16.8, 24, 15));
            _series = GenerateTimeSeries.From(ticks);
        }
        public void StackOverflowError()
        {
            IList <Tick> bigListOfTicks = new List <Tick>();

            for (var i = 0; i < 10000; i++)
            {
                bigListOfTicks.Add(GenerateTick.From(i));
            }
            var bigSeries = GenerateTimeSeries.From(bigListOfTicks);
            var obv       = new OnBalanceVolumeIndicator(bigSeries);

            // If a StackOverflowError is thrown here, then the RecursiveCachedIndicator
            // does not work as intended.
            TaTestsUtils.AssertDecimalEquals(obv.GetValue(9999), 0);
        }
        public void SetUp()
        {
            IList <Tick> ticks = new List <Tick>();

            // open, close, high, low
            ticks.Add(GenerateTick.From(19, 19, 22, 15));
            ticks.Add(GenerateTick.From(10, 18, 20, 8));
            ticks.Add(GenerateTick.From(17, 20, 21, 17));
            ticks.Add(GenerateTick.From(19, 17, 20, 16.9));
            ticks.Add(GenerateTick.From(17.5, 14, 18, 13.9));
            ticks.Add(GenerateTick.From(15, 11, 15, 11));
            ticks.Add(GenerateTick.From(12, 14, 15, 8));
            ticks.Add(GenerateTick.From(13, 16, 16, 11));
            _series = GenerateTimeSeries.From(ticks);
        }
Beispiel #17
0
        public void StackOverflowError()
        {
            IList <Tick> bigListOfTicks = new List <Tick>();

            for (var i = 0; i < 10000; i++)
            {
                bigListOfTicks.Add(GenerateTick.From(i));
            }
            var bigSeries  = GenerateTimeSeries.From(bigListOfTicks);
            var closePrice = new ClosePriceIndicator(bigSeries);
            var ema        = new EmaIndicator(closePrice, 10);

            // If a StackOverflowError is thrown here, then the RecursiveCachedIndicator
            // does not work as intended.
            TaTestsUtils.AssertDecimalEquals(ema.GetValue(9999), 9994.5);
        }
Beispiel #18
0
        public void GetValue()
        {
            IList <Tick> ticks = new List <Tick>();

            ticks.Add(GenerateTick.From(0, 12, 15, 8));
            ticks.Add(GenerateTick.From(0, 8, 11, 6));
            ticks.Add(GenerateTick.From(0, 15, 17, 14));
            ticks.Add(GenerateTick.From(0, 15, 17, 14));
            ticks.Add(GenerateTick.From(0, 0, 0, 2));
            var tr = new TrueRangeIndicator(GenerateTimeSeries.From(ticks));

            TaTestsUtils.AssertDecimalEquals(tr.GetValue(0), 7);
            TaTestsUtils.AssertDecimalEquals(tr.GetValue(1), 6);
            TaTestsUtils.AssertDecimalEquals(tr.GetValue(2), 9);
            TaTestsUtils.AssertDecimalEquals(tr.GetValue(3), 3);
            TaTestsUtils.AssertDecimalEquals(tr.GetValue(4), 15);
        }
        public void TrendSwitchTest()
        {
            IList <Tick> ticks = new List <Tick>();

            ticks.Add(GenerateTick.From(0, 10, 13, 8));
            ticks.Add(GenerateTick.From(0, 8, 11, 6));
            ticks.Add(GenerateTick.From(0, 6, 9, 4));
            ticks.Add(GenerateTick.From(0, 11, 15, 9));
            ticks.Add(GenerateTick.From(0, 13, 15, 9));
            var sar = new ParabolicSarIndicator(GenerateTimeSeries.From(ticks), 1);

            TaTestsUtils.AssertDecimalEquals(sar.GetValue(0), 10);
            TaTestsUtils.AssertDecimalEquals(sar.GetValue(1), 8);
            TaTestsUtils.AssertDecimalEquals(sar.GetValue(2), 11);
            TaTestsUtils.AssertDecimalEquals(sar.GetValue(3), 4);
            TaTestsUtils.AssertDecimalEquals(sar.GetValue(4), 4);
        }
Beispiel #20
0
        public void GetValue()
        {
            IList <Tick> ticks = new List <Tick>();

            ticks.Add(GenerateTick.From(0, 12, 15, 8));
            ticks.Add(GenerateTick.From(0, 8, 11, 6));
            ticks.Add(GenerateTick.From(0, 15, 17, 14));
            ticks.Add(GenerateTick.From(0, 15, 17, 14));
            ticks.Add(GenerateTick.From(0, 0, 0, 2));
            var atr = new AverageTrueRangeIndicator(GenerateTimeSeries.From(ticks), 3);

            TaTestsUtils.AssertDecimalEquals(atr.GetValue(0), 1);
            TaTestsUtils.AssertDecimalEquals(atr.GetValue(1), 8d / 3);
            TaTestsUtils.AssertDecimalEquals(atr.GetValue(2), 8d / 3 * 2d / 3 + 3);
            TaTestsUtils.AssertDecimalEquals(atr.GetValue(3), (8d / 3 * 2d / 3 + 3) * 2d / 3 + 1);
            TaTestsUtils.AssertDecimalEquals(atr.GetValue(4), ((8d / 3 * 2d / 3 + 3) * 2d / 3 + 1) * 2d / 3 + 15d / 3);
        }
        public void TrendSwitchTest2()
        {
            IList <Tick> ticks = new List <Tick>();

            ticks.Add(GenerateTick.From(0, 10, 13, 11));
            ticks.Add(GenerateTick.From(0, 10, 15, 13));
            ticks.Add(GenerateTick.From(0, 12, 18, 11));
            ticks.Add(GenerateTick.From(0, 10, 15, 9));
            ticks.Add(GenerateTick.From(0, 9, 15, 9));

            var sar = new ParabolicSarIndicator(GenerateTimeSeries.From(ticks), 1);

            TaTestsUtils.AssertDecimalEquals(sar.GetValue(0), 10);
            TaTestsUtils.AssertDecimalEquals(sar.GetValue(1), 10);
            TaTestsUtils.AssertDecimalEquals(sar.GetValue(2), 0.04 * (18 - 10) + 10);
            TaTestsUtils.AssertDecimalEquals(sar.GetValue(3), 18);
            TaTestsUtils.AssertDecimalEquals(sar.GetValue(4), 18);
        }
        public void UpTrendTest()
        {
            IList <Tick> ticks = new List <Tick>();

            ticks.Add(GenerateTick.From(0, 10, 13, 11));
            ticks.Add(GenerateTick.From(0, 17, 15, 11.38));
            ticks.Add(GenerateTick.From(0, 18, 16, 14));
            ticks.Add(GenerateTick.From(0, 19, 17, 12));
            ticks.Add(GenerateTick.From(0, 20, 18, 9));

            var sar = new ParabolicSarIndicator(GenerateTimeSeries.From(ticks), 1);

            TaTestsUtils.AssertDecimalEquals(sar.GetValue(0), 10);
            TaTestsUtils.AssertDecimalEquals(sar.GetValue(1), 17);
            TaTestsUtils.AssertDecimalEquals(sar.GetValue(2), 11.38);
            TaTestsUtils.AssertDecimalEquals(sar.GetValue(3), 11.38);
            TaTestsUtils.AssertDecimalEquals(sar.GetValue(4), 18);
        }
        public void SetUp()
        {
            IList <Tick> ticks = new List <Tick>();

            ticks.Add(GenerateTick.From(0, 0, 16, 8));
            ticks.Add(GenerateTick.From(0, 0, 12, 6));
            ticks.Add(GenerateTick.From(0, 0, 18, 14));
            ticks.Add(GenerateTick.From(0, 0, 10, 6));
            ticks.Add(GenerateTick.From(0, 0, 32, 6));
            ticks.Add(GenerateTick.From(0, 0, 2, 2));
            ticks.Add(GenerateTick.From(0, 0, 0, 0));
            ticks.Add(GenerateTick.From(0, 0, 8, 1));
            ticks.Add(GenerateTick.From(0, 0, 83, 32));
            ticks.Add(GenerateTick.From(0, 0, 9, 3));

            _timeSeries = GenerateTimeSeries.From(ticks);
            _average    = new MedianPriceIndicator(_timeSeries);
        }
Beispiel #24
0
        public void AverageDirectionalMovement()
        {
            IList <Tick> ticks = new List <Tick>();

            ticks.Add(GenerateTick.From(0, 0, 10, 2));
            ticks.Add(GenerateTick.From(0, 0, 12, 2));
            ticks.Add(GenerateTick.From(0, 0, 15, 2));
            ticks.Add(GenerateTick.From(0, 0, 11, 2));
            ticks.Add(GenerateTick.From(0, 0, 13, 7));

            var series = GenerateTimeSeries.From(ticks);
            var admup  = new AverageDirectionalMovementUpIndicator(series, 3);

            TaTestsUtils.AssertDecimalEquals(admup.GetValue(0), 1);
            TaTestsUtils.AssertDecimalEquals(admup.GetValue(1), 4d / 3);
            TaTestsUtils.AssertDecimalEquals(admup.GetValue(2), 4d / 3 * 2d / 3 + 1);
            TaTestsUtils.AssertDecimalEquals(admup.GetValue(3), (4d / 3 * 2d / 3 + 1) * 2d / 3);
            TaTestsUtils.AssertDecimalEquals(admup.GetValue(4), (4d / 3 * 2d / 3 + 1) * 2d / 3 * 2d / 3 + 2d / 3);
        }
Beispiel #25
0
        public void GetValue()
        {
            IList <Tick> ticks = new List <Tick>();

            ticks.Add(GenerateTick.From(0, 0, 10, 2));
            ticks.Add(GenerateTick.From(0, 0, 12, 2));
            ticks.Add(GenerateTick.From(0, 0, 15, 2));
            ticks.Add(GenerateTick.From(0, 0, 11, 2));
            ticks.Add(GenerateTick.From(0, 0, 13, 7));

            var series = GenerateTimeSeries.From(ticks);
            var dup    = new DirectionalUpIndicator(series, 3);

            TaTestsUtils.AssertDecimalEquals(dup.GetValue(0), 1);
            TaTestsUtils.AssertDecimalEquals(dup.GetValue(1), (4d / 3) / (14d / 3));
            TaTestsUtils.AssertDecimalEquals(dup.GetValue(2), (4d / 3 * 2d / 3 + 1) / (14d / 3 * 2d / 3 + 15d / 3));
            TaTestsUtils.AssertDecimalEquals(dup.GetValue(3), ((4d / 3 * 2d / 3 + 1) * 2d / 3) / (((14d / 3 * 2d / 3 + 15d / 3) * 2d / 3) + 11d / 3));
            TaTestsUtils.AssertDecimalEquals(dup.GetValue(4), ((4d / 3 * 2d / 3 + 1) * 2d / 3 * 2d / 3 + 2d / 3) / (((((14d / 3 * 2d / 3 + 15d / 3) * 2d / 3) + 11d / 3) * 2d / 3) + 13d / 3));
        }
        public void AverageDirectionalMovement()
        {
            IList <Tick> ticks = new List <Tick>();

            ticks.Add(GenerateTick.From(0, 0, 13, 7));
            ticks.Add(GenerateTick.From(0, 0, 11, 5));
            ticks.Add(GenerateTick.From(0, 0, 15, 3));
            ticks.Add(GenerateTick.From(0, 0, 14, 2));
            ticks.Add(GenerateTick.From(0, 0, 13, 0.2));

            var series = GenerateTimeSeries.From(ticks);
            var ddown  = new DirectionalDownIndicator(series, 3);

            TaTestsUtils.AssertDecimalEquals(ddown.GetValue(0), 1);
            TaTestsUtils.AssertDecimalEquals(ddown.GetValue(1), (4d / 3) / (13d / 3));
            TaTestsUtils.AssertDecimalEquals(ddown.GetValue(2), (4d / 3 * 2d / 3) / (13d / 3 * 2d / 3 + 15d / 3));
            TaTestsUtils.AssertDecimalEquals(ddown.GetValue(3), ((4d / 3 * 2d / 3) * 2d / 3 + 1d / 3) / (((13d / 3 * 2d / 3 + 15d / 3) * 2d / 3) + 14d / 3));
            TaTestsUtils.AssertDecimalEquals(ddown.GetValue(4), (((4d / 3 * 2d / 3) * 2d / 3 + 1d / 3) * 2d / 3 + 1.8 * 1d / 3) / (((((13d / 3 * 2d / 3 + 15d / 3) * 2d / 3) + 14d / 3) * 2d / 3) + 13d / 3));
        }
Beispiel #27
0
        public void SetUp()
        {
            _ticks = new List <Tick>
            {
                GenerateTick.From(new LocalDateTime(2014, 6, 13, 0, 0), 1d),
                GenerateTick.From(new LocalDateTime(2014, 6, 14, 0, 0, 0), 2d),
                GenerateTick.From(new LocalDateTime(2014, 6, 15, 0, 0, 0), 3d),
                GenerateTick.From(new LocalDateTime(2014, 6, 20, 0, 0, 0), 4d),
                GenerateTick.From(new LocalDateTime(2014, 6, 25, 0, 0, 0), 5d),
                GenerateTick.From(new LocalDateTime(2014, 6, 30, 0, 0, 0), 6d)
            };

            _date        = new LocalDateTime();
            _defaultName = "Series Name";

            _defaultSeries = new TimeSeries(_defaultName, _ticks);
            _subSeries     = _defaultSeries.Subseries(2, 4);
            _emptySeries   = new TimeSeries();

            _seriesForRun = GenerateTimeSeries.From(new[]
            {
                1d, 2d, 3d, 4d, 5d, 6d, 7d, 8d, 9d
            }, new[]
            {
                _date.WithDate(2013, 01, 01),
                _date.WithDate(2013, 08, 01),
                _date.WithDate(2013, 10, 01),
                _date.WithDate(2013, 12, 01),
                _date.WithDate(2014, 02, 01),
                _date.WithDate(2015, 01, 01),
                _date.WithDate(2015, 08, 01),
                _date.WithDate(2015, 10, 01),
                _date.WithDate(2015, 12, 01)
            });

            // Strategy would need a real test class
            _strategy = new Strategy(
                new FixedRule(0, 2, 3, 6),
                new FixedRule(1, 4, 7, 8))
            {
                UnstablePeriod = 2
            };
        }
        public void SetUp()
        {
            IList <Tick> ticks = new List <Tick>();

            ticks.Add(GenerateTick.From(44.98, 45.05, 45.17, 44.96));
            ticks.Add(GenerateTick.From(45.05, 45.10, 45.15, 44.99));
            ticks.Add(GenerateTick.From(45.11, 45.19, 45.32, 45.11));
            ticks.Add(GenerateTick.From(45.19, 45.14, 45.25, 45.04));
            ticks.Add(GenerateTick.From(45.12, 45.15, 45.20, 45.10));
            ticks.Add(GenerateTick.From(45.15, 45.14, 45.20, 45.10));
            ticks.Add(GenerateTick.From(45.13, 45.10, 45.16, 45.07));
            ticks.Add(GenerateTick.From(45.12, 45.15, 45.22, 45.10));
            ticks.Add(GenerateTick.From(45.15, 45.22, 45.27, 45.14));
            ticks.Add(GenerateTick.From(45.24, 45.43, 45.45, 45.20));
            ticks.Add(GenerateTick.From(45.43, 45.44, 45.50, 45.39));
            ticks.Add(GenerateTick.From(45.43, 45.55, 45.60, 45.35));
            ticks.Add(GenerateTick.From(45.58, 45.55, 45.61, 45.39));

            _data = new TimeSeries(ticks);
        }
        public void GetValue()
        {
            IList <Tick> ticks = new List <Tick>();

            ticks.Add(GenerateTick.From(0, 0, 10, 2));
            ticks.Add(GenerateTick.From(0, 0, 12, 2));
            ticks.Add(GenerateTick.From(0, 0, 15, 2));
            var series = GenerateTimeSeries.From(ticks);

            var dm = new DirectionalMovementIndicator(series, 3);

            TaTestsUtils.AssertDecimalEquals(dm.GetValue(0), 0);
            var dup   = (2d / 3 + 2d / 3) / (2d / 3 + 12d / 3);
            var ddown = (2d / 3) / (2d / 3 + 12d / 3);

            TaTestsUtils.AssertDecimalEquals(dm.GetValue(1), (dup - ddown) / (dup + ddown) * 100d);
            dup   = ((2d / 3 + 2d / 3) * 2d / 3 + 1) / ((2d / 3 + 12d / 3) * 2d / 3 + 15d / 3);
            ddown = (4d / 9) / ((2d / 3 + 12d / 3) * 2d / 3 + 15d / 3);
            TaTestsUtils.AssertDecimalEquals(dm.GetValue(2), (dup - ddown) / (dup + ddown) * 100d);
        }
        public void AccumulationDistribution()
        {
            var          now   = new LocalDateTime();
            IList <Tick> ticks = new List <Tick>();

            ticks.Add(GenerateTick.From(now, 0d, 10d, 12d, 8d, 0d, 200d, 0));            //2-2 * 200 / 4
            ticks.Add(GenerateTick.From(now, 0d, 8d, 10d, 7d, 0d, 100d, 0));             //1-2 *100 / 3
            ticks.Add(GenerateTick.From(now, 0d, 9d, 15d, 6d, 0d, 300d, 0));             //3-6 *300 /9
            ticks.Add(GenerateTick.From(now, 0d, 20d, 40d, 5d, 0d, 50d, 0));             //15-20 *50 / 35
            ticks.Add(GenerateTick.From(now, 0d, 30d, 30d, 3d, 0d, 600d, 0));            //27-0 *600 /27

            TimeSeries series = GenerateTimeSeries.From(ticks);
            var        ac     = new AccumulationDistributionIndicator(series);

            TaTestsUtils.AssertDecimalEquals(ac.GetValue(0), 0);
            TaTestsUtils.AssertDecimalEquals(ac.GetValue(1), -100d / 3);
            TaTestsUtils.AssertDecimalEquals(ac.GetValue(2), -100d - (100d / 3));
            TaTestsUtils.AssertDecimalEquals(ac.GetValue(3), (-250d / 35) + (-100d - (100d / 3)));
            TaTestsUtils.AssertDecimalEquals(ac.GetValue(4), 600d + ((-250d / 35) + (-100d - (100d / 3))));
        }