Support SetBenchmark(null) to disable the benchmark - #9856
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
QCAlgorithm.SetBenchmark(Symbol)now sets a constant zero benchmark (FuncBenchmark(_ => 0)) when the symbol is null, instead of creating a security benchmark. Since the benchmark is then set, the brokerage model default is not loaded inPostInitializeand no benchmark security is added.Related Issue
Closes #9854
Motivation and Context
set_benchmark(None)binds toSetBenchmark(Symbol symbol), which passed the null symbol toSecurityBenchmark.CreateInstanceand failed withObject reference not set to an instance of an object. This gives users a direct way to disable the benchmark instead of theset_benchmark(lambda x: 0)workaround. From C#,SetBenchmark((Symbol)null)behaves the same.Requires Documentation Change
No
How Has This Been Tested?
Added
AlgorithmBenchmarkTests.NullBenchmarkDisablesTheBenchmarkfor C# (SetBenchmark((Symbol)null)) and Python (algorithm.set_benchmark(None)called from a Python module). It asserts that afterPostInitializethe benchmark is aFuncBenchmarkevaluating to 0 and that no securities were added. Both cases fail with the reported null reference without the fix and pass with it.Types of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>🤖 Generated with Claude Code