/// <summary> /// Get list of symbols from a PyObject /// </summary> /// <param name="pyObject">PyObject containing a list of tickers</param> /// <returns>List of Symbol</returns> private List <Symbol> GetSymbolsFromPyObject(PyObject pyObject, bool isEquity = false) { using (Py.GIL()) { // If not a PyList, convert it into one if (!PyList.IsListType(pyObject)) { var tmp = new PyList(); tmp.Append(pyObject); pyObject = tmp; } var symbols = new List <Symbol>(); foreach (PyObject item in pyObject) { var symbol = (Symbol)item.AsManagedObject(typeof(Symbol)); if (isEquity && string.IsNullOrWhiteSpace(symbol.Value)) { var ticker = (string)item.AsManagedObject(typeof(string)); symbol = new Symbol(SecurityIdentifier.GenerateEquity(ticker, Market.USA), ticker); } symbols.Add(symbol); } return(symbols.Count == 0 || string.IsNullOrEmpty(symbols.First().Value) ? null : symbols); } }
public void OrderByMarginImpactDoesNotReturnTargetsForWhichUnorderedQuantityIsZeroBecauseOpenOrder() { var algorithm = new FakeAlgorithm(); var orderProcessor = new FakeOrderProcessor(); algorithm.Transactions.SetOrderProcessor(orderProcessor); var symbol = new Symbol(SecurityIdentifier.GenerateEquity(_symbol, Market.USA), _symbol); var equity = algorithm.AddEquity(symbol); equity.Cache.AddData(new TradeBar(DateTime.UtcNow, symbol, 1, 1, 1, 1, 1)); var collection = new PortfolioTargetCollection(); var target = new PortfolioTarget(symbol, 1); collection.Add(target); var openOrderRequest = new SubmitOrderRequest(OrderType.Market, symbol.SecurityType, symbol, 1, 0, 0, DateTime.UtcNow, ""); openOrderRequest.SetOrderId(1); var openOrderTicket = new OrderTicket(algorithm.Transactions, openOrderRequest); orderProcessor.AddOrder(new MarketOrder(symbol, 1, DateTime.UtcNow)); orderProcessor.AddTicket(openOrderTicket); var targets = collection.OrderByMarginImpact(algorithm); Assert.AreEqual(collection.Count, 1); Assert.IsTrue(targets.IsNullOrEmpty()); }
/// <summary> /// Creates a user defined universe symbol /// </summary> /// <param name="securityType">The security</param> /// <param name="market">The market</param> /// <returns>A symbol for user defined universe of the specified security type and market</returns> public static Symbol CreateSymbol(SecurityType securityType, string market) { var ticker = string.Format("qc-universe-userdefined-{0}-{1}", market.ToLower(), securityType); SecurityIdentifier sid; switch (securityType) { case SecurityType.Base: sid = SecurityIdentifier.GenerateBase(ticker, market); break; case SecurityType.Equity: sid = SecurityIdentifier.GenerateEquity(SecurityIdentifier.DefaultDate, ticker, market); break; case SecurityType.Option: sid = SecurityIdentifier.GenerateOption(SecurityIdentifier.DefaultDate, ticker, market, 0, 0, 0); break; case SecurityType.Forex: sid = SecurityIdentifier.GenerateForex(ticker, market); break; case SecurityType.Cfd: sid = SecurityIdentifier.GenerateCfd(ticker, market); break; case SecurityType.Commodity: case SecurityType.Future: default: throw new NotImplementedException("The specified security type is not implemented yet: " + securityType); } return(new Symbol(sid, ticker)); }
/// <summary> /// Get the Lean <see cref = "Symbol"/> object given its ticker, security type and market. /// </summary> /// <param name="ticker">The asset symbol name</param> /// <param name="type">The asset security type</param> /// <param name="market">The asset market</param> /// <returns><see cref = "Symbol"/> object wrapped in a <see cref = "PyObject"/></returns> public PyObject GetSymbol(string ticker, string type = "Equity", string market = null) { var securityType = (SecurityType)Enum.Parse(typeof(SecurityType), type, true); SecurityIdentifier sid; if (securityType == SecurityType.Cfd) { sid = SecurityIdentifier.GenerateCfd(ticker, market ?? Market.Oanda); } else if (securityType == SecurityType.Equity) { sid = SecurityIdentifier.GenerateEquity(ticker, market ?? Market.USA); } else if (securityType == SecurityType.Forex) { sid = SecurityIdentifier.GenerateForex(ticker, market ?? Market.FXCM); } else { return("Invalid security type. Use Equity, Forex or Cfd.".ToPython()); } // Add symbol to cache SymbolCache.Set(ticker, new Symbol(sid, ticker)); return(SymbolCache.GetSymbol(ticker).ToPython()); }
/// <summary> /// Creates the symbol used for coarse fundamental data /// </summary> /// <param name="market">The market</param> /// <returns>A coarse universe symbol for the specified market</returns> public static Symbol CreateUniverseSymbol(string market) { market = market.ToLower(); var ticker = "qc-universe-coarse-" + market; var sid = SecurityIdentifier.GenerateEquity(SecurityIdentifier.DefaultDate, ticker, market); return(new Symbol(sid, ticker)); }
/// <summary> /// Initializes a new instance of the <see cref="SecurityIdentifierContext"/> class. /// </summary> /// <param name="mapFile">The map file.</param> /// <param name="market">The market.</param> public SecurityIdentifierContext(MapFile mapFile, string market) { MapFile = mapFile; SID = SecurityIdentifier.GenerateEquity(MapFile.FirstDate, MapFile.FirstTicker, market); MapFileRows = MapFile.Select(mfr => new Tuple <DateTime, string>(mfr.Date, mfr.MappedSymbol)).ToArray(); Tickers = MapFile.Select(mfr => mfr.MappedSymbol.ToLowerInvariant()).Distinct().ToArray(); LastTicker = MapFile.Last().MappedSymbol.ToLowerInvariant(); }
public void SurvivesRoundtripSerialization() { var sid = SecurityIdentifier.GenerateEquity("SPY", Market.USA); var expected = new Symbol(sid, "value"); var json = JsonConvert.SerializeObject(expected, Settings); var actual = JsonConvert.DeserializeObject<Symbol>(json, Settings); Assert.AreEqual(expected, actual); }
/// <summary> /// Creates the universe symbol used for fine fundamental data /// </summary> /// <param name="market">The market</param> /// <returns>A fine universe symbol for the specified market</returns> public static Symbol CreateUniverseSymbol(string market) { market = market.ToLower(); var ticker = $"qc-universe-fine-{market}-{Guid.NewGuid()}"; var sid = SecurityIdentifier.GenerateEquity(SecurityIdentifier.DefaultDate, ticker, market); return(new Symbol(sid, ticker)); }
public void LocalDiskShortableProviderDefaultsToZeroForMissingData(string ticker, string brokerage) { var provider = new LocalDiskShortableProvider(SecurityType.Equity, brokerage, QuantConnect.Market.USA); var date = new DateTime(2020, 12, 21); var symbol = new Symbol(SecurityIdentifier.GenerateEquity(ticker, QuantConnect.Market.USA, mappingResolveDate: date), ticker); Assert.AreEqual(0, provider.ShortableQuantity(symbol, date).Value); }
public void GenerateEquityWithTickerUsingMapFile() { var expectedFirstDate = new DateTime(1998, 1, 2); var sid = SecurityIdentifier.GenerateEquity("TWX", Market.USA, mapSymbol: true, mapFileProvider: new LocalDiskMapFileProvider()); Assert.AreEqual(sid.Date, expectedFirstDate); Assert.AreEqual(sid.Symbol, "AOL"); }
private Subscription CreateSubscription(Resolution resolution, string symbol = "AAPL", bool isInternalFeed = false, SecurityType type = SecurityType.Equity, TickType tickType = TickType.Trade) { var start = DateTime.UtcNow; var end = start.AddSeconds(10); Security security; Symbol _symbol; if (type == SecurityType.Equity) { _symbol = new Symbol(SecurityIdentifier.GenerateEquity(DateTime.Now, symbol, Market.USA), symbol); security = new Equity( _symbol, SecurityExchangeHours.AlwaysOpen(DateTimeZone.Utc), new Cash(Currencies.USD, 0, 1), SymbolProperties.GetDefault(Currencies.USD), ErrorCurrencyConverter.Instance, RegisteredSecurityDataTypesProvider.Null ); } else if (type == SecurityType.Option) { _symbol = new Symbol(SecurityIdentifier.GenerateOption(DateTime.Now, SecurityIdentifier.GenerateEquity(DateTime.Now, symbol, Market.USA), Market.USA, 0.0m, OptionRight.Call, OptionStyle.American), symbol); security = new Option( _symbol, SecurityExchangeHours.AlwaysOpen(DateTimeZone.Utc), new Cash(Currencies.USD, 0, 1), new OptionSymbolProperties(SymbolProperties.GetDefault(Currencies.USD)), ErrorCurrencyConverter.Instance, RegisteredSecurityDataTypesProvider.Null ); } else if (type == SecurityType.Future) { _symbol = new Symbol(SecurityIdentifier.GenerateFuture(DateTime.Now, symbol, Market.USA), symbol); security = new Future( _symbol, SecurityExchangeHours.AlwaysOpen(DateTimeZone.Utc), new Cash(Currencies.USD, 0, 1), SymbolProperties.GetDefault(Currencies.USD), ErrorCurrencyConverter.Instance, RegisteredSecurityDataTypesProvider.Null ); } else { throw new Exception("SecurityType not implemented"); } var config = new SubscriptionDataConfig(typeof(TradeBar), _symbol, resolution, DateTimeZone.Utc, DateTimeZone.Utc, true, false, isInternalFeed, false, tickType); var timeZoneOffsetProvider = new TimeZoneOffsetProvider(DateTimeZone.Utc, start, end); var enumerator = new EnqueueableEnumerator <BaseData>(); var subscriptionDataEnumerator = new SubscriptionDataEnumerator(config, security.Exchange.Hours, timeZoneOffsetProvider, enumerator); var subscriptionRequest = new SubscriptionRequest(false, null, security, config, start, end); return(new Subscription(subscriptionRequest, subscriptionDataEnumerator, timeZoneOffsetProvider)); }
/// <summary> /// Creates a user defined universe symbol /// </summary> /// <param name="securityType">The security</param> /// <param name="market">The market</param> /// <returns>A symbol for user defined universe of the specified security type and market</returns> public static Symbol CreateSymbol(SecurityType securityType, string market) { var ticker = $"qc-universe-userdefined-{market.ToLowerInvariant()}-{securityType}"; SecurityIdentifier sid; switch (securityType) { case SecurityType.Base: sid = SecurityIdentifier.GenerateBase(null, ticker, market); break; case SecurityType.Equity: sid = SecurityIdentifier.GenerateEquity(SecurityIdentifier.DefaultDate, ticker, market); break; case SecurityType.Option: var underlying = SecurityIdentifier.GenerateEquity(SecurityIdentifier.DefaultDate, ticker, market); sid = SecurityIdentifier.GenerateOption(SecurityIdentifier.DefaultDate, underlying, market, 0, 0, 0); break; case SecurityType.FutureOption: var underlyingFuture = SecurityIdentifier.GenerateFuture(SecurityIdentifier.DefaultDate, ticker, market); sid = SecurityIdentifier.GenerateOption(SecurityIdentifier.DefaultDate, underlyingFuture, market, 0, 0, 0); break; case SecurityType.IndexOption: var underlyingIndex = SecurityIdentifier.GenerateIndex(ticker, market); sid = SecurityIdentifier.GenerateOption(SecurityIdentifier.DefaultDate, underlyingIndex, market, 0, 0, OptionStyle.European); break; case SecurityType.Forex: sid = SecurityIdentifier.GenerateForex(ticker, market); break; case SecurityType.Cfd: sid = SecurityIdentifier.GenerateCfd(ticker, market); break; case SecurityType.Index: sid = SecurityIdentifier.GenerateIndex(ticker, market); break; case SecurityType.Future: sid = SecurityIdentifier.GenerateFuture(SecurityIdentifier.DefaultDate, ticker, market); break; case SecurityType.Crypto: sid = SecurityIdentifier.GenerateCrypto(ticker, market); break; case SecurityType.Commodity: default: throw new NotImplementedException($"The specified security type is not implemented yet: {securityType}"); } return(new Symbol(sid, ticker)); }
private TestCaseData[] GetSymbolCreateTestCaseData() { return(new [] { new TestCaseData("SPY", SecurityType.Equity, Market.USA, new Symbol(SecurityIdentifier.GenerateEquity("SPY", Market.USA), "SPY")), new TestCaseData("EURUSD", SecurityType.Forex, Market.FXCM, new Symbol(SecurityIdentifier.GenerateForex("EURUSD", Market.FXCM), "EURUSD")), new TestCaseData("SPY", SecurityType.Option, Market.USA, new Symbol(SecurityIdentifier.GenerateOption(SecurityIdentifier.DefaultDate, Symbols.SPY.ID, Market.USA, 0, default(OptionRight), default(OptionStyle)), "?SPY")) }); }
public void UsesSidForDictionaryKey() { var sid = SecurityIdentifier.GenerateEquity("SPY", Market.USA); var dictionary = new Dictionary<Symbol, int> { {new Symbol(sid, "value"), 1} }; var key = new Symbol(sid, "other value"); Assert.IsTrue(dictionary.ContainsKey(key)); }
/// <summary> /// Helper method to deserialize a single json Tiingo news /// </summary> /// <param name="token">The json token containing the Tiingo news to deserialize</param> /// <returns>The deserialized <see cref="TiingoNews"/> instance</returns> public static TiingoNews DeserializeNews(JToken token) { // just in case we add some default values for these var title = token["title"]?.ToString() ?? ""; var source = token["source"]?.ToString() ?? ""; var url = token["url"]?.ToString() ?? ""; var tags = token["tags"]?.ToObject <List <string> >() ?? new List <string>(); var description = token["description"]?.ToString() ?? ""; var publishedDate = GetDateTime(token["publishedDate"]); var crawlDate = GetDateTime(token["crawlDate"]); var articleID = token["id"].ToString(); var tickers = token["tickers"]; // 'time' is QC time which could be crawl time or published data + offset (see converter) this is not present in live // which will use 'crawlDate' var time = GetDateTime(token["time"], defaultValue: crawlDate); var symbols = new List <Symbol>(); foreach (var tiingoTicker in tickers) { var rawTicker = tiingoTicker.ToString(); if (rawTicker.Contains(" ") || rawTicker.Contains("|")) { Log.Trace($"TiingoNewsJsonConverter.DeserializeNews(): Article ID {articleID}, ignoring ticker [{rawTicker}] because it contains space or pipe character."); continue; } var ticker = TiingoSymbolMapper.GetLeanTicker(rawTicker); var sid = SecurityIdentifier.GenerateEquity( ticker, // for now we suppose USA market QuantConnect.Market.USA, // we use the news date to resolve the map file to use mappingResolveDate: publishedDate); symbols.Add(new Symbol(sid, ticker)); } var dataPoint = new TiingoNews { ArticleID = articleID, CrawlDate = crawlDate, Description = description, PublishedDate = publishedDate, Time = time, Source = source, Tags = tags, Symbols = symbols, Url = url, Title = title }; return(dataPoint); }
public void ReadsFactorFileWithoutInfValues() { var PermTick = "AAPL"; var Market = "usa"; var _symbol = new Symbol(SecurityIdentifier.GenerateEquity(PermTick, Market), PermTick); var factorFile = TestGlobals.FactorFileProvider.Get(_symbol) as CorporateFactorProvider; Assert.AreEqual(41, factorFile.SortedFactorFileData.Count); Assert.AreEqual(new DateTime(1998, 01, 01), factorFile.FactorFileMinimumDate.Value); }
public void GeneratesEquitySecurityIdentifier() { var sid1 = SecurityIdentifier.GenerateEquity(new DateTime(1998, 01, 02), "SPY", Market.USA); // verify various values Assert.AreEqual(new DateTime(1998, 01, 02), sid1.Date); Assert.AreEqual(Market.USA, sid1.Market); Assert.AreEqual(SecurityType.Equity, sid1.SecurityType); Assert.AreEqual("SPY", sid1.Symbol); Console.WriteLine(sid1); }
/// <summary> /// Generates an equity sid by using the map file provider /// </summary> private static SecurityIdentifier GetEquitySid(string ticker, DateTime date) { string firstSymbol = ticker; var resolver = MapFileProvider.Value.Get(Market.USA); var mapFile = resolver.ResolveMapFile(ticker, date); var firstDate = mapFile.FirstDate; if (mapFile.Any()) { firstSymbol = mapFile.OrderBy(x => x.Date).First().MappedSymbol; } return(SecurityIdentifier.GenerateEquity(firstDate, firstSymbol, Market.USA)); }
/// <summary> /// Creates the universe symbol used for fine fundamental data /// </summary> /// <param name="market">The market</param> /// <param name="addGuid">True, will add a random GUID to allow uniqueness</param> /// <returns>A fine universe symbol for the specified market</returns> public static Symbol CreateUniverseSymbol(string market, bool addGuid = true) { market = market.ToLowerInvariant(); var ticker = $"qc-universe-fine-{market}"; if (addGuid) { ticker += $"-{Guid.NewGuid()}"; } var sid = SecurityIdentifier.GenerateEquity(SecurityIdentifier.DefaultDate, ticker, market); return(new Symbol(sid, ticker)); }
/// <summary> /// Gets a list of all shortable Symbols, including the quantity shortable as a Dictionary. /// </summary> /// <param name="localTime">The algorithm's local time</param> /// <returns>Symbol/quantity shortable as a Dictionary. Returns null if no entry data exists for this date or brokerage</returns> public Dictionary <Symbol, long> AllShortableSymbols(DateTime localTime) { var allSymbols = new Dictionary <Symbol, long>(); if (_shortableDataDirectory == null) { return(allSymbols); } FileInfo shortableListFile = null; // Check backwards up to one week to see if we can source a previous file. // If not, then we return a list of all Symbols with quantity set to zero. var i = 0; var shortableListFileExists = false; while (i <= 7) { shortableListFile = new FileInfo(Path.Combine(_shortableDataDirectory.FullName, "dates", $"{localTime.AddDays(-i):yyyyMMdd}.csv")); if (shortableListFile.Exists) { shortableListFileExists = true; break; } i++; } if (!shortableListFileExists) { // Empty case, we'll know to consider all quantities zero. return(allSymbols); } using (var fileStream = shortableListFile.OpenRead()) using (var streamReader = new StreamReader(fileStream)) { string line; while ((line = streamReader.ReadLine()) != null) { var csv = line.Split(','); var ticker = csv[0]; var symbol = new Symbol(SecurityIdentifier.GenerateEquity(ticker, QuantConnect.Market.USA, mappingResolveDate: localTime), ticker); var quantity = Parse.Long(csv[1]); allSymbols[symbol] = quantity; } } return(allSymbols); }
private void OnLevel1FundamentalEvent(object sender, Level1FundamentalEventArgs e) { // handle split data, they're only valid today, they'll show up around 4:45am EST if (e.SplitDate1.Date == DateTime.Today && DateTime.Now.TimeOfDay.TotalHours <= 8) // they will always be sent premarket { // get the last price, if it doesn't exist then we'll just issue the split claiming the price was zero // this should (ideally) never happen, but sending this without the price is much better then not sending // it at all double referencePrice; _prices.TryGetValue(e.Symbol, out referencePrice); var sid = SecurityIdentifier.GenerateEquity(e.Symbol, Market.USA); var split = new Split(new Symbol(sid, e.Symbol), FeedTime, (decimal)referencePrice, (decimal)e.SplitFactor1); _dataQueue.Add(split); } }
public void ClearRemovesUnreachedTarget() { var algorithm = new FakeAlgorithm(); var symbol = new Symbol(SecurityIdentifier.GenerateEquity(_symbol, Market.USA), _symbol); var equity = algorithm.AddEquity(symbol); var dummySecurityHolding = new FakeSecurityHolding(equity); equity.Holdings = dummySecurityHolding; var collection = new PortfolioTargetCollection(); var target = new PortfolioTarget(symbol, -1); collection.Add(target); collection.Clear(); Assert.AreEqual(collection.Count, 0); }
public void OrderByMarginImpactDoesNotReturnTargetsWithNoData() { var algorithm = new FakeAlgorithm(); var symbol = new Symbol(SecurityIdentifier.GenerateEquity(_symbol, Market.USA), _symbol); algorithm.AddEquity(symbol); var collection = new PortfolioTargetCollection(); var target = new PortfolioTarget(symbol, -1); collection.Add(target); var targets = collection.OrderByMarginImpact(algorithm); Assert.AreEqual(collection.Count, 1); Assert.IsTrue(targets.IsNullOrEmpty()); }
public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode) { if (!isLiveMode) { // backtest gets data from csv file in dropbox var csv = line.Split(','); return(new NyseTopGainers { Time = DateTime.ParseExact(csv[0], "yyyyMMdd", null), Symbol = new Symbol(SecurityIdentifier.GenerateEquity(csv[1], Market.USA), csv[1]), TopGainersRank = int.Parse(csv[2]) }); } if (lastDate != date) { // reset our counter for the new day lastDate = date; count = 0; } // parse the html into a symbol if (!line.StartsWith(@"<a href=""/public/quotes/main.html?symbol=")) { // we're only looking for lines that contain the symbols return(null); } var lastCloseParen = line.LastIndexOf(")", StringComparison.Ordinal); var lastOpenParen = line.LastIndexOf("(", StringComparison.Ordinal); if (lastOpenParen == -1 || lastCloseParen == -1) { return(null); } var symbolString = line.Substring(lastOpenParen + 1, lastCloseParen - lastOpenParen - 1); return(new NyseTopGainers { Symbol = new Symbol(SecurityIdentifier.GenerateEquity(symbolString, Market.USA), symbolString), Time = date, // the html has these in order, so we'll keep incrementing until a new day TopGainersRank = ++count }); }
/// <summary> /// Helper method to deserialize a single json Tiingo news /// </summary> /// <param name="token">The json token containing the Tiingo news to deserialize</param> /// <returns>The deserialized <see cref="TiingoNewsData"/> instance</returns> public static TiingoNewsData DeserializeNews(JToken token) { // just in case we add some default values for these var title = token["title"]?.ToString() ?? ""; var source = token["source"]?.ToString() ?? ""; var url = token["url"]?.ToString() ?? ""; var tags = token["tags"]?.ToObject <List <string> >() ?? new List <string>(); var description = token["description"]?.ToString() ?? ""; var publishedDate = GetDateTime(token["publishedDate"]); var crawlDate = GetDateTime(token["crawlDate"]); var articleID = token["id"].ToString(); var tickers = token["tickers"]; var symbols = new List <Symbol>(); foreach (var tiingoTicker in tickers) { var ticker = TiingoSymbolMapper.GetLeanTicker(tiingoTicker.ToString()); var sid = SecurityIdentifier.GenerateEquity( ticker, // for now we suppose USA market QuantConnect.Market.USA, // we use the news date to resolve the map file to use mappingResolveDate: publishedDate); symbols.Add(new Symbol(sid, ticker)); } var dataPoint = new TiingoNewsData { ArticleID = articleID, CrawlDate = crawlDate, Description = description, PublishedDate = publishedDate, Time = publishedDate, Source = source, Tags = tags, Symbols = symbols, Url = url, Title = title }; return(dataPoint); }
/// <summary> /// Yahoo Downloader Toolbox Project For LEAN Algorithmic Trading Engine. /// Original by @chrisdk2015, tidied by @jaredbroad /// </summary> static void Main(string[] args) { if (args.Length != 4) { Console.WriteLine("Usage: YahooDownloader SYMBOLS RESOLUTION FROMDATE TODATE"); Console.WriteLine("SYMBOLS = eg SPY,AAPL"); Console.WriteLine("RESOLUTION = Daily"); Console.WriteLine("FROMDATE = yyyymmdd"); Console.WriteLine("TODATE = yyyymmdd"); Environment.Exit(1); } try { // Load settings from command line var symbols = args[0].Split(','); var resolution = (Resolution)Enum.Parse(typeof(Resolution), args[1]); var startDate = DateTime.ParseExact(args[2], "yyyyMMdd", CultureInfo.InvariantCulture); var endDate = DateTime.ParseExact(args[3], "yyyyMMdd", CultureInfo.InvariantCulture); // Load settings from config.json var dataDirectory = Config.Get("data-directory", "../../../Data"); // Create an instance of the downloader const string market = Market.USA; var downloader = new YahooDataDownloader(); foreach (var symbol in symbols) { // Download the data var sid = SecurityIdentifier.GenerateEquity(symbol, market); var symbolObject = new Symbol(sid, symbol); var data = downloader.Get(symbolObject, SecurityType.Equity, resolution, startDate, endDate); // Save the data var writer = new LeanDataWriter(SecurityType.Equity, resolution, symbolObject, dataDirectory, market); writer.Write(data); } } catch (Exception err) { Log.Error("YahooDownloader(): Error: " + err.Message); } }
public void ClearFulfilledRemovesPositiveTarget() { var algorithm = new FakeAlgorithm(); algorithm.SetFinishedWarmingUp(); var symbol = new Symbol(SecurityIdentifier.GenerateEquity(_symbol, Market.USA), _symbol); var equity = algorithm.AddEquity(symbol); var dummySecurityHolding = new FakeSecurityHolding(equity); equity.Holdings = dummySecurityHolding; var collection = new PortfolioTargetCollection(); var target = new PortfolioTarget(symbol, 1); collection.Add(target); dummySecurityHolding.SetQuantity(1); collection.ClearFulfilled(algorithm); Assert.AreEqual(collection.Count, 0); }
private static Symbol GetSymbol(MapFile mapFile, string market, SecurityType securityType) { SecurityIdentifier sid; switch (securityType) { case SecurityType.Equity: sid = SecurityIdentifier.GenerateEquity(mapFile.FirstDate, mapFile.FirstTicker, market); break; case SecurityType.Future: sid = SecurityIdentifier.GenerateFuture(SecurityIdentifier.DefaultDate, mapFile.Permtick, market); break; default: throw new ArgumentOutOfRangeException(nameof(securityType), securityType, null); } return(new Symbol(sid, mapFile.Permtick)); }
/// <summary> /// Grabs the TradeBar values from the set of keys /// </summary> private static TradeBar GetTradeBar(this IReadOnlyDictionary <string, string> dictionary, bool forceVolumeColumn = false) { var sid = (dictionary.ContainsKey("symbol") || dictionary.ContainsKey("ticker")) ? SecurityIdentifier.GenerateEquity(dictionary.GetCsvValue("symbol", "ticker"), Market.USA) : SecurityIdentifier.Empty; return(new TradeBar { Symbol = sid != SecurityIdentifier.Empty ? new Symbol(sid, dictionary.GetCsvValue("symbol", "ticker")) : Symbol.Empty, Time = Time.ParseDate(dictionary.GetCsvValue("date", "time")), Open = dictionary.GetCsvValue("open").ToDecimal(), High = dictionary.GetCsvValue("high").ToDecimal(), Low = dictionary.GetCsvValue("low").ToDecimal(), Close = dictionary.GetCsvValue("close").ToDecimal(), Volume = forceVolumeColumn || dictionary.ContainsKey("volume") ? Parse.Long(dictionary.GetCsvValue("volume"), NumberStyles.AllowExponent | NumberStyles.AllowDecimalPoint) : 0 }); }
public void OrderByMarginImpactDoesNotReturnTargetsForWhichUnorderdQuantityIsZeroBecauseTargetIsZero() { var algorithm = new FakeAlgorithm(); algorithm.Transactions.SetOrderProcessor(new FakeOrderProcessor()); var symbol = new Symbol(SecurityIdentifier.GenerateEquity(_symbol, Market.USA), _symbol); var equity = algorithm.AddEquity(symbol); equity.Cache.AddData(new TradeBar(DateTime.UtcNow, symbol, 1, 1, 1, 1, 1)); var collection = new PortfolioTargetCollection(); var target = new PortfolioTarget(symbol, 0); collection.Add(target); var targets = collection.OrderByMarginImpact(algorithm); Assert.AreEqual(collection.Count, 1); Assert.IsTrue(targets.IsNullOrEmpty()); }