I am getting the error "An item with the same key has already been added" when using MeanVarianceOptimizationPortfolioConstructionModel or BlackLittermanOptimizationPortfolioConstructionModel. Code and Stack trace are below, but I read it that QC500 is inserting some symbols twice for the same timestamp?
public class ResistanceParticleRegulators : QCAlgorithm
{
public override void Initialize()
{
SetStartDate(2018, 1, 1); //Set Start Date
SetEndDate(2019, 4, 15); //Set End Date
SetCash(25000); //Set Strategy Cash
this.UniverseSettings.Resolution = Resolution.Daily;
AddUniverse(Universe.Index.QC500);
SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin);
SetAlpha(new ConstantAlphaModel(InsightType.Price, InsightDirection.Up, TimeSpan.FromDays(1), .1D, .1D));
SetPortfolioConstruction(new MeanVarianceOptimizationPortfolioConstructionModel());
SetExecution(new ImmediateExecutionModel());
SetRiskManagement(new TrailingStopRiskManagementModel (0.05M));
}
}
System.ArgumentException: An item with the same key has already been added. Key: 01/03/2018 00:00:00
at System.Collections.Generic.Dictionary`2[TKey, TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) [0x000ad] in :0
at System.Collections.Generic.Dictionary`2[TKey, TValue].Add (TKey key, TValue value) [0x00000] in :0
at System.Linq.Enumerable.ToDictionary[TSource, TKey, TElement] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T, TResult] keySelector, System.Func`2[T, TResult] elementSelector, System.Collections.Generic.IEqualityComparer`1[T] comparer) [0x0009d] in <92922d9bda2f4e1cba9242d052be6d43>:0
at System.Linq.Enumerable.ToDictionary[TSource, TKey, TElement] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T, TResult] keySelector, System.Func`2[T, TResult] elementSelector) [0x00000] in <92922d9bda2f4e1cba9242d052be6d43>:0
at QuantConnect.Algorithm.Framework.Portfolio.ReturnsSymbolData.get_Returns () [0x0002a] in <8b107ed117cc425e92bf5484bf89a480>:0
at QuantConnect.Algorithm.Framework.Portfolio.ReturnsSymbolDataExtensions+<>c.b__0_2 (QuantConnect.Symbol s, System.Collections.Generic.KeyValuePair`2[TKey, TValue] sd) [0x00007] in <8b107ed117cc425e92bf5484bf89a480>:0
at System.Linq.Enumerable+d__81`4[TOuter, TInner, TKey, TResult].MoveNext () [0x000cb] in <92922d9bda2f4e1cba9242d052be6d43>:0
at System.Linq.Enumerable+SelectManySingleSelectorIterator`2[TSource, TResult].MoveNext () [0x00038] in <92922d9bda2f4e1cba9242d052be6d43>:0
at System.Linq.Enumerable+DistinctIterator`1[TSource].MoveNext () [0x00028] in <92922d9bda2f4e1cba9242d052be6d43>:0
at System.Linq.Enumerable+SelectEnumerableIterator`2[TSource, TResult].MoveNext () [0x00029] in <92922d9bda2f4e1cba9242d052be6d43>:0
at System.Linq.Enumerable+WhereEnumerableIterator`1[TSource].ToArray () [0x00033] in <92922d9bda2f4e1cba9242d052be6d43>:0
at System.Linq.Enumerable.ToArray[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x0001f] in <92922d9bda2f4e1cba9242d052be6d43>:0
at QuantConnect.Algorithm.Framework.Portfolio.ReturnsSymbolDataExtensions.FormReturnsMatrix (System.Collections.Generic.Dictionary`2[TKey, TValue] symbolData, System.Collections.Generic.IEnumerable`1[T] symbols) [0x000d7] in <8b107ed117cc425e92bf5484bf89a480>:0
at QuantConnect.Algorithm.Framework.Portfolio.MeanVarianceOptimizationPortfolioConstructionModel.CreateTargets (QuantConnect.Algorithm.QCAlgorithm algorithm, QuantConnect.Algorithm.Framework.Alphas.Insight[] insights) [0x00175] in <8b107ed117cc425e92bf5484bf89a480>:0
at QuantConnect.Algorithm.QCAlgorithm.ProcessInsights (QuantConnect.Algorithm.Framework.Alphas.Insight[] insights) [0x00007] in <177fd9949b0b4c9cab41063dc4c8ebc6>:0
at QuantConnect.Algorithm.QCAlgorithm.OnFrameworkData (QuantConnect.Data.Slice slice) [0x001a4] in <177fd9949b0b4c9cab41063dc4c8ebc6>:0
at QuantConnect.Lean.Engine.AlgorithmManager.Run (QuantConnect.Packets.AlgorithmNodePacket job, QuantConnect.Interfaces.IAlgorithm algorithm, QuantConnect.Lean.Engine.DataFeeds.ISynchronizer synchronizer, QuantConnect.Lean.Engine.TransactionHandlers.ITransactionHandler transactions, QuantConnect.Lean.Engine.Results.IResultHandler results, QuantConnect.Lean.Engine.RealTime.IRealTimeHandler realtime, QuantConnect.Lean.Engine.Server.ILeanManager leanManager, QuantConnect.Lean.Engine.Alpha.IAlphaHandler alphas, System.Threading.CancellationToken token) [0x0160a] in Lean.Engine.Alpha.IAlphaHandler alphas, System.Threading.CancellationToken token) [0x0160a] in <530d1b234f8847759030f96b4a0a04b7>:0
Jack Simonson
Hi Daniel,
We've reproduced the issue locally and have seen the issue you opened in GitHub. We'll do our best to debug and come up with a solution soon. Keep an eye on the GH issue for any updates.
Daniel Root
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!