/// <summary> /// Create portfolio targets from the specified insights /// </summary> /// <param name="algorithm">The algorithm instance</param> /// <param name="insights">The insights to create portoflio targets from</param> /// <returns>An enumerable of portoflio targets to be sent to the execution model</returns> public override IEnumerable <IPortfolioTarget> CreateTargets(QCAlgorithmFramework algorithm, Insight[] insights) { _insightCollection.AddRange(insights); var targets = new List <IPortfolioTarget>(); if (_removedSymbols != null) { // zero out securities removes from the universe targets.AddRange(_removedSymbols.Select(s => new PortfolioTarget(s, 0))); _removedSymbols = null; } if (insights.Length == 0) { return(targets); } // Get symbols that have emit insights, are still in the universe, and insigths haven't expired var symbols = _insightCollection .Where(x => x.CloseTimeUtc > algorithm.UtcTime) .Select(x => x.Symbol).Distinct().ToList(); if (symbols.Count == 0) { return(targets); } // give equal weighting to each security var percent = 1m / symbols.Count; foreach (var symbol in symbols) { List <Insight> activeInsights; if (_insightCollection.TryGetValue(symbol, out activeInsights)) { var direction = activeInsights.Last().Direction; targets.Add(PortfolioTarget.Percent(algorithm, symbol, (int)direction * percent)); } } return(targets); }