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

            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual(volumeIndicator.GetValue(i), series.GetBar(i).Volume);
            }
        }
Пример #2
0
        public void runOnSeriesSlices()
        {
            ITimeSeries series = new MockTimeSeries(new decimal[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
                                                    new DateTime[] {
                new DateTime(2000, 1, 1, 0, 0, 0, 0),
                new DateTime(2000, 1, 1, 0, 0, 0, 0),
                new DateTime(2001, 1, 1, 0, 0, 0, 0),
                new DateTime(2001, 1, 1, 0, 0, 0, 0),
                new DateTime(2002, 1, 1, 0, 0, 0, 0),
                new DateTime(2002, 1, 1, 0, 0, 0, 0),
                new DateTime(2002, 1, 1, 0, 0, 0, 0),
                new DateTime(2003, 1, 1, 0, 0, 0, 0),
                new DateTime(2004, 1, 1, 0, 0, 0, 0),
                new DateTime(2005, 1, 1, 0, 0, 0, 0)
            });

            manager.SetTimeSeries(series);

            IStrategy aStrategy = new BaseStrategy(new FixedRule(0, 3, 5, 7), new FixedRule(2, 4, 6, 9));

            var trades = manager.Run(aStrategy, 0, 1).Trades;

            Assert.AreEqual(1, trades.Count);
            Assert.AreEqual(Order.buyAt(0, series.GetBar(0).ClosePrice, Decimals.NaN), trades[0].GetEntry());
            Assert.AreEqual(Order.sellAt(2, series.GetBar(2).ClosePrice, Decimals.NaN), trades[0].GetExit());

            trades = manager.Run(aStrategy, 2, 3).Trades;
            Assert.AreEqual(1, trades.Count);
            Assert.AreEqual(Order.buyAt(3, series.GetBar(3).ClosePrice, Decimals.NaN), trades[0].GetEntry());
            Assert.AreEqual(Order.sellAt(4, series.GetBar(4).ClosePrice, Decimals.NaN), trades[0].GetExit());

            trades = manager.Run(aStrategy, 4, 6).Trades;
            Assert.AreEqual(1, trades.Count);
            Assert.AreEqual(Order.buyAt(5, series.GetBar(5).ClosePrice, Decimals.NaN), trades[0].GetEntry());
            Assert.AreEqual(Order.sellAt(6, series.GetBar(6).ClosePrice, Decimals.NaN), trades[0].GetExit());

            trades = manager.Run(aStrategy, 7, 7).Trades;
            Assert.AreEqual(1, trades.Count);
            Assert.AreEqual(Order.buyAt(7, series.GetBar(7).ClosePrice, Decimals.NaN), trades[0].GetEntry());
            Assert.AreEqual(Order.sellAt(9, series.GetBar(9).ClosePrice, Decimals.NaN), trades[0].GetExit());

            trades = manager.Run(aStrategy, 8, 8).Trades;
            Assert.IsTrue(trades.isEmpty());

            trades = manager.Run(aStrategy, 9, 9).Trades;
            Assert.IsTrue(trades.isEmpty());
        }