{"record":{"id":"19110138775c2b2b","repo":"QuantConnect/Lean","slug":"symbol-total-dividends-expected-sumofdividen","errorCode":null,"errorMessage":"{_symbol} Total Dividends: Expected {_sumOfDividends}. Actual {Portfolio[_symbol].TotalDividends}","messagePattern":"(.+?) Total Dividends: Expected (.+?)\\. Actual (.+?)","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/DividendRegressionAlgorithm.cs","lineNumber":90,"sourceCode":"        }\n        \n        public override void OnEndOfAlgorithm()\n        {\n            // The expected value refers to sum of dividend payments\n            if (Portfolio.TotalProfit != _sumOfDividends)\n            {\n                throw new RegressionTestException($\"Total Profit: Expected {_sumOfDividends}. Actual {Portfolio.TotalProfit}\");\n            }\n\n            var expectNetProfit = _sumOfDividends - Portfolio.TotalFees;\n            if (Portfolio.TotalNetProfit != expectNetProfit)\n            {\n                throw new RegressionTestException($\"Total Net Profit: Expected {expectNetProfit}. Actual {Portfolio.TotalNetProfit}\");\n            }\n\n            if (Portfolio[_symbol].TotalDividends != _sumOfDividends)\n            {\n                throw new RegressionTestException($\"{_symbol} Total Dividends: Expected {_sumOfDividends}. Actual {Portfolio[_symbol].TotalDividends}\");\n            }\n        }\n\n        /// <summary>\n        /// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.\n        /// </summary>\n        public bool CanRunLocally { get; } = true;\n\n        /// <summary>\n        /// This is used by the regression test system to indicate which languages this algorithm is written in.\n        /// </summary>\n        public List<Language> Languages { get; } = new() { Language.CSharp };\n\n        /// <summary>\n        /// Data Points count of all timeslices of algorithm\n        /// </summary>\n        public long DataPoints => 16077;\n","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/DividendRegressionAlgorithm.cs#L72-L108","documentation":"Asserts the per-security dividend accumulator Portfolio[_symbol].TotalDividends equals the algorithm-side _sumOfDividends. Both should track the same dividend payments; a mismatch means the SecurityHolding's dividend total diverged from the algorithm's manual accumulation.","triggerScenarios":"Portfolio[_symbol].TotalDividends is updated at a different time or with a different Distribution/Quantity than OnDividends, or holdings.Quantity changed between the dividend application and the manual accumulation.","commonSituations":"A Lean change in when SecurityHolding.TotalDividends is incremented vs when OnDividends fires, a timing gap where the position size differs, or a dividend split/adjustment applied only to one counter.","solutions":["Log Portfolio[_symbol].TotalDividends after each OnDividends call to see where the divergence begins.","Confirm holdings.Quantity at dividend time matches the quantity used in _sumOfDividends accumulation.","Check for a Lean regression in SecurityHolding dividend tracking vs the Dividend event distribution value.","Verify no position-size changes (rebalancing) occur between dividends that would desync the two counters."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"public override void OnDividends(Dividends dividends)\n{\n    var dividend = dividends[_symbol];\n    var holdings = Portfolio[_symbol];\n    _sumOfDividends += dividend.Distribution * holdings.Quantity;\n    Debug($\"Dividend accum: algo={_sumOfDividends} security={Portfolio[_symbol].TotalDividends}\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Log both the algorithm-side and security-side dividend totals after each payment.","Avoid rebalancing between dividends so Quantity stays consistent.","Check for Lean changes in SecurityHolding.TotalDividends update timing."],"tags":["quantconnect","dividends","security-holding","portfolio","regression-test"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}