コード例 #1
0
        public void AddsOnEndOfDayEventsIfImplemented(Language language)
        {
            IAlgorithm algorithm;

            if (language == Language.CSharp)
            {
                algorithm = new TestAlgorithm();
                (algorithm as QCAlgorithm).AddEquity("SPY");
            }
            else
            {
                algorithm = new AlgorithmPythonWrapper("OnEndOfDayRegressionAlgorithm");
                algorithm.SubscriptionManager.SetDataManager(new DataManagerStub(new MockDataFeed(), algorithm));
                algorithm.AddSecurity(SecurityType.Equity,
                                      "SPY",
                                      Resolution.Daily,
                                      Market.USA,
                                      false,
                                      1,
                                      false);
            }

            var realTimeHandler = new TestBacktestingRealTimeHandler();

            realTimeHandler.Setup(algorithm,
                                  new AlgorithmNodePacket(PacketType.AlgorithmNode)
            {
                Language = language
            },
                                  new TestResultHandler(),
                                  null,
                                  new TestTimeLimitManager());
            Assert.AreEqual(2, realTimeHandler.GetScheduledEventsCount);
        }
コード例 #2
0
        public void AddsOnEndOfDayEventsIfImplemented(Language language)
        {
            Security   security;
            IAlgorithm algorithm;

            if (language == Language.CSharp)
            {
                algorithm = new TestAlgorithmB();
                security  = (algorithm as QCAlgorithm).AddEquity("SPY");
            }
            else
            {
                algorithm = new AlgorithmPythonWrapper("OnEndOfDayRegressionAlgorithm");
                algorithm.SubscriptionManager.SetDataManager(new DataManagerStub(new MockDataFeed(), algorithm));
                security = algorithm.AddSecurity(SecurityType.Equity,
                                                 "SPY",
                                                 Resolution.Daily,
                                                 Market.USA,
                                                 false,
                                                 1,
                                                 false);
            }

            var realTimeHandler = new TestBacktestingRealTimeHandler();

            realTimeHandler.Setup(algorithm,
                                  new AlgorithmNodePacket(PacketType.AlgorithmNode)
            {
                Language = language
            },
                                  _resultHandler,
                                  null,
                                  new TestTimeLimitManager());

            // Because neither implement EOD() deprecated it should be zero
            Assert.AreEqual(0, realTimeHandler.GetScheduledEventsCount);

            realTimeHandler.OnSecuritiesChanged(
                new SecurityChanges(new[] { security }, Enumerable.Empty <Security>()));

            Assert.AreEqual(1, realTimeHandler.GetScheduledEventsCount);
            realTimeHandler.Exit();
        }
コード例 #3
0
        public void DoesNotAddOnEndOfDayEventsIfNotImplemented(Language language)
        {
            Security   security;
            IAlgorithm algorithm;

            if (language == Language.CSharp)
            {
                algorithm = new AlgorithmStub();
                security  = (algorithm as QCAlgorithm).AddEquity("SPY");
            }
            else
            {
                algorithm = new AlgorithmPythonWrapper("Test_CustomDataAlgorithm");
                algorithm.SubscriptionManager.SetDataManager(new DataManagerStub(algorithm));
                security = algorithm.AddSecurity(SecurityType.Equity,
                                                 "SPY",
                                                 Resolution.Daily,
                                                 Market.USA,
                                                 false,
                                                 1,
                                                 false);
            }

            var realTimeHandler = new TestBacktestingRealTimeHandler();

            realTimeHandler.Setup(algorithm,
                                  new AlgorithmNodePacket(PacketType.AlgorithmNode)
            {
                Language = language
            },
                                  _resultHandler,
                                  null,
                                  new TestTimeLimitManager());

            Assert.AreEqual(0, realTimeHandler.GetScheduledEventsCount);

            realTimeHandler.OnSecuritiesChanged(
                new SecurityChanges(new[] { security }, Enumerable.Empty <Security>()));

            Assert.AreEqual(0, realTimeHandler.GetScheduledEventsCount);

            realTimeHandler.Exit();
        }