Пример #1
0
        public void ChecksMapFileFirstDate()
        {
            var algorithm = PerformanceBenchmarkAlgorithms.SingleSecurity_Second;

            algorithm.Initialize();
            algorithm.PostInitialize();

            var dataProvider       = new DefaultDataProvider();
            var resultHandler      = new TestResultHandler();
            var mapFileProvider    = new LocalDiskMapFileProvider();
            var factorFileProvider = new LocalDiskFactorFileProvider(mapFileProvider);
            var factory            = new SubscriptionDataReaderSubscriptionEnumeratorFactory(resultHandler, mapFileProvider, factorFileProvider, dataProvider, true, enablePriceScaling: false);

            var universe       = algorithm.UniverseManager.Single().Value;
            var security       = algorithm.AddEquity("AAA", Resolution.Daily);
            var securityConfig = security.Subscriptions.First();
            // start date is before the first date in the map file
            var subscriptionRequest = new SubscriptionRequest(false, universe, security, securityConfig, new DateTime(2001, 12, 1),
                                                              new DateTime(2016, 11, 1));
            var enumerator = factory.CreateEnumerator(subscriptionRequest, dataProvider);

            // should initialize the data source reader
            enumerator.MoveNext();

            enumerator.Dispose();
            factory.DisposeSafely();
            resultHandler.Exit();

            var message = ((DebugPacket)resultHandler.Messages.Single()).Message;

            Assert.IsTrue(message.Equals(
                              "The starting date for symbol AAA, 2001-11-30, has been adjusted to match map file first date 2002-05-22."));
        }
Пример #2
0
        public void ChecksMapFileFirstDate()
        {
            var algorithm = PerformanceBenchmarkAlgorithms.SingleSecurity_Second;

            algorithm.Initialize();
            algorithm.PostInitialize();

            var resultHandler = new TestResultHandler();

            using var cache = new ZipDataCacheProvider(TestGlobals.DataProvider);
            var factory = new SubscriptionDataReaderSubscriptionEnumeratorFactory(resultHandler, TestGlobals.MapFileProvider, TestGlobals.FactorFileProvider, cache, enablePriceScaling: false);

            var universe       = algorithm.UniverseManager.Single().Value;
            var security       = algorithm.AddEquity("AAA", Resolution.Daily);
            var securityConfig = security.Subscriptions.First();
            // start date is before the first date in the map file
            var subscriptionRequest = new SubscriptionRequest(false, universe, security, securityConfig, new DateTime(2001, 12, 1),
                                                              new DateTime(2016, 11, 1));
            var enumerator = factory.CreateEnumerator(subscriptionRequest, TestGlobals.DataProvider);

            // should initialize the data source reader
            enumerator.MoveNext();

            enumerator.Dispose();
            factory.DisposeSafely();
            resultHandler.Exit();

            var message = ((DebugPacket)resultHandler.Messages.Single()).Message;

            Assert.IsTrue(message.Equals(
                              "The starting dates for the following symbols have been adjusted to match their map files first date: [AAA, 2020-09-09]"));
        }
Пример #3
0
        /// <summary>
        /// Send an exit signal to the thread.
        /// </summary>
        public void Exit()
        {
            if (IsActive)
            {
                IsActive = false;
                Log.Trace("FileSystemDataFeed.Exit(): Start. Setting cancellation token...");
                _cancellationTokenSource.Cancel();
                Log.Trace("FileSystemDataFeed.Exit(): Ending Thread...");
                _controller?.DisposeSafely();

                if (_subscriptions != null)
                {
                    // remove each subscription from our collection
                    foreach (var subscription in Subscriptions)
                    {
                        try
                        {
                            RemoveSubscription(subscription.Configuration);
                        }
                        catch (Exception err)
                        {
                            Log.Error(err, "Error removing: " + subscription.Configuration);
                        }
                    }
                }

                _subscriptionfactory?.DisposeSafely();
                Log.Trace("FileSystemDataFeed.Exit(): Exit Finished.");
            }
        }
Пример #4
0
 /// <summary>
 /// Send an exit signal to the thread.
 /// </summary>
 public void Exit()
 {
     if (IsActive)
     {
         IsActive = false;
         Log.Trace("FileSystemDataFeed.Exit(): Start. Setting cancellation token...");
         _cancellationTokenSource.Cancel();
         _subscriptionFactory?.DisposeSafely();
         Log.Trace("FileSystemDataFeed.Exit(): Exit Finished.");
     }
 }
Пример #5
0
        public void TestDataFeedEnumeratorStackSpeed()
        {
            var algorithm = PerformanceBenchmarkAlgorithms.SingleSecurity_Second;

            algorithm.Initialize();
            algorithm.PostInitialize();

            var dataProvider       = new DefaultDataProvider();
            var resultHandler      = new BacktestingResultHandler();
            var mapFileProvider    = new LocalDiskMapFileProvider();
            var factorFileProvider = new LocalDiskFactorFileProvider(mapFileProvider);
            var factory            = new SubscriptionDataReaderSubscriptionEnumeratorFactory(resultHandler, mapFileProvider, factorFileProvider, dataProvider, true, enablePriceScaling: false);

            var universe            = algorithm.UniverseManager.Single().Value;
            var security            = algorithm.Securities.Single().Value;
            var securityConfig      = security.Subscriptions.First();
            var subscriptionRequest = new SubscriptionRequest(false, universe, security, securityConfig, algorithm.StartDate, algorithm.EndDate);
            var enumerator          = factory.CreateEnumerator(subscriptionRequest, dataProvider);

            var count     = 0;
            var stopwatch = Stopwatch.StartNew();
            var lastMonth = algorithm.StartDate.Month;

            while (enumerator.MoveNext())
            {
                var current = enumerator.Current;
                if (current == null)
                {
                    Log.Trace("ERROR: Current is null");
                    continue;
                }

                if (current.Time.Month != lastMonth)
                {
                    var elapsed   = stopwatch.Elapsed.TotalSeconds;
                    var thousands = count / 1000d;
                    Log.Trace($"{DateTime.Now} - Time: {current.Time}: KPS: {thousands / elapsed}");
                    lastMonth = current.Time.Month;
                }
                count++;
            }
            Log.Trace("Count: " + count);

            stopwatch.Stop();
            enumerator.Dispose();
            factory.DisposeSafely();
            Log.Trace($"Elapsed time: {stopwatch.Elapsed}   KPS: {count / 1000d / stopwatch.Elapsed.TotalSeconds}");
        }