{"record":{"id":"d8f05eeaeaa85c0b","repo":"QuantConnect/Lean","slug":"shareclassmeanreversionalphamodel-symbols-paramet","errorCode":null,"errorMessage":"ShareClassMeanReversionAlphaModel: symbols parameter must contain 2 elements","messagePattern":"ShareClassMeanReversionAlphaModel: symbols parameter must contain 2 elements","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/Alphas/ShareClassMeanReversionAlpha.cs","lineNumber":94,"sourceCode":"        private class ShareClassMeanReversionAlphaModel : AlphaModel\n        {\n            private const double _insightMagnitude = 0.001;\n            private readonly Symbol _longSymbol;\n            private readonly Symbol _shortSymbol;\n            private readonly TimeSpan _insightPeriod;\n            private readonly SimpleMovingAverage _sma;\n            private readonly RollingWindow<decimal> _positionWindow;\n            private decimal _alpha;\n            private decimal _beta;\n            private bool _invested;\n\n            public ShareClassMeanReversionAlphaModel(\n                IEnumerable<Symbol> symbols,\n                Resolution resolution = Resolution.Minute)\n            {\n                if (symbols.Count() != 2)\n                {\n                    throw new ArgumentException(\"ShareClassMeanReversionAlphaModel: symbols parameter must contain 2 elements\");\n                }\n                _longSymbol = symbols.ToArray()[0];\n                _shortSymbol = symbols.ToArray()[1];\n                _insightPeriod = resolution.ToTimeSpan().Multiply(5);\n                _sma = new SimpleMovingAverage(2);\n                _positionWindow = new RollingWindow<decimal>(2);\n            }\n\n            public override IEnumerable<Insight> Update(QCAlgorithm algorithm, Slice data)\n            {\n                // Check to see if either ticker will return a NoneBar, and skip the data slice if so\n                if (data.Bars.Count < 2)\n                {\n                    return Enumerable.Empty<Insight>();\n                }\n\n                // If Alpha and Beta haven't been calculated yet, then do so\n                if (_alpha == 0 || _beta == 0)","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/Alphas/ShareClassMeanReversionAlpha.cs#L76-L112","documentation":"ShareClassMeanReversionAlphaModel is a benchmark pairs-trading alpha that builds a mean-reversion signal between two share classes of the same company (e.g. VIA/VIAB). Its constructor is dimensionally fixed at two symbols because the internal logic — alpha/beta regression, an SMA(2) over the dollar-neutral spread, and a RollingWindow(2) — assigns _longSymbol = symbols[0] and _shortSymbol = symbols[1]. Passing any count other than 2 throws ArgumentException at construction, since indexing the array beyond/below a pair would break the strategy.","triggerScenarios":"Constructing new ShareClassMeanReversionAlphaModel(symbols) where the IEnumerable<Symbol> resolves to a Count() != 2 — e.g. an empty list, a single ticker, or a universe selection result that yielded 3+ securities. The check symbols.Count() != 2 fires immediately in the ctor before any indicator state is set up.","commonSituations":"Adapting the benchmark alpha to a custom pair but passing a single symbol; wiring SetAlpha to a live UniverseSelectionModel whose selected set varies in size; refactoring the symbol list and dropping one ticker; reusing this model class for a non-pairs strategy.","solutions":["Pass exactly two Symbol objects: the long share class and the short share class (e.g. VIA, VIAB).","If symbols come from a universe, materialize to a list first and assert/branch on the count before constructing the model.","Do not reuse this alpha model for strategies needing a different number of legs — it is hard-coded to a pair.","When copying the model, keep the symbols = new[] { ... }.Select(...).Create(...) pattern so the enumerable is a stable two-element array."],"exampleFix":"// before\nvar symbols = SelectedSymbols; // count unknown / variable\nSetAlpha(new ShareClassMeanReversionAlphaModel(symbols));\n\n// after\nvar symbols = new[] { \"VIA\", \"VIAB\" }\n    .Select(x => QuantConnect.Symbol.Create(x, SecurityType.Equity, Market.USA));\nSetAlpha(new ShareClassMeanReversionAlphaModel(symbols));","handlingStrategy":"validation","validationCode":"// Validate before constructing the alpha model\nvar symbolList = symbols.ToList();\nif (symbolList.Count != 2)\n{\n    throw new InvalidOperationException(\n        $\"ShareClassMeanReversionAlphaModel requires exactly 2 symbols, got {symbolList.Count}.\");\n}\nSetAlpha(new ShareClassMeanReversionAlphaModel(symbolList));","typeGuard":"static bool IsValidPair(IEnumerable<Symbol> symbols)\n{\n    var list = symbols as ICollection<Symbol> ?? symbols.ToList();\n    return list.Count == 2 && list.All(s => s != null);\n}","tryCatchPattern":null,"preventionTips":["Always pass a fixed two-element array of Symbols to this alpha model.","When wiring from a universe, materialize and count before constructing.","Do not reuse this dimensionally-fixed model for non-pair strategies."],"tags":["alpha-model","pairs-trading","validation","argument-exception","quantconnect"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}