public void TestAlgorithmManagerSpeed() { var algorithmManager = new AlgorithmManager(false); var algorithm = PerformanceBenchmarkAlgorithms.SingleSecurity_Second; var job = new BacktestNodePacket(1, 2, "3", null, 9m, $"{nameof(AlgorithmManagerTests)}.{nameof(TestAlgorithmManagerSpeed)}"); var feed = new MockDataFeed(); var transactions = new BacktestingTransactionHandler(); var results = new BacktestingResultHandler(); var realtime = new BacktestingRealTimeHandler(); var leanManager = new NullLeanManager(); var alphas = new NullAlphaHandler(); var token = new CancellationToken(); algorithm.Initialize(); results.Initialize(job, new QuantConnect.Messaging.Messaging(), new Api.Api(), feed, new BacktestingSetupHandler(), transactions); results.SetAlgorithm(algorithm); transactions.Initialize(algorithm, new BacktestingBrokerage(algorithm), results); feed.Initialize(algorithm, job, results, null, null, null); Log.Trace("Starting algorithm manager loop to process " + feed.Count + " time slices"); var sw = Stopwatch.StartNew(); algorithmManager.Run(job, algorithm, feed, transactions, results, realtime, leanManager, alphas, token); sw.Stop(); var thousands = feed.Count / 1000d; var seconds = sw.Elapsed.TotalSeconds; Log.Trace("COUNT: " + feed.Count + " KPS: " + thousands / seconds); }
public void TestAlgorithmManagerSpeed() { var algorithm = PerformanceBenchmarkAlgorithms.SingleSecurity_Second; var algorithmManager = new AlgorithmManager(false); var job = new BacktestNodePacket(1, 2, "3", null, 9m, $"{nameof(AlgorithmManagerTests)}.{nameof(TestAlgorithmManagerSpeed)}"); var feed = new MockDataFeed(); var marketHoursDatabase = MarketHoursDatabase.FromDataFolder(); var symbolPropertiesDataBase = SymbolPropertiesDatabase.FromDataFolder(); var dataPermissionManager = new DataPermissionManager(); var dataManager = new DataManager(feed, new UniverseSelection( algorithm, new SecurityService(algorithm.Portfolio.CashBook, marketHoursDatabase, symbolPropertiesDataBase, algorithm, RegisteredSecurityDataTypesProvider.Null, new SecurityCacheProvider(algorithm.Portfolio)), dataPermissionManager, new DefaultDataProvider()), algorithm, algorithm.TimeKeeper, marketHoursDatabase, false, RegisteredSecurityDataTypesProvider.Null, dataPermissionManager); algorithm.SubscriptionManager.SetDataManager(dataManager); var transactions = new BacktestingTransactionHandler(); var results = new BacktestingResultHandler(); var realtime = new BacktestingRealTimeHandler(); var leanManager = new NullLeanManager(); var alphas = new NullAlphaHandler(); var token = new CancellationToken(); var nullSynchronizer = new NullSynchronizer(algorithm); algorithm.Initialize(); algorithm.PostInitialize(); results.Initialize(job, new QuantConnect.Messaging.Messaging(), new Api.Api(), transactions); results.SetAlgorithm(algorithm, algorithm.Portfolio.TotalPortfolioValue); transactions.Initialize(algorithm, new BacktestingBrokerage(algorithm), results); feed.Initialize(algorithm, job, results, null, null, null, dataManager, null, null); Log.Trace("Starting algorithm manager loop to process " + nullSynchronizer.Count + " time slices"); var sw = Stopwatch.StartNew(); algorithmManager.Run(job, algorithm, nullSynchronizer, transactions, results, realtime, leanManager, alphas, token); sw.Stop(); realtime.Exit(); results.Exit(); var thousands = nullSynchronizer.Count / 1000d; var seconds = sw.Elapsed.TotalSeconds; Log.Trace("COUNT: " + nullSynchronizer.Count + " KPS: " + thousands / seconds); }
public void AppliesDividendsOnce() { // init algorithm var algorithm = new AlgorithmStub(); algorithm.SetLiveMode(true); var dividend = new Dividend(Symbols.SPY, DateTime.UtcNow, 10m, 100m); var feed = new TestDividendDataFeed(algorithm, dividend); var dataManager = new DataManager(feed, new UniverseSelection(feed, algorithm), algorithm.Settings, algorithm.TimeKeeper); algorithm.SubscriptionManager.SetDataManager(dataManager); algorithm.AddSecurities(equities: new List <string> { "SPY" }); algorithm.Securities[Symbols.SPY].Holdings.SetHoldings(100m, 1); algorithm.PostInitialize(); var initializedCash = algorithm.Portfolio.CashBook["USD"].Amount; // init algorithm manager var manager = new AlgorithmManager(true); var job = new LiveNodePacket { UserId = 1, ProjectId = 2, DeployId = $"{nameof(PaperBrokerageTests)}.{nameof(AppliesDividendsOnce)}" }; var results = new LiveTradingResultHandler(); var transactions = new BacktestingTransactionHandler(); var brokerage = new PaperBrokerage(algorithm, job); // initialize results and transactions results.Initialize(job, new EventMessagingHandler(), new Api.Api(), feed, new BrokerageSetupHandler(), transactions); results.SetAlgorithm(algorithm); transactions.Initialize(algorithm, brokerage, results); // run algorithm manager manager.Run(job, algorithm, dataManager, transactions, results, new BacktestingRealTimeHandler(), new AlgorithmManagerTests.NullLeanManager(), new AlgorithmManagerTests.NullAlphaHandler(), new CancellationToken() ); var postDividendCash = algorithm.Portfolio.CashBook["USD"].Amount; Assert.AreEqual(initializedCash + dividend.Distribution, postDividendCash); }
public void AppliesDividendsOnce() { // init algorithm var algorithm = new AlgorithmStub(new MockDataFeed()); algorithm.SetLiveMode(true); var dividend = new Dividend(Symbols.SPY, DateTime.UtcNow, 10m, 100m); var feed = new MockDataFeed(); var marketHoursDatabase = MarketHoursDatabase.FromDataFolder(); var symbolPropertiesDataBase = SymbolPropertiesDatabase.FromDataFolder(); var dataPermissionManager = new DataPermissionManager(); var dataManager = new DataManager(feed, new UniverseSelection( algorithm, new SecurityService(algorithm.Portfolio.CashBook, marketHoursDatabase, symbolPropertiesDataBase, algorithm, RegisteredSecurityDataTypesProvider.Null, new SecurityCacheProvider(algorithm.Portfolio)), dataPermissionManager, new DefaultDataProvider()), algorithm, algorithm.TimeKeeper, marketHoursDatabase, true, RegisteredSecurityDataTypesProvider.Null, dataPermissionManager); var synchronizer = new NullSynchronizer(algorithm, dividend); algorithm.SubscriptionManager.SetDataManager(dataManager); algorithm.AddSecurities(equities: new List <string> { "SPY" }); algorithm.Securities[Symbols.SPY].Holdings.SetHoldings(100m, 1); algorithm.PostInitialize(); var initializedCash = algorithm.Portfolio.CashBook[Currencies.USD].Amount; // init algorithm manager var manager = new AlgorithmManager(true); var job = new LiveNodePacket { UserId = 1, ProjectId = 2, DeployId = $"{nameof(PaperBrokerageTests)}.{nameof(AppliesDividendsOnce)}" }; var results = new LiveTradingResultHandler(); var transactions = new BacktestingTransactionHandler(); var brokerage = new PaperBrokerage(algorithm, job); // initialize results and transactions results.Initialize(job, new EventMessagingHandler(), new Api.Api(), transactions); results.SetAlgorithm(algorithm, algorithm.Portfolio.TotalPortfolioValue); transactions.Initialize(algorithm, brokerage, results); var realTime = new BacktestingRealTimeHandler(); // run algorithm manager manager.Run(job, algorithm, synchronizer, transactions, results, realTime, new AlgorithmManagerTests.NullLeanManager(), new AlgorithmManagerTests.NullAlphaHandler(), new CancellationToken() ); var postDividendCash = algorithm.Portfolio.CashBook[Currencies.USD].Amount; realTime.Exit(); results.Exit(); Assert.AreEqual(initializedCash + dividend.Distribution, postDividendCash); }