public void Setup() { _algo = new QCAlgorithm(); var historyProvider = new SubscriptionDataReaderHistoryProvider(); historyProvider.Initialize(null, new DefaultDataProvider(), new SingleEntryDataCacheProvider(new DefaultDataProvider()), new LocalDiskMapFileProvider(), new LocalDiskFactorFileProvider(), null); _algo.HistoryProvider = historyProvider; _tradeBarSecurity = new Security(SecurityExchangeHours.AlwaysOpen(DateTimeZone.Utc), _tradeBarConfig, new Cash(CashBook.AccountCurrency, 0, 1m), SymbolProperties.GetDefault(CashBook.AccountCurrency)); _quoteBarSecurity = new Security(SecurityExchangeHours.AlwaysOpen(DateTimeZone.Utc), _quoteBarConfig, new Cash(CashBook.AccountCurrency, 0, 1m), SymbolProperties.GetDefault(CashBook.AccountCurrency)); _brokerageInitializer = new BrokerageModelSecurityInitializer(new DefaultBrokerageModel(), new FuncSecuritySeeder(_algo.GetLastKnownPrice)); }
public void OptionsAreMappedCorrectly() { var historyProvider = new SubscriptionDataReaderHistoryProvider(); var zipCache = new ZipDataCacheProvider(new DefaultDataProvider()); historyProvider.Initialize(new HistoryProviderInitializeParameters( null, null, TestGlobals.DataProvider, zipCache, TestGlobals.MapFileProvider, TestGlobals.FactorFileProvider, null, false, new DataPermissionManager())); var symbol = Symbol.CreateOption( "FOXA", Market.USA, OptionStyle.American, OptionRight.Call, 32, new DateTime(2013, 07, 20)); var result = historyProvider.GetHistory( new[] { new HistoryRequest(new DateTime(2013, 06, 28), new DateTime(2013, 07, 03), typeof(QuoteBar), symbol, Resolution.Minute, SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork), TimeZones.NewYork, null, false, false, DataNormalizationMode.Raw, TickType.Quote) }, TimeZones.NewYork).ToList(); Assert.IsNotEmpty(result); // assert we fetch the data for the previous and new symbol var firstBar = result.First().Values.Single(); var lastBar = result.Last().Values.Single(); Assert.IsTrue(firstBar.Symbol.Value.Contains("NWSA")); Assert.AreEqual(28, firstBar.Time.Date.Day); Assert.IsTrue(lastBar.Symbol.Value.Contains("FOXA")); Assert.AreEqual(2, lastBar.Time.Date.Day); zipCache.DisposeSafely(); }
public virtual void SetUp() { _algorithm = new QCAlgorithm(); var historyProvider = new SubscriptionDataReaderHistoryProvider(); _cacheProvider = new ZipDataCacheProvider(TestGlobals.DataProvider); historyProvider.Initialize(new HistoryProviderInitializeParameters(null, null, TestGlobals.DataProvider, _cacheProvider, TestGlobals.MapFileProvider, TestGlobals.FactorFileProvider, null, true, new DataPermissionManager())); _algorithm.SetHistoryProvider(historyProvider); _algorithm.SubscriptionManager.SetDataManager(new DataManagerStub(_algorithm)); _algorithm.Settings.FreePortfolioValue = 0; _algorithm.SetFinishedWarmingUp(); }
public void Setup() { _algo = new QCAlgorithm(); var historyProvider = new SubscriptionDataReaderHistoryProvider(); historyProvider.Initialize( new HistoryProviderInitializeParameters( null, null, TestGlobals.DataProvider, new SingleEntryDataCacheProvider(new DefaultDataProvider()), TestGlobals.MapFileProvider, TestGlobals.FactorFileProvider, null, true, new DataPermissionManager() ) ); _algo.HistoryProvider = historyProvider; _algo.SubscriptionManager.SetDataManager(new DataManagerStub(_algo)); _tradeBarSecurity = new Security( SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork), _tradeBarConfig, new Cash(Currencies.USD, 0, 1m), SymbolProperties.GetDefault(Currencies.USD), ErrorCurrencyConverter.Instance, RegisteredSecurityDataTypesProvider.Null, new SecurityCache() ); _quoteBarSecurity = new Security( SecurityExchangeHours.AlwaysOpen(DateTimeZone.ForOffset(Offset.FromHours(-5))), _quoteBarConfig, new Cash(Currencies.USD, 0, 1m), SymbolProperties.GetDefault(Currencies.USD), ErrorCurrencyConverter.Instance, RegisteredSecurityDataTypesProvider.Null, new SecurityCache() ); _brokerageInitializer = new BrokerageModelSecurityInitializer(new DefaultBrokerageModel(), new FuncSecuritySeeder(_algo.GetLastKnownPrice)); }
public virtual void SetUp() { _algorithm = new QCAlgorithm(); _dataProvider = new DefaultDataProvider(); var mapFileProvider = new LocalDiskMapFileProvider(); mapFileProvider.Initialize(_dataProvider); var factorFileProvider = new LocalZipFactorFileProvider(); factorFileProvider.Initialize(mapFileProvider, _dataProvider); var historyProvider = new SubscriptionDataReaderHistoryProvider(); _cacheProvider = new ZipDataCacheProvider(_dataProvider); historyProvider.Initialize(new HistoryProviderInitializeParameters(null, null, _dataProvider, _cacheProvider, mapFileProvider, factorFileProvider, null, true, new DataPermissionManager())); _algorithm.SetHistoryProvider(historyProvider); _algorithm.SubscriptionManager.SetDataManager(new DataManagerStub(_algorithm)); _algorithm.Settings.FreePortfolioValue = 0; }
public void Setup() { _algo = new QCAlgorithm(); var historyProvider = new SubscriptionDataReaderHistoryProvider(); historyProvider.Initialize(null, new LocalDiskMapFileProvider(), new LocalDiskFactorFileProvider(), new DefaultDataFileProvider(), null); _algo.HistoryProvider = historyProvider; _security = new Security(SecurityExchangeHours.AlwaysOpen(DateTimeZone.Utc), _config, new Cash(CashBook.AccountCurrency, 0, 1m), SymbolProperties.GetDefault(CashBook.AccountCurrency)); _brokerageInitializer = new BrokerageModelSecurityInitializer(new DefaultBrokerageModel(), new FuncSecuritySeeder(_algo.GetLastKnownPrice)); }
public void EquitiesAreMappedCorrectly() { var historyProvider = new SubscriptionDataReaderHistoryProvider(); var zipCache = new ZipDataCacheProvider(new DefaultDataProvider()); historyProvider.Initialize(new HistoryProviderInitializeParameters( null, null, new DefaultDataProvider(), zipCache, new LocalDiskMapFileProvider(), new LocalDiskFactorFileProvider(), null, false, new DataPermissionManager())); var symbol = Symbol.Create("WM", SecurityType.Equity, Market.USA); var result = historyProvider.GetHistory( new[] { new HistoryRequest(new DateTime(2008, 01, 01), new DateTime(2008, 01, 05), typeof(TradeBar), symbol, Resolution.Daily, SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork), TimeZones.NewYork, null, false, false, DataNormalizationMode.Raw, TickType.Trade) }, TimeZones.NewYork).ToList(); var firstBar = result.First().Values.Single(); Assert.AreEqual("WMI", firstBar.Symbol.Value); Assert.IsNotEmpty(result); zipCache.DisposeSafely(); }
public void CurrencyConversionRateResolved() { // Unit test to prove that in the event that default resolution (minute) history request returns // no data for our currency conversion that BaseSetupHandler will use a daily history request // to determine the the conversion rate if possible. // Setup history provider and algorithm var historyProvider = new SubscriptionDataReaderHistoryProvider(); var zipCache = new ZipDataCacheProvider(new DefaultDataProvider()); historyProvider.Initialize(new HistoryProviderInitializeParameters( null, null, TestGlobals.DataProvider, zipCache, TestGlobals.MapFileProvider, TestGlobals.FactorFileProvider, null, false, new DataPermissionManager())); var algorithm = new BrokerageSetupHandlerTests.TestAlgorithm { UniverseSettings = { Resolution = Resolution.Minute } }; algorithm.SetHistoryProvider(historyProvider); // Pick a date range where we do NOT have BTCUSD minute data algorithm.SetStartDate(2015, 1, 24); algorithm.SetCash("USD", 0); algorithm.SetCash("BTC", 10); // Have BaseSetupHandler resolve the currency conversion BaseSetupHandler.SetupCurrencyConversions(algorithm, algorithm.DataManager.UniverseSelection); // Assert that our portfolio has some value and that value is bitcoin Assert.IsTrue(algorithm.Portfolio.Cash > 0); Assert.IsTrue(algorithm.Portfolio.CashBook["BTC"].ValueInAccountCurrency > 0); zipCache.DisposeSafely(); }
public virtual void SetUp() { _nowUtc = new DateTime(2013, 10, 8); _algorithm = new QCAlgorithm(); _algorithm.SetPandasConverter(); _algorithm.SubscriptionManager.SetDataManager(new DataManagerStub(_algorithm)); _algorithm.SetDateTime(_nowUtc.ConvertToUtc(_algorithm.TimeZone)); var historyProvider = new SubscriptionDataReaderHistoryProvider(); _algorithm.SetHistoryProvider(historyProvider); historyProvider.Initialize(new HistoryProviderInitializeParameters( new BacktestNodePacket(), new Api.Api(), new DefaultDataProvider(), new SingleEntryDataCacheProvider(new DefaultDataProvider()), new LocalDiskMapFileProvider(), new LocalDiskFactorFileProvider(new LocalDiskMapFileProvider()), i => { }, true)); }
/// <summary> /// Creates an instance of the PortfolioLooper class /// </summary> /// <param name="startingCash">Equity curve</param> /// <param name="orders">Order events</param> /// <param name="resolution">Optional parameter to override default resolution (Hourly)</param> private PortfolioLooper(double startingCash, List <Order> orders, Resolution resolution = _resolution) { // Initialize the providers that the HistoryProvider requires var factorFileProvider = Composer.Instance.GetExportedValueByTypeName <IFactorFileProvider>("LocalDiskFactorFileProvider"); var mapFileProvider = Composer.Instance.GetExportedValueByTypeName <IMapFileProvider>("LocalDiskMapFileProvider"); _cacheProvider = new ZipDataCacheProvider(new DefaultDataProvider(), false); var historyProvider = new SubscriptionDataReaderHistoryProvider(); var dataPermissionManager = new DataPermissionManager(); historyProvider.Initialize(new HistoryProviderInitializeParameters(null, null, null, _cacheProvider, mapFileProvider, factorFileProvider, (_) => { }, false, dataPermissionManager)); Algorithm = new PortfolioLooperAlgorithm((decimal)startingCash, orders); Algorithm.SetHistoryProvider(historyProvider); // Dummy LEAN datafeed classes and initializations that essentially do nothing var job = new BacktestNodePacket(1, 2, "3", null, 9m, $""); var feed = new MockDataFeed(); // Create MHDB and Symbol properties DB instances for the DataManager var marketHoursDatabase = MarketHoursDatabase.FromDataFolder(); var symbolPropertiesDataBase = SymbolPropertiesDatabase.FromDataFolder(); _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); _securityService = new SecurityService(Algorithm.Portfolio.CashBook, marketHoursDatabase, symbolPropertiesDataBase, Algorithm, RegisteredSecurityDataTypesProvider.Null, new SecurityCacheProvider(Algorithm.Portfolio)); var transactions = new BacktestingTransactionHandler(); _resultHandler = new BacktestingResultHandler(); // Initialize security services and other properties so that we // don't get null reference exceptions during our re-calculation Algorithm.Securities.SetSecurityService(_securityService); Algorithm.SubscriptionManager.SetDataManager(_dataManager); // Initializes all the proper Securities from the orders provided by the user Algorithm.FromOrders(orders); // Initialize the algorithm Algorithm.Initialize(); Algorithm.PostInitialize(); // More initialization, this time with Algorithm and other misc. classes _resultHandler.Initialize(job, new Messaging.Messaging(), new Api.Api(), transactions); _resultHandler.SetAlgorithm(Algorithm, Algorithm.Portfolio.TotalPortfolioValue); Algorithm.Transactions.SetOrderProcessor(transactions); transactions.Initialize(Algorithm, new BacktestingBrokerage(Algorithm), _resultHandler); feed.Initialize(Algorithm, job, _resultHandler, null, null, null, _dataManager, null, null); // Begin setting up the currency conversion feed if needed var coreSecurities = Algorithm.Securities.Values.ToList(); if (coreSecurities.Any(x => x.Symbol.SecurityType == SecurityType.Forex || x.Symbol.SecurityType == SecurityType.Crypto)) { BaseSetupHandler.SetupCurrencyConversions(Algorithm, _dataManager.UniverseSelection); var conversionSecurities = Algorithm.Securities.Values.Where(s => !coreSecurities.Contains(s)).ToList(); // Skip the history request if we don't need to convert anything if (conversionSecurities.Any()) { // Point-in-time Slices to convert FX and Crypto currencies to the portfolio currency _conversionSlices = GetHistory(Algorithm, conversionSecurities, resolution); } } }