public void WarmupDifferentResolutions(Resolution resolution, SecurityType securityType)
        {
            _algorithm = TestSetupHandler.TestAlgorithm = new TestWarmupAlgorithm(resolution);

            _algorithm.SecurityType = securityType;
            if (securityType == SecurityType.Forex)
            {
                _algorithm.StartDateToUse = new DateTime(2014, 05, 03);
                _algorithm.EndDateToUse   = new DateTime(2014, 05, 04);
            }
            else if (securityType == SecurityType.Equity)
            {
                _algorithm.StartDateToUse = new DateTime(2013, 10, 09);
                _algorithm.EndDateToUse   = new DateTime(2013, 10, 10);
            }
            else if (securityType == SecurityType.Crypto)
            {
                _algorithm.StartDateToUse = new DateTime(2018, 04, 06);
                _algorithm.EndDateToUse   = new DateTime(2018, 04, 07);
            }

            AlgorithmRunner.RunLocalBacktest(nameof(TestWarmupAlgorithm),
                                             new Dictionary <string, string> {
                { "Total Trades", "1" }
            },
                                             null,
                                             Language.CSharp,
                                             AlgorithmStatus.Completed,
                                             setupHandler: "TestSetupHandler");

            int estimateExpectedDataCount;

            switch (resolution)
            {
            case Resolution.Tick:
                estimateExpectedDataCount = 2 * (securityType == SecurityType.Forex ? 19 : 4) * 60 * 60;
                break;

            case Resolution.Second:
                estimateExpectedDataCount = 2 * (securityType == SecurityType.Forex ? 19 : 6) * 60 * 60;
                break;

            case Resolution.Minute:
                estimateExpectedDataCount = 2 * (securityType == SecurityType.Forex ? 19 : 6) * 60;
                break;

            case Resolution.Hour:
                estimateExpectedDataCount = 2 * (securityType == SecurityType.Forex ? 19 : 6);
                break;

            case Resolution.Daily:
                estimateExpectedDataCount = 2;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(resolution), resolution, null);
            }

            Log.Trace($"WarmUpDataCount: {_algorithm.WarmUpDataCount}. Resolution {resolution}. SecurityType {securityType}");
            Assert.GreaterOrEqual(_algorithm.WarmUpDataCount, estimateExpectedDataCount);
        }
Esempio n. 2
0
        public void WarmupDifferentResolutions(Resolution resolution, SecurityType securityType)
        {
            _algorithm = TestSetupHandler.TestAlgorithm = new TestWarmupAlgorithm(resolution);

            _algorithm.SecurityType = securityType;
            if (securityType == SecurityType.Forex)
            {
                _algorithm.StartDateToUse = new DateTime(2014, 05, 03);
                _algorithm.EndDateToUse   = new DateTime(2014, 05, 04);
            }
            else if (securityType == SecurityType.Equity)
            {
                _algorithm.StartDateToUse = new DateTime(2013, 10, 09);
                _algorithm.EndDateToUse   = new DateTime(2013, 10, 10);
            }
            else if (securityType == SecurityType.Crypto)
            {
                _algorithm.StartDateToUse = new DateTime(2018, 04, 06);
                _algorithm.EndDateToUse   = new DateTime(2018, 04, 07);
            }

            AlgorithmRunner.RunLocalBacktest(nameof(TestWarmupAlgorithm),
                                             new Dictionary <string, string> {
                { "Total Trades", "1" }
            },
                                             null,
                                             Language.CSharp,
                                             AlgorithmStatus.Completed,
                                             setupHandler: "TestSetupHandler");

            int estimateExpectedDataCount;

            switch (resolution)
            {
            case Resolution.Tick:
                estimateExpectedDataCount = 2 * (securityType == SecurityType.Forex ? 19 : 4) * 60;
                break;

            case Resolution.Second:
                estimateExpectedDataCount = 2 * (securityType == SecurityType.Forex ? 19 : 6) * 60 * 60;
                break;

            case Resolution.Minute:
                estimateExpectedDataCount = 2 * (securityType == SecurityType.Forex ? 19 : 6) * 60;
                break;

            case Resolution.Hour:
                estimateExpectedDataCount = 2 * (securityType == SecurityType.Forex ? 19 : 6);
                break;

            case Resolution.Daily:
                // Warmup is 2 days. During warmup we expect the daily data point which goes from T-2 to T-1, once warmup finished,
                // we will get T-1 to T data point which is let through but the data feed since the algorithm starts at T
                estimateExpectedDataCount = 1;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(resolution), resolution, null);
            }

            Log.Debug($"WarmUpDataCount: {_algorithm.WarmUpDataCount}. Resolution {resolution}. SecurityType {securityType}");
            Assert.GreaterOrEqual(_algorithm.WarmUpDataCount, estimateExpectedDataCount);
        }